diff --git a/translate/snippets/src/test/java/com/example/translate/BatchTranslateTextTests.java b/translate/snippets/src/test/java/com/example/translate/BatchTranslateTextTests.java index 14531aae59e..9fb051e80a4 100644 --- a/translate/snippets/src/test/java/com/example/translate/BatchTranslateTextTests.java +++ b/translate/snippets/src/test/java/com/example/translate/BatchTranslateTextTests.java @@ -42,11 +42,12 @@ @RunWith(JUnit4.class) @SuppressWarnings("checkstyle:abbreviationaswordinname") public class BatchTranslateTextTests { + private static final String PROJECT_ID = System.getenv("GOOGLE_CLOUD_PROJECT"); private static final String INPUT_URI = "gs://cloud-samples-data/translation/text.txt"; - private static final String PREFIX = "BATCH_TRANSLATION_OUTPUT/"; - private static final String OUTPUT_URI = - String.format("gs://%s/%s%s/", PROJECT_ID, PREFIX, UUID.randomUUID()); + private static final String PREFIX = + String.format("translation-%s/%s", UUID.randomUUID(), "BATCH_TRANSLATION_OUTPUT/"); + private static final String OUTPUT_URI = String.format("gs://%s/%s", PROJECT_ID, PREFIX); private ByteArrayOutputStream bout; private PrintStream out; @@ -97,6 +98,9 @@ public void setUp() { out = new PrintStream(bout); originalPrintStream = System.out; System.setOut(out); + + // clean up bucket before the use to prevent concurrency issue. + cleanUpBucket(); } @After diff --git a/translate/snippets/src/test/java/com/example/translate/BatchTranslateTextWithGlossaryAndModelTests.java b/translate/snippets/src/test/java/com/example/translate/BatchTranslateTextWithGlossaryAndModelTests.java index 12f63d4d50c..c7e95e51c20 100644 --- a/translate/snippets/src/test/java/com/example/translate/BatchTranslateTextWithGlossaryAndModelTests.java +++ b/translate/snippets/src/test/java/com/example/translate/BatchTranslateTextWithGlossaryAndModelTests.java @@ -42,14 +42,15 @@ @RunWith(JUnit4.class) @SuppressWarnings("checkstyle:abbreviationaswordinname") public class BatchTranslateTextWithGlossaryAndModelTests { + private static final String PROJECT_ID = System.getenv("GOOGLE_CLOUD_PROJECT"); private static final String INPUT_URI = "gs://cloud-samples-data/translation/text_with_custom_model_and_glossary.txt"; private static final String GLOSSARY_ID = "DO_NOT_DELETE_TEST_GLOSSARY"; private static final String MODEL_ID = "TRL3645318651705294848"; - private static final String PREFIX = "BATCH_TRANSLATION_WITH_MODEL_OUTPUT/"; - private static final String OUTPUT_URI = - String.format("gs://%s/%s%s/", PROJECT_ID, PREFIX, UUID.randomUUID()); + private static final String PREFIX = + String.format("translation-%s/%s", UUID.randomUUID(), "BATCH_TRANSLATION_WITH_MODEL_OUTPUT/"); + private static final String OUTPUT_URI = String.format("gs://%s/%s", PROJECT_ID, PREFIX); private ByteArrayOutputStream bout; private PrintStream out; @@ -103,6 +104,9 @@ public void setUp() { out = new PrintStream(bout); originalPrintStream = System.out; System.setOut(out); + + // clear up bucket before the use to prevent concurrency issue. + cleanUpBucket(); } @After diff --git a/translate/snippets/src/test/java/com/example/translate/BatchTranslateTextWithGlossaryTests.java b/translate/snippets/src/test/java/com/example/translate/BatchTranslateTextWithGlossaryTests.java index f63135cda6d..950b733e962 100644 --- a/translate/snippets/src/test/java/com/example/translate/BatchTranslateTextWithGlossaryTests.java +++ b/translate/snippets/src/test/java/com/example/translate/BatchTranslateTextWithGlossaryTests.java @@ -42,13 +42,14 @@ @RunWith(JUnit4.class) @SuppressWarnings("checkstyle:abbreviationaswordinname") public class BatchTranslateTextWithGlossaryTests { + private static final String PROJECT_ID = System.getenv("GOOGLE_CLOUD_PROJECT"); private static final String INPUT_URI = "gs://cloud-samples-data/translation/text_with_glossary.txt"; private static final String GLOSSARY_ID = "DO_NOT_DELETE_TEST_GLOSSARY"; - private static final String PREFIX = "BATCH_TRANSLATION_GLOSSARY_OUTPUT/"; - private static final String OUTPUT_URI = - String.format("gs://%s/%s%s/", PROJECT_ID, PREFIX, UUID.randomUUID()); + private static final String PREFIX = + String.format("translation-%s/%s", UUID.randomUUID(), "BATCH_TRANSLATION_GLOSSARY_OUTPUT/"); + private static final String OUTPUT_URI = String.format("gs://%s/%s", PROJECT_ID, PREFIX); private ByteArrayOutputStream bout; private PrintStream out; @@ -101,6 +102,9 @@ public void setUp() { out = new PrintStream(bout); originalPrintStream = System.out; System.setOut(out); + + // clear up bucket before the use to prevent concurrency issue. + cleanUpBucket(); } @After diff --git a/translate/snippets/src/test/java/com/example/translate/BatchTranslateTextWithModelTests.java b/translate/snippets/src/test/java/com/example/translate/BatchTranslateTextWithModelTests.java index 5971609673f..7fdc42ddbe8 100644 --- a/translate/snippets/src/test/java/com/example/translate/BatchTranslateTextWithModelTests.java +++ b/translate/snippets/src/test/java/com/example/translate/BatchTranslateTextWithModelTests.java @@ -42,13 +42,14 @@ @RunWith(JUnit4.class) @SuppressWarnings("checkstyle:abbreviationaswordinname") public class BatchTranslateTextWithModelTests { + private static final String PROJECT_ID = System.getenv("GOOGLE_CLOUD_PROJECT"); private static final String INPUT_URI = "gs://cloud-samples-data/translation/custom_model_text.txt"; private static final String MODEL_ID = "TRL3645318651705294848"; - private static final String PREFIX = "BATCH_TRANSLATION_MODEL_GLOS_OUTPUT/"; - private static final String OUTPUT_URI = - String.format("gs://%s/%s%s/", PROJECT_ID, PREFIX, UUID.randomUUID()); + private static final String PREFIX = + String.format("translation-%s/%s", UUID.randomUUID(), "BATCH_TRANSLATION_MODEL_GLOS_OUTPUT/"); + private static final String OUTPUT_URI = String.format("gs://%s/%s", PROJECT_ID, PREFIX); private ByteArrayOutputStream bout; private PrintStream out; @@ -98,6 +99,9 @@ public void setUp() { out = new PrintStream(bout); originalPrintStream = System.out; System.setOut(out); + + // clear up bucket before the use to prevent concurrency issue. + cleanUpBucket(); } @After