Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

translate: use unique gcs folders for batch translate tests #2053

Merged
merged 4 commits into from
Feb 5, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.PrintStream;
import java.util.UUID;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeoutException;

Expand All @@ -43,6 +44,8 @@
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 PREFIX_PATH = PREFIX + UUID.randomUUID().toString() + "/";

private ByteArrayOutputStream bout;
private PrintStream out;
Expand All @@ -53,7 +56,7 @@ private static void cleanUpBucket() {
storage.list(
PROJECT_ID,
Storage.BlobListOption.currentDirectory(),
Storage.BlobListOption.prefix("BATCH_TRANSLATION_OUTPUT/"));
Storage.BlobListOption.prefix(PREFIX));

deleteDirectory(storage, blobs);
}
Expand Down Expand Up @@ -102,7 +105,7 @@ public void tearDown() {
public void testBatchTranslateText()
throws InterruptedException, ExecutionException, IOException, TimeoutException {
BatchTranslateText.batchTranslateText(
PROJECT_ID, "en", "es", INPUT_URI, "gs://" + PROJECT_ID + "/BATCH_TRANSLATION_OUTPUT/");
PROJECT_ID, "en", "es", INPUT_URI, "gs://" + PROJECT_ID + "/" + PREFIX_PATH);
String got = bout.toString();
assertThat(got).contains("Total Characters: 13");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ public class BatchTranslateTextWithGlossaryAndModelTests {
private static final String MODEL_ID = "TRL2188848820815848149";
private static final String GLOSSARY_INPUT_URI =
"gs://cloud-samples-data/translation/glossary_ja.csv";
private static final String PREFIX = "BATCH_TRANSLATION_OUTPUT/";
private static final String PREFIX_PATH = PREFIX + UUID.randomUUID().toString() + "/";

private ByteArrayOutputStream bout;
private PrintStream out;
Expand All @@ -74,7 +76,7 @@ private static final void cleanUpBucket() {
storage.list(
PROJECT_ID,
Storage.BlobListOption.currentDirectory(),
Storage.BlobListOption.prefix("BATCH_TRANSLATION_OUTPUT/"));
Storage.BlobListOption.prefix(PREFIX));

deleteDirectory(storage, blobs);
}
Expand Down Expand Up @@ -137,7 +139,7 @@ public void testBatchTranslateTextWithGlossaryAndModel()
"en",
"ja",
INPUT_URI,
"gs://" + PROJECT_ID + "/BATCH_TRANSLATION_OUTPUT/",
"gs://" + PROJECT_ID + "/" + PREFIX_PATH,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok - but as I look at this, I wonder if String.format should be used as being a bit clearer, I've decided that it's just longer, but I wish we'd get rid of all the string contraction.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated to use a variable.

private static final String OUTPUT_URI =
          String.format("gs://%s/%s/%s/", PROJECT_ID, PREFIX, UUID.randomUUID());

GLOSSARY_ID,
MODEL_ID);
String got = bout.toString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ public class BatchTranslateTextWithGlossaryTests {
"gs://cloud-samples-data/translation/glossary_ja.csv";
private static final String GLOSSARY_ID =
String.format("test_%s", UUID.randomUUID().toString().replace("-", "_").substring(0, 26));
private static final String PREFIX = "BATCH_TRANSLATION_OUTPUT/";
private static final String PREFIX_PATH = PREFIX + UUID.randomUUID().toString() + "/";

private ByteArrayOutputStream bout;
private PrintStream out;
Expand All @@ -73,7 +75,7 @@ private static final void cleanUpBucket() {
storage.list(
PROJECT_ID,
Storage.BlobListOption.currentDirectory(),
Storage.BlobListOption.prefix("BATCH_TRANSLATION_OUTPUT/"));
Storage.BlobListOption.prefix(PREFIX));

deleteDirectory(storage, blobs);
}
Expand Down Expand Up @@ -137,7 +139,7 @@ public void testBatchTranslateTextWithGlossary()
"en",
"ja",
INPUT_URI,
"gs://" + PROJECT_ID + "/BATCH_TRANSLATION_OUTPUT/",
"gs://" + PROJECT_ID + "/" + PREFIX_PATH,
GLOSSARY_ID);
String got = bout.toString();
assertThat(got).contains("Total Characters: 9");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.PrintStream;
import java.util.UUID;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeoutException;

Expand All @@ -45,6 +46,8 @@ public class BatchTranslateTextWithModelTests {
private static final String INPUT_URI =
"gs://cloud-samples-data/translation/custom_model_text.txt";
private static final String MODEL_ID = "TRL2188848820815848149";
private static final String PREFIX = "BATCH_TRANSLATION_OUTPUT/";
private static final String PREFIX_PATH = PREFIX + UUID.randomUUID().toString() + "/";

private ByteArrayOutputStream bout;
private PrintStream out;
Expand All @@ -55,7 +58,7 @@ private static final void cleanUpBucket() {
storage.list(
PROJECT_ID,
Storage.BlobListOption.currentDirectory(),
Storage.BlobListOption.prefix("BATCH_TRANSLATION_OUTPUT/"));
Storage.BlobListOption.prefix(PREFIX));

deleteDirectory(storage, blobs);
}
Expand Down Expand Up @@ -108,7 +111,7 @@ public void testBatchTranslateTextWithModel()
"en",
"ja",
INPUT_URI,
"gs://" + PROJECT_ID + "/BATCH_TRANSLATION_OUTPUT/",
"gs://" + PROJECT_ID + "/" + PREFIX_PATH,
MODEL_ID);
String got = bout.toString();
assertThat(got).contains("Total Characters: 15");
Expand Down