Search in sources :

Example 26 with StatusRuntimeException

use of org.apache.beam.vendor.grpc.v1p43p2.io.grpc.StatusRuntimeException in project google-cloud-java by GoogleCloudPlatform.

the class SpeechClientTest method longRunningRecognizeExceptionTest.

@Test
@SuppressWarnings("all")
public void longRunningRecognizeExceptionTest() throws Exception {
    StatusRuntimeException exception = new StatusRuntimeException(Status.INVALID_ARGUMENT);
    mockSpeech.addException(exception);
    try {
        RecognitionConfig.AudioEncoding encoding = RecognitionConfig.AudioEncoding.FLAC;
        int sampleRateHertz = 44100;
        String languageCode = "en-US";
        RecognitionConfig config = RecognitionConfig.newBuilder().setEncoding(encoding).setSampleRateHertz(sampleRateHertz).setLanguageCode(languageCode).build();
        String uri = "gs://bucket_name/file_name.flac";
        RecognitionAudio audio = RecognitionAudio.newBuilder().setUri(uri).build();
        client.longRunningRecognizeAsync(config, audio).get();
        Assert.fail("No exception raised");
    } catch (ExecutionException e) {
        Assert.assertEquals(ApiException.class, e.getCause().getClass());
        ApiException apiException = (ApiException) e.getCause();
        Assert.assertEquals(Status.INVALID_ARGUMENT.getCode(), apiException.getStatusCode());
    }
}
Also used : RecognitionAudio(com.google.cloud.speech.v1.RecognitionAudio) AudioEncoding(com.google.cloud.speech.v1.RecognitionConfig.AudioEncoding) StatusRuntimeException(io.grpc.StatusRuntimeException) RecognitionConfig(com.google.cloud.speech.v1.RecognitionConfig) ExecutionException(java.util.concurrent.ExecutionException) ApiException(com.google.api.gax.grpc.ApiException) Test(org.junit.Test)

Example 27 with StatusRuntimeException

use of org.apache.beam.vendor.grpc.v1p43p2.io.grpc.StatusRuntimeException in project google-cloud-java by GoogleCloudPlatform.

the class SpeechClientTest method recognizeExceptionTest.

@Test
@SuppressWarnings("all")
public void recognizeExceptionTest() throws Exception {
    StatusRuntimeException exception = new StatusRuntimeException(Status.INVALID_ARGUMENT);
    mockSpeech.addException(exception);
    try {
        RecognitionConfig.AudioEncoding encoding = RecognitionConfig.AudioEncoding.FLAC;
        int sampleRateHertz = 44100;
        String languageCode = "en-US";
        RecognitionConfig config = RecognitionConfig.newBuilder().setEncoding(encoding).setSampleRateHertz(sampleRateHertz).setLanguageCode(languageCode).build();
        String uri = "gs://bucket_name/file_name.flac";
        RecognitionAudio audio = RecognitionAudio.newBuilder().setUri(uri).build();
        client.recognize(config, audio);
        Assert.fail("No exception raised");
    } catch (ApiException e) {
        Assert.assertEquals(Status.INVALID_ARGUMENT.getCode(), e.getStatusCode());
    }
}
Also used : RecognitionAudio(com.google.cloud.speech.v1.RecognitionAudio) AudioEncoding(com.google.cloud.speech.v1.RecognitionConfig.AudioEncoding) StatusRuntimeException(io.grpc.StatusRuntimeException) RecognitionConfig(com.google.cloud.speech.v1.RecognitionConfig) ApiException(com.google.api.gax.grpc.ApiException) Test(org.junit.Test)

Example 28 with StatusRuntimeException

use of org.apache.beam.vendor.grpc.v1p43p2.io.grpc.StatusRuntimeException in project google-cloud-java by GoogleCloudPlatform.

the class SpeechClientTest method streamingRecognizeExceptionTest.

@Test
@SuppressWarnings("all")
public void streamingRecognizeExceptionTest() throws Exception {
    StatusRuntimeException exception = new StatusRuntimeException(Status.INVALID_ARGUMENT);
    mockSpeech.addException(exception);
    StreamingRecognizeRequest request = StreamingRecognizeRequest.newBuilder().build();
    MockStreamObserver<StreamingRecognizeResponse> responseObserver = new MockStreamObserver<>();
    StreamingCallable<StreamingRecognizeRequest, StreamingRecognizeResponse> callable = client.streamingRecognizeCallable();
    ApiStreamObserver<StreamingRecognizeRequest> requestObserver = callable.bidiStreamingCall(responseObserver);
    requestObserver.onNext(request);
    try {
        List<StreamingRecognizeResponse> actualResponses = responseObserver.future().get();
        Assert.fail("No exception thrown");
    } catch (ExecutionException e) {
        Assert.assertTrue(e.getCause() instanceof StatusRuntimeException);
        StatusRuntimeException statusException = (StatusRuntimeException) e.getCause();
        Assert.assertEquals(Status.INVALID_ARGUMENT, statusException.getStatus());
    }
}
Also used : StreamingRecognizeRequest(com.google.cloud.speech.v1.StreamingRecognizeRequest) StatusRuntimeException(io.grpc.StatusRuntimeException) StreamingRecognizeResponse(com.google.cloud.speech.v1.StreamingRecognizeResponse) MockStreamObserver(com.google.api.gax.grpc.testing.MockStreamObserver) ExecutionException(java.util.concurrent.ExecutionException) Test(org.junit.Test)

Example 29 with StatusRuntimeException

use of org.apache.beam.vendor.grpc.v1p43p2.io.grpc.StatusRuntimeException in project google-cloud-java by GoogleCloudPlatform.

the class LanguageServiceClientTest method analyzeSyntaxExceptionTest.

@Test
@SuppressWarnings("all")
public void analyzeSyntaxExceptionTest() throws Exception {
    StatusRuntimeException exception = new StatusRuntimeException(Status.INVALID_ARGUMENT);
    mockLanguageService.addException(exception);
    try {
        Document document = Document.newBuilder().build();
        EncodingType encodingType = EncodingType.NONE;
        client.analyzeSyntax(document, encodingType);
        Assert.fail("No exception raised");
    } catch (ApiException e) {
        Assert.assertEquals(Status.INVALID_ARGUMENT.getCode(), e.getStatusCode());
    }
}
Also used : StatusRuntimeException(io.grpc.StatusRuntimeException) EncodingType(com.google.cloud.language.v1beta2.EncodingType) Document(com.google.cloud.language.v1beta2.Document) ApiException(com.google.api.gax.grpc.ApiException) Test(org.junit.Test)

Example 30 with StatusRuntimeException

use of org.apache.beam.vendor.grpc.v1p43p2.io.grpc.StatusRuntimeException in project google-cloud-java by GoogleCloudPlatform.

the class LanguageServiceClientTest method annotateTextExceptionTest.

@Test
@SuppressWarnings("all")
public void annotateTextExceptionTest() throws Exception {
    StatusRuntimeException exception = new StatusRuntimeException(Status.INVALID_ARGUMENT);
    mockLanguageService.addException(exception);
    try {
        Document document = Document.newBuilder().build();
        AnnotateTextRequest.Features features = AnnotateTextRequest.Features.newBuilder().build();
        EncodingType encodingType = EncodingType.NONE;
        client.annotateText(document, features, encodingType);
        Assert.fail("No exception raised");
    } catch (ApiException e) {
        Assert.assertEquals(Status.INVALID_ARGUMENT.getCode(), e.getStatusCode());
    }
}
Also used : AnnotateTextRequest(com.google.cloud.language.v1beta2.AnnotateTextRequest) StatusRuntimeException(io.grpc.StatusRuntimeException) EncodingType(com.google.cloud.language.v1beta2.EncodingType) Document(com.google.cloud.language.v1beta2.Document) Features(com.google.cloud.language.v1beta2.AnnotateTextRequest.Features) ApiException(com.google.api.gax.grpc.ApiException) Test(org.junit.Test)

Aggregations

StatusRuntimeException (io.grpc.StatusRuntimeException)240 Test (org.junit.Test)164 ApiException (com.google.api.gax.grpc.ApiException)74 Status (io.grpc.Status)25 StreamObserver (io.grpc.stub.StreamObserver)20 ByteString (com.google.protobuf.ByteString)18 ArrayList (java.util.ArrayList)18 Metadata (io.grpc.Metadata)14 SimpleServiceGrpc (io.grpc.testing.protobuf.SimpleServiceGrpc)13 ExecutionException (java.util.concurrent.ExecutionException)12 JanusGraphGrpcServerBaseTest (org.janusgraph.graphdb.grpc.JanusGraphGrpcServerBaseTest)12 Test (org.junit.jupiter.api.Test)12 SubscriptionName (com.google.pubsub.v1.SubscriptionName)9 ManagedChannel (io.grpc.ManagedChannel)9 StatusRuntimeException (org.apache.beam.vendor.grpc.v1p43p2.io.grpc.StatusRuntimeException)8 BStruct (org.ballerinalang.model.values.BStruct)8 SimpleRequest (io.grpc.testing.integration.Messages.SimpleRequest)7 ChannelCredentials (io.grpc.ChannelCredentials)6 ServerCredentials (io.grpc.ServerCredentials)6 TlsChannelCredentials (io.grpc.TlsChannelCredentials)6