Skip to content

Commit

Permalink
samples: translate: bump batch request timeouts (#1951)
Browse files Browse the repository at this point in the history
  • Loading branch information
nnegrey authored and Shabirmean committed Nov 18, 2022
1 parent fa56558 commit 1378590
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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",
Expand Down

0 comments on commit 1378590

Please sign in to comment.