use of com.google.type.Color in project gax-java by googleapis.
the class GrpcDirectStreamingCallableTest method testBidiStreaming.
@Test
public void testBidiStreaming() throws Exception {
BidiStreamingCallable<Color, Money> streamingCallable = GrpcCallableFactory.createBidiStreamingCallable(GrpcCallSettings.create(METHOD_STREAMING_RECOGNIZE), null, clientContext);
CountDownLatch latch = new CountDownLatch(1);
GrpcDirectServerStreamingCallableTest.MoneyObserver moneyObserver = new GrpcDirectServerStreamingCallableTest.MoneyObserver(true, latch);
Color request = Color.newBuilder().setRed(0.5f).build();
ClientStream<Color> stream = streamingCallable.splitCall(moneyObserver);
stream.send(request);
stream.closeSend();
latch.await(20, TimeUnit.SECONDS);
assertThat(moneyObserver.error).isNull();
Money expected = Money.newBuilder().setCurrencyCode("USD").setUnits(127).build();
assertThat(moneyObserver.response).isEqualTo(expected);
assertThat(moneyObserver.completed).isTrue();
}
use of com.google.type.Color in project gax-java by googleapis.
the class GrpcDirectStreamingCallableTest method testBidiStreamingServerError.
@Test
public void testBidiStreamingServerError() throws Exception {
BidiStreamingCallable<Color, Money> streamingCallable = GrpcCallableFactory.createBidiStreamingCallable(GrpcCallSettings.create(METHOD_STREAMING_RECOGNIZE_ERROR), null, clientContext);
CountDownLatch latch = new CountDownLatch(1);
GrpcDirectServerStreamingCallableTest.MoneyObserver moneyObserver = new GrpcDirectServerStreamingCallableTest.MoneyObserver(true, latch);
Color request = Color.newBuilder().setRed(0.5f).build();
ClientStream<Color> stream = streamingCallable.splitCall(moneyObserver);
stream.send(request);
latch.await(20, TimeUnit.SECONDS);
assertThat(moneyObserver.error).isNotNull();
assertThat(moneyObserver.error).isInstanceOf(ApiException.class);
assertThat(moneyObserver.error.getCause()).isInstanceOf(StatusRuntimeException.class);
assertThat(((StatusRuntimeException) moneyObserver.error.getCause()).getStatus()).isEqualTo(Status.INVALID_ARGUMENT);
assertThat(moneyObserver.response).isNull();
}
use of com.google.type.Color in project gax-java by googleapis.
the class GrpcDirectStreamingCallableTest method testClientStreaming.
@Test
public void testClientStreaming() throws Exception {
ClientStreamingCallable<Color, Money> streamingCallable = GrpcCallableFactory.createClientStreamingCallable(GrpcCallSettings.create(METHOD_CLIENT_STREAMING_RECOGNIZE), null, clientContext);
CountDownLatch latch = new CountDownLatch(1);
MoneyObserver moneyObserver = new MoneyObserver(latch);
Color request = Color.newBuilder().setRed(0.5f).build();
ApiStreamObserver<Color> requestObserver = streamingCallable.clientStreamingCall(moneyObserver);
requestObserver.onNext(request);
requestObserver.onCompleted();
latch.await(20, TimeUnit.SECONDS);
assertThat(moneyObserver.error).isNull();
Money expected = Money.newBuilder().setCurrencyCode("USD").setUnits(127).build();
assertThat(moneyObserver.response).isEqualTo(expected);
assertThat(moneyObserver.completed).isTrue();
}
use of com.google.type.Color in project gax-java by googleapis.
the class HttpJsonDirectServerStreamingCallableTest method testBlockingServerStreaming.
@Test
public void testBlockingServerStreaming() {
MOCK_SERVICE.addResponse(new Money[] { DEFAULT_RESPONSE });
Color request = Color.newBuilder().setRed(0.5f).build();
ServerStream<Money> response = streamingCallable.call(request);
List<Money> responseData = Lists.newArrayList(response);
Money expected = Money.newBuilder().setCurrencyCode("USD").setUnits(127).build();
Truth.assertThat(responseData).containsExactly(expected);
}
use of com.google.type.Color in project gax-java by googleapis.
the class GrpcClientCallsTest method testTimeoutBeforeDeadline.
@Test
public void testTimeoutBeforeDeadline() {
MethodDescriptor<Color, Money> descriptor = FakeServiceGrpc.METHOD_RECOGNIZE;
@SuppressWarnings("unchecked") ClientCall<Color, Money> mockClientCall = Mockito.mock(ClientCall.class);
@SuppressWarnings("unchecked") ClientCall.Listener<Money> mockListener = Mockito.mock(ClientCall.Listener.class);
Channel mockChannel = Mockito.mock(ManagedChannel.class);
ArgumentCaptor<CallOptions> capturedCallOptions = ArgumentCaptor.forClass(CallOptions.class);
Mockito.when(mockChannel.newCall(Mockito.eq(descriptor), capturedCallOptions.capture())).thenReturn(mockClientCall);
// Configure a timeout that occurs before the grpc deadline
Duration timeout = Duration.ofSeconds(5);
Deadline subsequentDeadline = Deadline.after(10, TimeUnit.SECONDS);
Deadline minExpectedDeadline = Deadline.after(timeout.getSeconds(), TimeUnit.SECONDS);
GrpcCallContext context = GrpcCallContext.createDefault().withChannel(mockChannel).withCallOptions(CallOptions.DEFAULT.withDeadline(subsequentDeadline)).withTimeout(timeout);
GrpcClientCalls.newCall(descriptor, context).start(mockListener, new Metadata());
// Verify that the timeout is ignored
Deadline maxExpectedDeadline = Deadline.after(timeout.getSeconds(), TimeUnit.SECONDS);
Truth.assertThat(capturedCallOptions.getValue().getDeadline()).isAtLeast(minExpectedDeadline);
Truth.assertThat(capturedCallOptions.getValue().getDeadline()).isAtMost(maxExpectedDeadline);
}
Aggregations