Search in sources :

Example 1 with MockStreamObserver

use of com.google.api.gax.grpc.testing.MockStreamObserver 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.v1beta1.StreamingRecognizeRequest) StatusRuntimeException(io.grpc.StatusRuntimeException) StreamingRecognizeResponse(com.google.cloud.speech.v1beta1.StreamingRecognizeResponse) MockStreamObserver(com.google.api.gax.grpc.testing.MockStreamObserver) ExecutionException(java.util.concurrent.ExecutionException) Test(org.junit.Test)

Example 2 with MockStreamObserver

use of com.google.api.gax.grpc.testing.MockStreamObserver in project google-cloud-java by GoogleCloudPlatform.

the class SpeechClientTest method streamingRecognizeTest.

@Test
@SuppressWarnings("all")
public void streamingRecognizeTest() throws Exception {
    StreamingRecognizeResponse expectedResponse = StreamingRecognizeResponse.newBuilder().build();
    mockSpeech.addResponse(expectedResponse);
    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);
    requestObserver.onCompleted();
    List<StreamingRecognizeResponse> actualResponses = responseObserver.future().get();
    Assert.assertEquals(1, actualResponses.size());
    Assert.assertEquals(expectedResponse, actualResponses.get(0));
}
Also used : StreamingRecognizeRequest(com.google.cloud.speech.v1.StreamingRecognizeRequest) StreamingRecognizeResponse(com.google.cloud.speech.v1.StreamingRecognizeResponse) MockStreamObserver(com.google.api.gax.grpc.testing.MockStreamObserver) Test(org.junit.Test)

Example 3 with MockStreamObserver

use of com.google.api.gax.grpc.testing.MockStreamObserver 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 4 with MockStreamObserver

use of com.google.api.gax.grpc.testing.MockStreamObserver in project google-cloud-java by GoogleCloudPlatform.

the class SpeechClientTest method streamingRecognizeTest.

@Test
@SuppressWarnings("all")
public void streamingRecognizeTest() throws Exception {
    int resultIndex = 520358448;
    StreamingRecognizeResponse expectedResponse = StreamingRecognizeResponse.newBuilder().setResultIndex(resultIndex).build();
    mockSpeech.addResponse(expectedResponse);
    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);
    requestObserver.onCompleted();
    List<StreamingRecognizeResponse> actualResponses = responseObserver.future().get();
    Assert.assertEquals(1, actualResponses.size());
    Assert.assertEquals(expectedResponse, actualResponses.get(0));
}
Also used : StreamingRecognizeRequest(com.google.cloud.speech.v1beta1.StreamingRecognizeRequest) StreamingRecognizeResponse(com.google.cloud.speech.v1beta1.StreamingRecognizeResponse) MockStreamObserver(com.google.api.gax.grpc.testing.MockStreamObserver) Test(org.junit.Test)

Example 5 with MockStreamObserver

use of com.google.api.gax.grpc.testing.MockStreamObserver in project google-cloud-java by GoogleCloudPlatform.

the class SubscriptionAdminClientTest method streamingPullExceptionTest.

@Test
@SuppressWarnings("all")
public void streamingPullExceptionTest() throws Exception {
    StatusRuntimeException exception = new StatusRuntimeException(Status.INVALID_ARGUMENT);
    mockSubscriber.addException(exception);
    SubscriptionName subscription = SubscriptionName.create("[PROJECT]", "[SUBSCRIPTION]");
    int streamAckDeadlineSeconds = 1875467245;
    StreamingPullRequest request = StreamingPullRequest.newBuilder().setSubscriptionWithSubscriptionName(subscription).setStreamAckDeadlineSeconds(streamAckDeadlineSeconds).build();
    MockStreamObserver<StreamingPullResponse> responseObserver = new MockStreamObserver<>();
    StreamingCallable<StreamingPullRequest, StreamingPullResponse> callable = client.streamingPullCallable();
    ApiStreamObserver<StreamingPullRequest> requestObserver = callable.bidiStreamingCall(responseObserver);
    requestObserver.onNext(request);
    try {
        List<StreamingPullResponse> 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 : StreamingPullResponse(com.google.pubsub.v1.StreamingPullResponse) StatusRuntimeException(io.grpc.StatusRuntimeException) SubscriptionName(com.google.pubsub.v1.SubscriptionName) MockStreamObserver(com.google.api.gax.grpc.testing.MockStreamObserver) ExecutionException(java.util.concurrent.ExecutionException) StreamingPullRequest(com.google.pubsub.v1.StreamingPullRequest) Test(org.junit.Test)

Aggregations

MockStreamObserver (com.google.api.gax.grpc.testing.MockStreamObserver)6 Test (org.junit.Test)6 StatusRuntimeException (io.grpc.StatusRuntimeException)3 ExecutionException (java.util.concurrent.ExecutionException)3 StreamingRecognizeRequest (com.google.cloud.speech.v1.StreamingRecognizeRequest)2 StreamingRecognizeResponse (com.google.cloud.speech.v1.StreamingRecognizeResponse)2 StreamingRecognizeRequest (com.google.cloud.speech.v1beta1.StreamingRecognizeRequest)2 StreamingRecognizeResponse (com.google.cloud.speech.v1beta1.StreamingRecognizeResponse)2 StreamingPullRequest (com.google.pubsub.v1.StreamingPullRequest)2 StreamingPullResponse (com.google.pubsub.v1.StreamingPullResponse)2 SubscriptionName (com.google.pubsub.v1.SubscriptionName)2