From 8e3aec8a6e3263d6ddcf042b00ee0988311d66e9 Mon Sep 17 00:00:00 2001 From: nnegrey Date: Wed, 12 Jun 2019 15:01:12 -0600 Subject: [PATCH] Prevent Name collisions on tests --- .../google/cloud/vision/samples/automl/DatasetApiIT.java | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/vision/automl/src/test/java/com/google/cloud/vision/samples/automl/DatasetApiIT.java b/vision/automl/src/test/java/com/google/cloud/vision/samples/automl/DatasetApiIT.java index 8b9c033f3fb..c9cf9f34133 100644 --- a/vision/automl/src/test/java/com/google/cloud/vision/samples/automl/DatasetApiIT.java +++ b/vision/automl/src/test/java/com/google/cloud/vision/samples/automl/DatasetApiIT.java @@ -21,6 +21,7 @@ import java.io.ByteArrayOutputStream; import java.io.PrintStream; +import java.util.UUID; import org.junit.After; import org.junit.Before; import org.junit.Test; @@ -35,7 +36,6 @@ public class DatasetApiIT { private static final String PROJECT_ID = "java-docs-samples-testing"; private static final String BUCKET = PROJECT_ID + "-vcm"; private static final String COMPUTE_REGION = "us-central1"; - private static final String DATASET_NAME = "test_vision_dataset"; private ByteArrayOutputStream bout; private PrintStream out; private String datasetId; @@ -54,8 +54,13 @@ public void tearDown() { @Test public void testCreateImportDeleteDataset() { + // Create a random dataset name with a length of 32 characters (max allowed by AutoML) + // To prevent name collisions when running tests in multiple java versions at once. + // AutoML doesn't allow "-", but accepts "_" + String datasetName = String.format("test_%s", + UUID.randomUUID().toString().replace("-", "_").substring(0, 26)); // Act - DatasetApi.createDataset(PROJECT_ID, COMPUTE_REGION, DATASET_NAME, false); + DatasetApi.createDataset(PROJECT_ID, COMPUTE_REGION, datasetName, false); // Assert String got = bout.toString();