use of io.grpc.examples.helloworld.HelloReply in project grpc-java by grpc.
the class HostnameGreeter method sayHello.
@Override
public void sayHello(HelloRequest req, StreamObserver<HelloReply> responseObserver) {
HelloReply reply = HelloReply.newBuilder().setMessage("Hello " + req.getName() + ", from " + serverName).build();
responseObserver.onNext(reply);
responseObserver.onCompleted();
}
use of io.grpc.examples.helloworld.HelloReply in project grpc-java by grpc.
the class HostnameGreeterTest method sayHello_dynamicHostname.
@Test
public void sayHello_dynamicHostname() throws Exception {
grpcCleanup.register(InProcessServerBuilder.forName("hostname").directExecutor().addService(new HostnameGreeter(null)).build().start());
// Just verifing the service doesn't crash
HelloReply reply = blockingStub.sayHello(HelloRequest.newBuilder().setName("anonymous").build());
assertTrue(reply.getMessage(), reply.getMessage().startsWith("Hello anonymous, from "));
}
use of io.grpc.examples.helloworld.HelloReply in project grpc-java by grpc.
the class DetailErrorSample method asyncCall.
void asyncCall() {
GreeterStub stub = GreeterGrpc.newStub(channel);
HelloRequest request = HelloRequest.newBuilder().build();
final CountDownLatch latch = new CountDownLatch(1);
StreamObserver<HelloReply> responseObserver = new StreamObserver<HelloReply>() {
@Override
public void onNext(HelloReply value) {
// Won't be called.
}
@Override
public void onError(Throwable t) {
verifyErrorReply(t);
latch.countDown();
}
@Override
public void onCompleted() {
// Won't be called, since the server in this example always fails.
}
};
stub.sayHello(request, responseObserver);
if (!Uninterruptibles.awaitUninterruptibly(latch, 1, TimeUnit.SECONDS)) {
throw new RuntimeException("timeout!");
}
}
use of io.grpc.examples.helloworld.HelloReply in project grpc-java by grpc.
the class DetailErrorSample method advancedAsyncCall.
/**
* This is more advanced and does not make use of the stub. You should not normally need to do
* this, but here is how you would.
*/
void advancedAsyncCall() {
ClientCall<HelloRequest, HelloReply> call = channel.newCall(GreeterGrpc.getSayHelloMethod(), CallOptions.DEFAULT);
final CountDownLatch latch = new CountDownLatch(1);
call.start(new ClientCall.Listener<HelloReply>() {
@Override
public void onClose(Status status, Metadata trailers) {
Verify.verify(status.getCode() == Status.Code.INTERNAL);
Verify.verify(trailers.containsKey(DEBUG_INFO_TRAILER_KEY));
try {
Verify.verify(trailers.get(DEBUG_INFO_TRAILER_KEY).equals(DEBUG_INFO));
} catch (IllegalArgumentException e) {
throw new VerifyException(e);
}
latch.countDown();
}
}, new Metadata());
call.sendMessage(HelloRequest.newBuilder().build());
call.halfClose();
if (!Uninterruptibles.awaitUninterruptibly(latch, 1, TimeUnit.SECONDS)) {
throw new RuntimeException("timeout!");
}
}
use of io.grpc.examples.helloworld.HelloReply in project brave by openzipkin.
the class BaseITTracingClientInterceptor method setsErrorTag_onCanceledFuture.
@Test
public void setsErrorTag_onCanceledFuture() {
server.enqueueDelay(TimeUnit.SECONDS.toMillis(1));
ListenableFuture<HelloReply> resp = GreeterGrpc.newFutureStub(client).sayHello(HELLO_REQUEST);
assumeTrue("lost race on cancel", resp.cancel(true));
MutableSpan span = testSpanHandler.takeRemoteSpanWithErrorTag(CLIENT, "CANCELLED");
assertThat(span.tags().get("grpc.status_code")).isEqualTo("CANCELLED");
}
Aggregations