use of com.google.type.Color in project gax-java by googleapis.
the class GrpcClientCallsTest method testTimeoutToDeadlineConversion.
@Test
public void testTimeoutToDeadlineConversion() {
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);
Duration timeout = Duration.ofSeconds(10);
Deadline minExpectedDeadline = Deadline.after(timeout.getSeconds(), TimeUnit.SECONDS);
GrpcCallContext context = GrpcCallContext.createDefault().withChannel(mockChannel).withTimeout(timeout);
GrpcClientCalls.newCall(descriptor, context).start(mockListener, new Metadata());
Deadline maxExpectedDeadline = Deadline.after(timeout.getSeconds(), TimeUnit.SECONDS);
Truth.assertThat(capturedCallOptions.getValue().getDeadline()).isAtLeast(minExpectedDeadline);
Truth.assertThat(capturedCallOptions.getValue().getDeadline()).isAtMost(maxExpectedDeadline);
}
use of com.google.type.Color in project gax-java by googleapis.
the class GrpcDirectServerStreamingCallableTest method setUp.
@Before
public void setUp() throws InstantiationException, IllegalAccessException, IOException {
String serverName = "fakeservice";
FakeServiceImpl serviceImpl = new FakeServiceImpl();
inprocessServer = new InProcessServer<>(serviceImpl, serverName);
inprocessServer.start();
channel = InProcessChannelBuilder.forName(serverName).directExecutor().usePlaintext().build();
clientContext = ClientContext.newBuilder().setTransportChannel(GrpcTransportChannel.create(channel)).setDefaultCallContext(GrpcCallContext.of(channel, CallOptions.DEFAULT)).build();
streamingCallSettings = ServerStreamingCallSettings.<Color, Money>newBuilder().build();
streamingCallable = GrpcCallableFactory.createServerStreamingCallable(GrpcCallSettings.create(METHOD_SERVER_STREAMING_RECOGNIZE), streamingCallSettings, clientContext);
}
use of com.google.type.Color in project gax-java by googleapis.
the class GrpcDirectServerStreamingCallableTest method testBlockingServerStreaming.
@Test
public void testBlockingServerStreaming() {
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 GrpcDirectStreamingCallableTest method testBidiStreamingClientError.
@Test
public void testBidiStreamingClientError() 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);
ClientStream<Color> stream = streamingCallable.splitCall(moneyObserver);
Throwable clientError = new StatusRuntimeException(Status.CANCELLED);
stream.closeSendWithError(clientError);
latch.await(20, TimeUnit.SECONDS);
assertThat(moneyObserver.error).isNotNull();
assertThat(moneyObserver.error).isInstanceOf(ApiException.class);
assertThat(((ApiException) moneyObserver.error).getStatusCode().getCode()).isEqualTo(Code.CANCELLED);
assertThat(moneyObserver.response).isNull();
// As of gRPC 1.8, when the client closes, the server gRPC issues
// io.grpc.StatusRuntimeException: CANCELLED: cancelled before receiving half close
// to the server application, and our error is not propagated.
// We don't check the error received by the server; we can't round-trip it.
}
use of com.google.type.Color in project gax-java by googleapis.
the class GrpcLongRunningTest method testFutureCallPollDoneOnFirst.
@Test
public void testFutureCallPollDoneOnFirst() throws Exception {
String opName = "testFutureCallPollDoneOnFirst";
Color resp = getColor(0.5f);
Money meta = getMoney("UAH");
Operation initialOperation = getOperation(opName, null, null, false);
Operation resultOperation = getOperation(opName, resp, meta, true);
mockResponse(channel, Code.OK, initialOperation, resultOperation);
OperationCallable<Integer, Color, Money> callable = GrpcCallableFactory.createOperationCallable(createGrpcSettings(), callSettings, initialContext, operationsStub);
OperationFuture<Color, Money> future = callable.futureCall(2);
assertFutureSuccessMetaSuccess(opName, future, resp, meta);
assertThat(executor.getIterationsCount()).isEqualTo(0);
}
Aggregations