From 1c1053ea462efaa58cbee68cbf6bec693c717dbb Mon Sep 17 00:00:00 2001 From: nnegrey Date: Wed, 15 Jan 2020 12:22:23 -0700 Subject: [PATCH] translate: bump batch request timeouts --- .../example/translate/BatchTranslateTextWithGlossary.java | 8 +++++--- .../translate/BatchTranslateTextWithGlossaryAndModel.java | 8 +++++--- .../example/translate/BatchTranslateTextWithModel.java | 8 +++++--- .../BatchTranslateTextWithGlossaryAndModelTests.java | 3 ++- .../translate/BatchTranslateTextWithGlossaryTests.java | 3 ++- .../translate/BatchTranslateTextWithModelTests.java | 3 ++- 6 files changed, 21 insertions(+), 12 deletions(-) diff --git a/translate/cloud-client/src/main/java/com/example/translate/BatchTranslateTextWithGlossary.java b/translate/cloud-client/src/main/java/com/example/translate/BatchTranslateTextWithGlossary.java index 1f37b7c0390..8971bf61f49 100644 --- a/translate/cloud-client/src/main/java/com/example/translate/BatchTranslateTextWithGlossary.java +++ b/translate/cloud-client/src/main/java/com/example/translate/BatchTranslateTextWithGlossary.java @@ -32,11 +32,13 @@ import java.io.IOException; import java.util.concurrent.ExecutionException; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.TimeoutException; public class BatchTranslateTextWithGlossary { public static void batchTranslateTextWithGlossary() - throws InterruptedException, ExecutionException, IOException { + throws InterruptedException, ExecutionException, IOException, TimeoutException { // TODO(developer): Replace these variables before running the sample. String projectId = "YOUR-PROJECT-ID"; // Supported Languages: https://cloud.google.com/translate/docs/languages @@ -57,7 +59,7 @@ public static void batchTranslateTextWithGlossary( String inputUri, String outputUri, String glossaryId) - throws IOException, ExecutionException, InterruptedException { + throws IOException, ExecutionException, InterruptedException, TimeoutException { // Initialize client that will be used to send requests. This client only needs to be created // once, and can be reused for multiple requests. After completing all of your requests, call @@ -102,7 +104,7 @@ public static void batchTranslateTextWithGlossary( client.batchTranslateTextAsync(request); System.out.println("Waiting for operation to complete..."); - BatchTranslateResponse response = future.get(); + BatchTranslateResponse response = future.get(120, TimeUnit.SECONDS); // Display the translation for each input text provided System.out.printf("Total Characters: %s\n", response.getTotalCharacters()); System.out.printf("Translated Characters: %s\n", response.getTranslatedCharacters()); diff --git a/translate/cloud-client/src/main/java/com/example/translate/BatchTranslateTextWithGlossaryAndModel.java b/translate/cloud-client/src/main/java/com/example/translate/BatchTranslateTextWithGlossaryAndModel.java index f0922884ba6..cee7e7199a8 100644 --- a/translate/cloud-client/src/main/java/com/example/translate/BatchTranslateTextWithGlossaryAndModel.java +++ b/translate/cloud-client/src/main/java/com/example/translate/BatchTranslateTextWithGlossaryAndModel.java @@ -32,11 +32,13 @@ import java.io.IOException; import java.util.concurrent.ExecutionException; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.TimeoutException; public class BatchTranslateTextWithGlossaryAndModel { public static void batchTranslateTextWithGlossaryAndModel() - throws InterruptedException, ExecutionException, IOException { + throws InterruptedException, ExecutionException, IOException, TimeoutException { // TODO(developer): Replace these variables before running the sample. String projectId = "YOUR-PROJECT-ID"; // Supported Languages: https://cloud.google.com/translate/docs/languages @@ -59,7 +61,7 @@ public static void batchTranslateTextWithGlossaryAndModel( String outputUri, String glossaryId, String modelId) - throws IOException, ExecutionException, InterruptedException { + throws IOException, ExecutionException, InterruptedException, TimeoutException { // Initialize client that will be used to send requests. This client only needs to be created // once, and can be reused for multiple requests. After completing all of your requests, call @@ -109,7 +111,7 @@ public static void batchTranslateTextWithGlossaryAndModel( client.batchTranslateTextAsync(request); System.out.println("Waiting for operation to complete..."); - BatchTranslateResponse response = future.get(); + BatchTranslateResponse response = future.get(120, TimeUnit.SECONDS); // Display the translation for each input text provided System.out.printf("Total Characters: %s\n", response.getTotalCharacters()); System.out.printf("Translated Characters: %s\n", response.getTranslatedCharacters()); diff --git a/translate/cloud-client/src/main/java/com/example/translate/BatchTranslateTextWithModel.java b/translate/cloud-client/src/main/java/com/example/translate/BatchTranslateTextWithModel.java index bbf2aff4263..1433444a683 100644 --- a/translate/cloud-client/src/main/java/com/example/translate/BatchTranslateTextWithModel.java +++ b/translate/cloud-client/src/main/java/com/example/translate/BatchTranslateTextWithModel.java @@ -30,11 +30,13 @@ import java.io.IOException; import java.util.concurrent.ExecutionException; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.TimeoutException; public class BatchTranslateTextWithModel { public static void batchTranslateTextWithModel() - throws InterruptedException, ExecutionException, IOException { + throws InterruptedException, ExecutionException, IOException, TimeoutException { // TODO(developer): Replace these variables before running the sample. String projectId = "YOUR-PROJECT-ID"; // Supported Languages: https://cloud.google.com/translate/docs/languages @@ -55,7 +57,7 @@ public static void batchTranslateTextWithModel( String inputUri, String outputUri, String modelId) - throws IOException, ExecutionException, InterruptedException { + throws IOException, ExecutionException, InterruptedException, TimeoutException { // Initialize client that will be used to send requests. This client only needs to be created // once, and can be reused for multiple requests. After completing all of your requests, call @@ -99,7 +101,7 @@ public static void batchTranslateTextWithModel( client.batchTranslateTextAsync(request); System.out.println("Waiting for operation to complete..."); - BatchTranslateResponse response = future.get(); + BatchTranslateResponse response = future.get(120, TimeUnit.SECONDS); // Display the translation for each input text provided System.out.printf("Total Characters: %s\n", response.getTotalCharacters()); System.out.printf("Translated Characters: %s\n", response.getTranslatedCharacters()); diff --git a/translate/cloud-client/src/test/java/com/example/translate/BatchTranslateTextWithGlossaryAndModelTests.java b/translate/cloud-client/src/test/java/com/example/translate/BatchTranslateTextWithGlossaryAndModelTests.java index a91e530a0fb..29da0562812 100644 --- a/translate/cloud-client/src/test/java/com/example/translate/BatchTranslateTextWithGlossaryAndModelTests.java +++ b/translate/cloud-client/src/test/java/com/example/translate/BatchTranslateTextWithGlossaryAndModelTests.java @@ -43,6 +43,7 @@ import java.util.List; import java.util.UUID; import java.util.concurrent.ExecutionException; +import java.util.concurrent.TimeoutException; import org.junit.After; import org.junit.Before; @@ -130,7 +131,7 @@ public void tearDown() throws InterruptedException, ExecutionException, IOExcept @Test public void testBatchTranslateTextWithGlossaryAndModel() - throws InterruptedException, ExecutionException, IOException { + throws InterruptedException, ExecutionException, IOException, TimeoutException { BatchTranslateTextWithGlossaryAndModel.batchTranslateTextWithGlossaryAndModel( PROJECT_ID, "en", diff --git a/translate/cloud-client/src/test/java/com/example/translate/BatchTranslateTextWithGlossaryTests.java b/translate/cloud-client/src/test/java/com/example/translate/BatchTranslateTextWithGlossaryTests.java index 6cefd2e3071..39fb65a58dd 100644 --- a/translate/cloud-client/src/test/java/com/example/translate/BatchTranslateTextWithGlossaryTests.java +++ b/translate/cloud-client/src/test/java/com/example/translate/BatchTranslateTextWithGlossaryTests.java @@ -43,6 +43,7 @@ import java.util.List; import java.util.UUID; import java.util.concurrent.ExecutionException; +import java.util.concurrent.TimeoutException; import org.junit.After; import org.junit.Before; @@ -130,7 +131,7 @@ public void tearDown() throws InterruptedException, ExecutionException, IOExcept @Test public void testBatchTranslateTextWithGlossary() - throws InterruptedException, ExecutionException, IOException { + throws InterruptedException, ExecutionException, IOException, TimeoutException { BatchTranslateTextWithGlossary.batchTranslateTextWithGlossary( PROJECT_ID, "en", diff --git a/translate/cloud-client/src/test/java/com/example/translate/BatchTranslateTextWithModelTests.java b/translate/cloud-client/src/test/java/com/example/translate/BatchTranslateTextWithModelTests.java index 30a4a1553b3..fa6a3852b7d 100644 --- a/translate/cloud-client/src/test/java/com/example/translate/BatchTranslateTextWithModelTests.java +++ b/translate/cloud-client/src/test/java/com/example/translate/BatchTranslateTextWithModelTests.java @@ -28,6 +28,7 @@ import java.io.IOException; import java.io.PrintStream; import java.util.concurrent.ExecutionException; +import java.util.concurrent.TimeoutException; import org.junit.After; import org.junit.Before; @@ -101,7 +102,7 @@ public void tearDown() { @Test public void testBatchTranslateTextWithModel() - throws InterruptedException, ExecutionException, IOException { + throws InterruptedException, ExecutionException, IOException, TimeoutException { BatchTranslateTextWithModel.batchTranslateTextWithModel( PROJECT_ID, "en",