use of io.grpc.testing.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<ClientCall.Listener<String>>();
final AtomicReference<Integer> message = new AtomicReference<Integer>();
final AtomicReference<Boolean> halfClosed = new AtomicReference<Boolean>();
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.testing.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.testing.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<ClientCall.Listener<String>>();
final AtomicReference<String> cancelMessage = new AtomicReference<String>();
final AtomicReference<Throwable> cancelCause = new AtomicReference<Throwable>();
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
}
}
use of io.grpc.testing.NoopClientCall in project grpc-java by grpc.
the class ClientCallsTest method blockingResponseStreamFailed.
@Test
public void blockingResponseStreamFailed() throws Exception {
final AtomicReference<ClientCall.Listener<String>> listener = new AtomicReference<ClientCall.Listener<String>>();
NoopClientCall<Integer, String> call = new NoopClientCall<Integer, String>() {
@Override
public void start(io.grpc.ClientCall.Listener<String> responseListener, Metadata headers) {
listener.set(responseListener);
}
};
Integer req = 2;
Iterator<String> iter = ClientCalls.blockingServerStreamingCall(call, req);
Metadata trailers = new Metadata();
listener.get().onClose(Status.INTERNAL, trailers);
try {
iter.next();
fail("Should fail");
} catch (Throwable e) {
Status status = Status.fromThrowable(e);
assertEquals(Status.INTERNAL, status);
Metadata metadata = Status.trailersFromThrowable(e);
assertSame(trailers, metadata);
}
}
use of io.grpc.testing.NoopClientCall in project grpc-java by grpc.
the class ClientCallsTest method unaryFutureCallFailed.
@Test
public void unaryFutureCallFailed() throws Exception {
final AtomicReference<ClientCall.Listener<String>> listener = new AtomicReference<ClientCall.Listener<String>>();
NoopClientCall<Integer, String> call = new NoopClientCall<Integer, String>() {
@Override
public void start(io.grpc.ClientCall.Listener<String> responseListener, Metadata headers) {
listener.set(responseListener);
}
};
Integer req = 2;
ListenableFuture<String> future = ClientCalls.futureUnaryCall(call, req);
Metadata trailers = new Metadata();
listener.get().onClose(Status.INTERNAL, trailers);
try {
future.get();
fail("Should fail");
} catch (ExecutionException e) {
Status status = Status.fromThrowable(e);
assertEquals(Status.INTERNAL, status);
Metadata metadata = Status.trailersFromThrowable(e);
assertSame(trailers, metadata);
}
}
Aggregations