use of io.grpc.internal.NoopClientCall in project grpc-java by grpc.
the class ClientCallsTest method unaryFutureCallSuccess.
@Test
public void unaryFutureCallSuccess() throws Exception {
final AtomicReference<ClientCall.Listener<String>> listener = new AtomicReference<>();
final AtomicReference<Integer> message = new AtomicReference<>();
final AtomicReference<Boolean> halfClosed = new AtomicReference<>();
NoopClientCall<Integer, String> call = new NoopClientCall<Integer, String>() {
@Override
public void start(io.grpc.ClientCall.Listener<String> responseListener, Metadata headers) {
listener.set(responseListener);
}
@Override
public void sendMessage(Integer msg) {
message.set(msg);
}
@Override
public void halfClose() {
halfClosed.set(true);
}
};
Integer req = 2;
ListenableFuture<String> future = ClientCalls.futureUnaryCall(call, req);
assertEquals(req, message.get());
assertTrue(halfClosed.get());
listener.get().onMessage("bar");
listener.get().onClose(Status.OK, new Metadata());
assertEquals("bar", future.get());
}
use of io.grpc.internal.NoopClientCall in project grpc-java by grpc.
the class ClientCallsTest method unaryBlockingCallSuccess.
@Test
public void unaryBlockingCallSuccess() throws Exception {
Integer req = 2;
final String resp = "bar";
final Status status = Status.OK;
final Metadata trailers = new Metadata();
NoopClientCall<Integer, String> call = new NoopClientCall<Integer, String>() {
@Override
public void start(ClientCall.Listener<String> listener, Metadata headers) {
listener.onMessage(resp);
listener.onClose(status, trailers);
}
};
String actualResponse = ClientCalls.blockingUnaryCall(call, req);
assertEquals(resp, actualResponse);
}
use of io.grpc.internal.NoopClientCall in project grpc-java by grpc.
the class ClientCallsTest method blockingUnaryCall_HasBlockingStubType.
@Test
public void blockingUnaryCall_HasBlockingStubType() {
NoopClientCall<Integer, Integer> call = new NoopClientCall<Integer, Integer>() {
@Override
public void start(io.grpc.ClientCall.Listener<Integer> listener, Metadata headers) {
listener.onMessage(1);
listener.onClose(Status.OK, new Metadata());
}
};
when(mockChannel.newCall(ArgumentMatchers.<MethodDescriptor<Integer, Integer>>any(), any(CallOptions.class))).thenReturn(call);
Integer unused = ClientCalls.blockingUnaryCall(mockChannel, UNARY_METHOD, CallOptions.DEFAULT, 1);
verify(mockChannel).newCall(methodDescriptorCaptor.capture(), callOptionsCaptor.capture());
CallOptions capturedCallOption = callOptionsCaptor.getValue();
assertThat(capturedCallOption.getOption(ClientCalls.STUB_TYPE_OPTION)).isEquivalentAccordingToCompareTo(StubType.BLOCKING);
}
use of io.grpc.internal.NoopClientCall in project grpc-java by grpc.
the class ClientCallsTest method blockingServerStreamingCall_HasBlockingStubType.
@Test
public void blockingServerStreamingCall_HasBlockingStubType() {
NoopClientCall<Integer, Integer> call = new NoopClientCall<Integer, Integer>() {
@Override
public void start(io.grpc.ClientCall.Listener<Integer> listener, Metadata headers) {
listener.onMessage(1);
listener.onClose(Status.OK, new Metadata());
}
};
when(mockChannel.newCall(ArgumentMatchers.<MethodDescriptor<Integer, Integer>>any(), any(CallOptions.class))).thenReturn(call);
Iterator<Integer> unused = ClientCalls.blockingServerStreamingCall(mockChannel, UNARY_METHOD, CallOptions.DEFAULT, 1);
verify(mockChannel).newCall(methodDescriptorCaptor.capture(), callOptionsCaptor.capture());
CallOptions capturedCallOption = callOptionsCaptor.getValue();
assertThat(capturedCallOption.getOption(ClientCalls.STUB_TYPE_OPTION)).isEquivalentAccordingToCompareTo(StubType.BLOCKING);
}
use of io.grpc.internal.NoopClientCall in project grpc-java by grpc.
the class ClientCallsTest method unaryFutureCallCancelled.
@Test
public void unaryFutureCallCancelled() throws Exception {
final AtomicReference<ClientCall.Listener<String>> listener = new AtomicReference<>();
final AtomicReference<String> cancelMessage = new AtomicReference<>();
final AtomicReference<Throwable> cancelCause = new AtomicReference<>();
NoopClientCall<Integer, String> call = new NoopClientCall<Integer, String>() {
@Override
public void start(io.grpc.ClientCall.Listener<String> responseListener, Metadata headers) {
listener.set(responseListener);
}
@Override
public void cancel(String message, Throwable cause) {
cancelMessage.set(message);
cancelCause.set(cause);
}
};
Integer req = 2;
ListenableFuture<String> future = ClientCalls.futureUnaryCall(call, req);
future.cancel(true);
assertEquals("GrpcFuture was cancelled", cancelMessage.get());
assertNull(cancelCause.get());
listener.get().onMessage("bar");
listener.get().onClose(Status.OK, new Metadata());
try {
future.get();
fail("Should fail");
} catch (CancellationException e) {
// Exepcted
}
}
Aggregations