Skip to content

Commit 924781f

Browse files
kweinmeisteranguillanneuf
authored andcommitted
test: Update batch translate tests to minimize flakiness (#846)
1 parent 383471f commit 924781f

File tree

5 files changed

+10
-16
lines changed

5 files changed

+10
-16
lines changed

translate/snippets/src/test/java/com/example/translate/BatchTranslateTextTests.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,6 @@ public class BatchTranslateTextTests {
4646
private static final String PROJECT_ID = System.getenv("GOOGLE_CLOUD_PROJECT");
4747
private static final String INPUT_URI = "gs://cloud-samples-data/translation/text.txt";
4848
private static final String PREFIX = "BATCH_TRANSLATION_OUTPUT_";
49-
private static final String OUTPUT_URI =
50-
String.format("gs://%s/%s%s/", PROJECT_ID, PREFIX, UUID.randomUUID());
5149

5250
private ByteArrayOutputStream bout;
5351
private PrintStream out;
@@ -115,8 +113,8 @@ public void tearDown() {
115113
@Test
116114
public void testBatchTranslateText()
117115
throws InterruptedException, ExecutionException, IOException, TimeoutException {
118-
BatchTranslateText.batchTranslateText(PROJECT_ID, "en", "es", INPUT_URI, OUTPUT_URI);
119-
116+
String outputUri = String.format("gs://%s/%s%s/", PROJECT_ID, PREFIX, UUID.randomUUID());
117+
BatchTranslateText.batchTranslateText(PROJECT_ID, "en", "es", INPUT_URI, outputUri);
120118
String got = bout.toString();
121119
assertThat(got).contains("Total Characters: 13");
122120
}

translate/snippets/src/test/java/com/example/translate/BatchTranslateTextWithGlossaryAndModelTests.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,6 @@ public class BatchTranslateTextWithGlossaryAndModelTests {
4949
private static final String GLOSSARY_ID = "DO_NOT_DELETE_TEST_GLOSSARY";
5050
private static final String MODEL_ID = "TRL3645318651705294848";
5151
private static final String PREFIX = "BATCH_TRANSLATION_MODEL_GLOS_OUTPUT_";
52-
private static final String OUTPUT_URI =
53-
String.format("gs://%s/%s%s/", PROJECT_ID, PREFIX, UUID.randomUUID());
5452

5553
private ByteArrayOutputStream bout;
5654
private PrintStream out;
@@ -121,8 +119,9 @@ public void tearDown() {
121119
@Test
122120
public void testBatchTranslateTextWithGlossaryAndModel()
123121
throws InterruptedException, ExecutionException, IOException, TimeoutException {
122+
String outputUri = String.format("gs://%s/%s%s/", PROJECT_ID, PREFIX, UUID.randomUUID());
124123
BatchTranslateTextWithGlossaryAndModel.batchTranslateTextWithGlossaryAndModel(
125-
PROJECT_ID, "en", "ja", INPUT_URI, OUTPUT_URI, GLOSSARY_ID, MODEL_ID);
124+
PROJECT_ID, "en", "ja", INPUT_URI, outputUri, GLOSSARY_ID, MODEL_ID);
126125
String got = bout.toString();
127126
assertThat(got).contains("Total Characters: 25");
128127
}

translate/snippets/src/test/java/com/example/translate/BatchTranslateTextWithGlossaryTests.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,6 @@ public class BatchTranslateTextWithGlossaryTests {
4848
"gs://cloud-samples-data/translation/text_with_glossary.txt";
4949
private static final String GLOSSARY_ID = "DO_NOT_DELETE_TEST_GLOSSARY";
5050
private static final String PREFIX = "BATCH_TRANSLATION_GLOSSARY_OUTPUT_";
51-
private static final String OUTPUT_URI =
52-
String.format("gs://%s/%s%s/", PROJECT_ID, PREFIX, UUID.randomUUID());
5351

5452
private ByteArrayOutputStream bout;
5553
private PrintStream out;
@@ -120,8 +118,9 @@ public void tearDown() {
120118
@Test
121119
public void testBatchTranslateTextWithGlossary()
122120
throws InterruptedException, ExecutionException, IOException, TimeoutException {
121+
String outputUri = String.format("gs://%s/%s%s/", PROJECT_ID, PREFIX, UUID.randomUUID());
123122
BatchTranslateTextWithGlossary.batchTranslateTextWithGlossary(
124-
PROJECT_ID, "en", "ja", INPUT_URI, OUTPUT_URI, GLOSSARY_ID);
123+
PROJECT_ID, "en", "ja", INPUT_URI, outputUri, GLOSSARY_ID);
125124
String got = bout.toString();
126125
assertThat(got).contains("Total Characters: 9");
127126
}

translate/snippets/src/test/java/com/example/translate/BatchTranslateTextWithModelTests.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,6 @@ public class BatchTranslateTextWithModelTests {
4848
"gs://cloud-samples-data/translation/custom_model_text.txt";
4949
private static final String MODEL_ID = "TRL3645318651705294848";
5050
private static final String PREFIX = "BATCH_TRANSLATION_WITH_MODEL_OUTPUT_";
51-
private static final String OUTPUT_URI =
52-
String.format("gs://%s/%s%s/", PROJECT_ID, PREFIX, UUID.randomUUID());
5351

5452
private ByteArrayOutputStream bout;
5553
private PrintStream out;
@@ -116,8 +114,9 @@ public void tearDown() {
116114
@Test
117115
public void testBatchTranslateTextWithModel()
118116
throws InterruptedException, ExecutionException, IOException, TimeoutException {
117+
String outputUri = String.format("gs://%s/%s%s/", PROJECT_ID, PREFIX, UUID.randomUUID());
119118
BatchTranslateTextWithModel.batchTranslateTextWithModel(
120-
PROJECT_ID, "en", "ja", INPUT_URI, OUTPUT_URI, MODEL_ID);
119+
PROJECT_ID, "en", "ja", INPUT_URI, outputUri, MODEL_ID);
121120
String got = bout.toString();
122121
assertThat(got).contains("Total Characters: 15");
123122
}

translate/snippets/src/test/java/com/example/translatev3beta1/BatchTranslateDocumentTests.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,6 @@ public class BatchTranslateDocumentTests {
4545
private static final String INPUT_URI =
4646
"gs://java-docs-samples-testing/translation/invoice2.docx";
4747
private static final String PREFIX = "BATCH_DOC_TRANSLATION_OUTPUT_";
48-
private static final String OUTPUT_URI =
49-
String.format("gs://%s/%s%s/", PROJECT_ID, PREFIX, UUID.randomUUID());
5048

5149
private ByteArrayOutputStream bout;
5250
private PrintStream out;
@@ -109,8 +107,9 @@ public void tearDown() {
109107
@Test
110108
public void testBatchTranslateDocument()
111109
throws InterruptedException, ExecutionException, IOException, TimeoutException {
110+
String outputUri = String.format("gs://%s/%s%s/", PROJECT_ID, PREFIX, UUID.randomUUID());
112111
BatchTranslateDocument.batchTranslateDocument(
113-
PROJECT_ID, "en-US", "fr-FR", INPUT_URI, OUTPUT_URI, 1000);
112+
PROJECT_ID, "en-US", "fr-FR", INPUT_URI, outputUri, 1000);
114113

115114
String got = bout.toString();
116115
assertThat(got).contains("Total Pages:");

0 commit comments

Comments
 (0)