Search in sources :

Example 46 with HelloReply

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

the class SafeMethodCachingInterceptorTest method responseMustRevalidateDirective_isIgnored.

@Test
public void responseMustRevalidateDirective_isIgnored() throws Exception {
    cacheControlDirectives.add("must-revalidate");
    HelloReply reply1 = ClientCalls.blockingUnaryCall(channelToUse, safeGreeterSayHelloMethod, CallOptions.DEFAULT, message);
    HelloReply reply2 = ClientCalls.blockingUnaryCall(channelToUse, safeGreeterSayHelloMethod, CallOptions.DEFAULT, message);
    assertSame(reply1, reply2);
}
Also used : HelloReply(io.grpc.examples.helloworld.HelloReply) Test(org.junit.Test)

Example 47 with HelloReply

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

the class SafeMethodCachingInterceptorTest method requestWithOnlyIfCachedOption_usesCache.

@Test
public void requestWithOnlyIfCachedOption_usesCache() {
    HelloReply reply1 = ClientCalls.blockingUnaryCall(channelToUse, safeGreeterSayHelloMethod, CallOptions.DEFAULT, message);
    HelloReply reply2 = ClientCalls.blockingUnaryCall(channelToUse, safeGreeterSayHelloMethod, CallOptions.DEFAULT.withOption(SafeMethodCachingInterceptor.ONLY_IF_CACHED_CALL_OPTION, true), message);
    assertSame(reply1, reply2);
}
Also used : HelloReply(io.grpc.examples.helloworld.HelloReply) Test(org.junit.Test)

Example 48 with HelloReply

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

the class SafeMethodCachingInterceptorTest method requestWithNoCacheOptionSkipsCache.

@Test
public void requestWithNoCacheOptionSkipsCache() {
    HelloReply reply1 = ClientCalls.blockingUnaryCall(channelToUse, safeGreeterSayHelloMethod, CallOptions.DEFAULT, message);
    HelloReply reply2 = ClientCalls.blockingUnaryCall(channelToUse, safeGreeterSayHelloMethod, CallOptions.DEFAULT.withOption(SafeMethodCachingInterceptor.NO_CACHE_CALL_OPTION, true), message);
    HelloReply reply3 = ClientCalls.blockingUnaryCall(channelToUse, safeGreeterSayHelloMethod, CallOptions.DEFAULT, message);
    assertNotEquals(reply1, reply2);
    assertSame(reply1, reply3);
}
Also used : HelloReply(io.grpc.examples.helloworld.HelloReply) Test(org.junit.Test)

Example 49 with HelloReply

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

the class SafeMethodCachingInterceptorTest method safeCallsAreCachedWithCopiedMethodDescriptor.

@Test
public void safeCallsAreCachedWithCopiedMethodDescriptor() {
    HelloReply reply1 = ClientCalls.blockingUnaryCall(channelToUse, safeGreeterSayHelloMethod, CallOptions.DEFAULT, message);
    HelloReply reply2 = ClientCalls.blockingUnaryCall(channelToUse, safeGreeterSayHelloMethod.toBuilder().build(), CallOptions.DEFAULT, message);
    assertSame(reply1, reply2);
}
Also used : HelloReply(io.grpc.examples.helloworld.HelloReply) Test(org.junit.Test)

Example 50 with HelloReply

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

the class SafeMethodCachingInterceptorTest method cacheHit_doesNotResetExpiration.

@Test
public void cacheHit_doesNotResetExpiration() throws Exception {
    cacheControlDirectives.add("max-age=1");
    HelloReply reply1 = ClientCalls.blockingUnaryCall(channelToUse, safeGreeterSayHelloMethod, CallOptions.DEFAULT, message);
    HelloReply reply2 = ClientCalls.blockingUnaryCall(channelToUse, safeGreeterSayHelloMethod, CallOptions.DEFAULT, message);
    sleepAtLeast(1001);
    HelloReply reply3 = ClientCalls.blockingUnaryCall(channelToUse, safeGreeterSayHelloMethod, CallOptions.DEFAULT, message);
    assertSame(reply1, reply2);
    assertNotEquals(reply1, reply3);
    Truth.assertThat(cache.internalCache).hasSize(1);
    Truth.assertThat(cache.removedKeys).hasSize(1);
}
Also used : HelloReply(io.grpc.examples.helloworld.HelloReply) Test(org.junit.Test)

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