From d76d1e2722ce273a0cf9451ae570bb5db03564d4 Mon Sep 17 00:00:00 2001 From: Mike <45373284+munkhuushmgl@users.noreply.github.com> Date: Fri, 18 Jun 2021 10:45:37 -0600 Subject: [PATCH] chore: fix batch test (#585) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * chore: fix batch test * fixed nit * 🦉 Updates from OwlBot * Update samples/snippets/src/test/java/com/example/translate/BatchTranslateTextTests.java Co-authored-by: Averi Kitsch Co-authored-by: Owl Bot Co-authored-by: Averi Kitsch --- .../com/example/translate/BatchTranslateTextTests.java | 10 +++++++--- .../BatchTranslateTextWithGlossaryAndModelTests.java | 10 +++++++--- .../translate/BatchTranslateTextWithGlossaryTests.java | 10 +++++++--- .../translate/BatchTranslateTextWithModelTests.java | 10 +++++++--- 4 files changed, 28 insertions(+), 12 deletions(-) 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