Search in sources :

Example 36 with HelloReply

use of io.grpc.examples.helloworld.HelloReply in project grpc-java by grpc.

the class SafeMethodCachingInterceptorTest method responseNoCacheDirective_notCached.

@Test
public void responseNoCacheDirective_notCached() throws Exception {
    cacheControlDirectives.add("no-cache");
    HelloReply reply1 = ClientCalls.blockingUnaryCall(channelToUse, safeGreeterSayHelloMethod, CallOptions.DEFAULT, message);
    HelloReply reply2 = ClientCalls.blockingUnaryCall(channelToUse, safeGreeterSayHelloMethod, CallOptions.DEFAULT, message);
    assertNotEquals(reply1, reply2);
    assertNotEquals(reply1, reply2);
    Truth.assertThat(cache.internalCache).isEmpty();
    Truth.assertThat(cache.removedKeys).isEmpty();
}
Also used : HelloReply(io.grpc.examples.helloworld.HelloReply) Test(org.junit.Test)

Example 37 with HelloReply

use of io.grpc.examples.helloworld.HelloReply in project grpc-java by grpc.

the class AuthClientTest method setUp.

@Before
public void setUp() throws IOException {
    // Generate a unique in-process server name.
    String serverName = InProcessServerBuilder.generateName();
    // Create a server, add service, start, and register for automatic graceful shutdown.
    grpcCleanup.register(InProcessServerBuilder.forName(serverName).directExecutor().addService(ServerInterceptors.intercept(new GreeterGrpc.GreeterImplBase() {

        @Override
        public void sayHello(HelloRequest request, StreamObserver<HelloReply> responseObserver) {
            HelloReply reply = HelloReply.newBuilder().setMessage("AuthClientTest user=" + request.getName()).build();
            responseObserver.onNext(reply);
            responseObserver.onCompleted();
        }
    }, mockServerInterceptor)).build().start());
    CallCredentials credentials = new JwtCredential("test-client");
    ManagedChannel channel = InProcessChannelBuilder.forName(serverName).directExecutor().build();
    client = new AuthClient(credentials, channel);
}
Also used : HelloRequest(io.grpc.examples.helloworld.HelloRequest) GreeterGrpc(io.grpc.examples.helloworld.GreeterGrpc) ManagedChannel(io.grpc.ManagedChannel) HelloReply(io.grpc.examples.helloworld.HelloReply) CallCredentials(io.grpc.CallCredentials) Before(org.junit.Before)

Example 38 with HelloReply

use of io.grpc.examples.helloworld.HelloReply in project grpc-java by grpc.

the class AuthClient method greet.

/**
 * Say hello to server.
 *
 * @param name name to set in HelloRequest
 * @return the message in the HelloReply from the server
 */
public String greet(String name) {
    logger.info("Will try to greet " + name + " ...");
    HelloRequest request = HelloRequest.newBuilder().setName(name).build();
    // Use a stub with the given call credentials applied to invoke the RPC.
    HelloReply response = blockingStub.withCallCredentials(callCredentials).sayHello(request);
    logger.info("Greeting: " + response.getMessage());
    return response.getMessage();
}
Also used : HelloRequest(io.grpc.examples.helloworld.HelloRequest) HelloReply(io.grpc.examples.helloworld.HelloReply)

Example 39 with HelloReply

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();
}
Also used : HelloReply(io.grpc.examples.helloworld.HelloReply)

Example 40 with HelloReply

use of io.grpc.examples.helloworld.HelloReply in project grpc-java by grpc.

the class HelloJsonClient method greet.

/**
 * Say hello to server.
 */
public void greet(String name) {
    logger.info("Will try to greet " + name + " ...");
    HelloRequest request = HelloRequest.newBuilder().setName(name).build();
    HelloReply response;
    try {
        response = blockingStub.sayHello(request);
    } catch (StatusRuntimeException e) {
        logger.log(Level.WARNING, "RPC failed: {0}", e.getStatus());
        return;
    }
    logger.info("Greeting: " + response.getMessage());
}
Also used : HelloRequest(io.grpc.examples.helloworld.HelloRequest) StatusRuntimeException(io.grpc.StatusRuntimeException) HelloReply(io.grpc.examples.helloworld.HelloReply)

Aggregations

HelloReply (io.grpc.examples.helloworld.HelloReply)55 Test (org.junit.Test)30 HelloRequest (io.grpc.examples.helloworld.HelloRequest)20 StatusRuntimeException (io.grpc.StatusRuntimeException)8 GreeterGrpc (io.grpc.examples.helloworld.GreeterGrpc)6 CountDownLatch (java.util.concurrent.CountDownLatch)6 Metadata (io.grpc.Metadata)5 Status (io.grpc.Status)5 GreeterFutureStub (io.grpc.examples.helloworld.GreeterGrpc.GreeterFutureStub)4 SpanCustomizer (brave.SpanCustomizer)3 ManagedChannel (io.grpc.ManagedChannel)3 Span (zipkin2.Span)3 TraceContext (brave.propagation.TraceContext)2 ClientCall (io.grpc.ClientCall)2 Server (io.grpc.Server)2 GreeterStub (io.grpc.examples.helloworld.GreeterGrpc.GreeterStub)2 HostnameGreeter (io.grpc.examples.hostname.HostnameGreeter)2 StreamObserver (io.grpc.stub.StreamObserver)2 ExecutionException (java.util.concurrent.ExecutionException)2 CurrentSpanCustomizer (brave.CurrentSpanCustomizer)1