Skip to content

Commit f735170

Browse files
authored
translate: bump batch request timeouts (#1951)
1 parent 0b04cfd commit f735170

File tree

6 files changed

+21
-12
lines changed

6 files changed

+21
-12
lines changed

translate/cloud-client/src/main/java/com/example/translate/BatchTranslateTextWithGlossary.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,13 @@
3232

3333
import java.io.IOException;
3434
import java.util.concurrent.ExecutionException;
35+
import java.util.concurrent.TimeUnit;
36+
import java.util.concurrent.TimeoutException;
3537

3638
public class BatchTranslateTextWithGlossary {
3739

3840
public static void batchTranslateTextWithGlossary()
39-
throws InterruptedException, ExecutionException, IOException {
41+
throws InterruptedException, ExecutionException, IOException, TimeoutException {
4042
// TODO(developer): Replace these variables before running the sample.
4143
String projectId = "YOUR-PROJECT-ID";
4244
// Supported Languages: https://cloud.google.com/translate/docs/languages
@@ -57,7 +59,7 @@ public static void batchTranslateTextWithGlossary(
5759
String inputUri,
5860
String outputUri,
5961
String glossaryId)
60-
throws IOException, ExecutionException, InterruptedException {
62+
throws IOException, ExecutionException, InterruptedException, TimeoutException {
6163

6264
// Initialize client that will be used to send requests. This client only needs to be created
6365
// once, and can be reused for multiple requests. After completing all of your requests, call
@@ -102,7 +104,7 @@ public static void batchTranslateTextWithGlossary(
102104
client.batchTranslateTextAsync(request);
103105

104106
System.out.println("Waiting for operation to complete...");
105-
BatchTranslateResponse response = future.get();
107+
BatchTranslateResponse response = future.get(120, TimeUnit.SECONDS);
106108
// Display the translation for each input text provided
107109
System.out.printf("Total Characters: %s\n", response.getTotalCharacters());
108110
System.out.printf("Translated Characters: %s\n", response.getTranslatedCharacters());

translate/cloud-client/src/main/java/com/example/translate/BatchTranslateTextWithGlossaryAndModel.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,13 @@
3232

3333
import java.io.IOException;
3434
import java.util.concurrent.ExecutionException;
35+
import java.util.concurrent.TimeUnit;
36+
import java.util.concurrent.TimeoutException;
3537

3638
public class BatchTranslateTextWithGlossaryAndModel {
3739

3840
public static void batchTranslateTextWithGlossaryAndModel()
39-
throws InterruptedException, ExecutionException, IOException {
41+
throws InterruptedException, ExecutionException, IOException, TimeoutException {
4042
// TODO(developer): Replace these variables before running the sample.
4143
String projectId = "YOUR-PROJECT-ID";
4244
// Supported Languages: https://cloud.google.com/translate/docs/languages
@@ -59,7 +61,7 @@ public static void batchTranslateTextWithGlossaryAndModel(
5961
String outputUri,
6062
String glossaryId,
6163
String modelId)
62-
throws IOException, ExecutionException, InterruptedException {
64+
throws IOException, ExecutionException, InterruptedException, TimeoutException {
6365

6466
// Initialize client that will be used to send requests. This client only needs to be created
6567
// once, and can be reused for multiple requests. After completing all of your requests, call
@@ -109,7 +111,7 @@ public static void batchTranslateTextWithGlossaryAndModel(
109111
client.batchTranslateTextAsync(request);
110112

111113
System.out.println("Waiting for operation to complete...");
112-
BatchTranslateResponse response = future.get();
114+
BatchTranslateResponse response = future.get(120, TimeUnit.SECONDS);
113115
// Display the translation for each input text provided
114116
System.out.printf("Total Characters: %s\n", response.getTotalCharacters());
115117
System.out.printf("Translated Characters: %s\n", response.getTranslatedCharacters());

translate/cloud-client/src/main/java/com/example/translate/BatchTranslateTextWithModel.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,13 @@
3030

3131
import java.io.IOException;
3232
import java.util.concurrent.ExecutionException;
33+
import java.util.concurrent.TimeUnit;
34+
import java.util.concurrent.TimeoutException;
3335

3436
public class BatchTranslateTextWithModel {
3537

3638
public static void batchTranslateTextWithModel()
37-
throws InterruptedException, ExecutionException, IOException {
39+
throws InterruptedException, ExecutionException, IOException, TimeoutException {
3840
// TODO(developer): Replace these variables before running the sample.
3941
String projectId = "YOUR-PROJECT-ID";
4042
// Supported Languages: https://cloud.google.com/translate/docs/languages
@@ -55,7 +57,7 @@ public static void batchTranslateTextWithModel(
5557
String inputUri,
5658
String outputUri,
5759
String modelId)
58-
throws IOException, ExecutionException, InterruptedException {
60+
throws IOException, ExecutionException, InterruptedException, TimeoutException {
5961

6062
// Initialize client that will be used to send requests. This client only needs to be created
6163
// once, and can be reused for multiple requests. After completing all of your requests, call
@@ -99,7 +101,7 @@ public static void batchTranslateTextWithModel(
99101
client.batchTranslateTextAsync(request);
100102

101103
System.out.println("Waiting for operation to complete...");
102-
BatchTranslateResponse response = future.get();
104+
BatchTranslateResponse response = future.get(120, TimeUnit.SECONDS);
103105
// Display the translation for each input text provided
104106
System.out.printf("Total Characters: %s\n", response.getTotalCharacters());
105107
System.out.printf("Translated Characters: %s\n", response.getTranslatedCharacters());

translate/cloud-client/src/test/java/com/example/translate/BatchTranslateTextWithGlossaryAndModelTests.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
import java.util.List;
4444
import java.util.UUID;
4545
import java.util.concurrent.ExecutionException;
46+
import java.util.concurrent.TimeoutException;
4647

4748
import org.junit.After;
4849
import org.junit.Before;
@@ -130,7 +131,7 @@ public void tearDown() throws InterruptedException, ExecutionException, IOExcept
130131

131132
@Test
132133
public void testBatchTranslateTextWithGlossaryAndModel()
133-
throws InterruptedException, ExecutionException, IOException {
134+
throws InterruptedException, ExecutionException, IOException, TimeoutException {
134135
BatchTranslateTextWithGlossaryAndModel.batchTranslateTextWithGlossaryAndModel(
135136
PROJECT_ID,
136137
"en",

translate/cloud-client/src/test/java/com/example/translate/BatchTranslateTextWithGlossaryTests.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
import java.util.List;
4444
import java.util.UUID;
4545
import java.util.concurrent.ExecutionException;
46+
import java.util.concurrent.TimeoutException;
4647

4748
import org.junit.After;
4849
import org.junit.Before;
@@ -130,7 +131,7 @@ public void tearDown() throws InterruptedException, ExecutionException, IOExcept
130131

131132
@Test
132133
public void testBatchTranslateTextWithGlossary()
133-
throws InterruptedException, ExecutionException, IOException {
134+
throws InterruptedException, ExecutionException, IOException, TimeoutException {
134135
BatchTranslateTextWithGlossary.batchTranslateTextWithGlossary(
135136
PROJECT_ID,
136137
"en",

translate/cloud-client/src/test/java/com/example/translate/BatchTranslateTextWithModelTests.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import java.io.IOException;
2929
import java.io.PrintStream;
3030
import java.util.concurrent.ExecutionException;
31+
import java.util.concurrent.TimeoutException;
3132

3233
import org.junit.After;
3334
import org.junit.Before;
@@ -101,7 +102,7 @@ public void tearDown() {
101102

102103
@Test
103104
public void testBatchTranslateTextWithModel()
104-
throws InterruptedException, ExecutionException, IOException {
105+
throws InterruptedException, ExecutionException, IOException, TimeoutException {
105106
BatchTranslateTextWithModel.batchTranslateTextWithModel(
106107
PROJECT_ID,
107108
"en",

0 commit comments

Comments
 (0)