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();
}
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);
}
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();
}
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 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());
}
Aggregations