Search in sources :

Example 26 with HelloReply

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

the class SafeMethodCachingInterceptorTest method responseNoStoreDirective_notCached.

@Test
public void responseNoStoreDirective_notCached() throws Exception {
    cacheControlDirectives.add("no-store");
    HelloReply reply1 = ClientCalls.blockingUnaryCall(channelToUse, safeGreeterSayHelloMethod, CallOptions.DEFAULT, message);
    HelloReply reply2 = ClientCalls.blockingUnaryCall(channelToUse, safeGreeterSayHelloMethod, CallOptions.DEFAULT, message);
    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 27 with HelloReply

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

the class SafeMethodCachingInterceptorTest method responseMaxAge_caseInsensitive.

@Test
public void responseMaxAge_caseInsensitive() throws Exception {
    cacheControlDirectives.add("MaX-aGe=0");
    HelloReply reply1 = ClientCalls.blockingUnaryCall(channelToUse, safeGreeterSayHelloMethod, CallOptions.DEFAULT, message);
    HelloReply reply2 = ClientCalls.blockingUnaryCall(channelToUse, safeGreeterSayHelloMethod, CallOptions.DEFAULT, message);
    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 28 with HelloReply

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

the class HostnameGreeterTest method sayHello_fixedHostname.

@Test
public void sayHello_fixedHostname() throws Exception {
    grpcCleanup.register(InProcessServerBuilder.forName("hostname").directExecutor().addService(new HostnameGreeter("me")).build().start());
    HelloReply reply = blockingStub.sayHello(HelloRequest.newBuilder().setName("you").build());
    assertEquals("Hello you, from me", reply.getMessage());
}
Also used : HostnameGreeter(io.grpc.examples.hostname.HostnameGreeter) HelloReply(io.grpc.examples.helloworld.HelloReply) Test(org.junit.Test)

Example 29 with HelloReply

use of io.grpc.examples.helloworld.HelloReply in project brave by openzipkin.

the class BaseITTracingClientInterceptor method callbackContextIsFromInvocationTime.

/**
 * This ensures that response callbacks run in the invocation context, not the client one. This
 * allows async chaining to appear caused by the parent, not by the most recent client. Otherwise,
 * we would see a client span child of a client span, which could be confused with duplicate
 * instrumentation and affect dependency link counts.
 */
@Test
public void callbackContextIsFromInvocationTime() {
    AssertableCallback<HelloReply> callback = new AssertableCallback<>();
    // Capture the current trace context when onSuccess or onError occur
    AtomicReference<TraceContext> invocationContext = new AtomicReference<>();
    callback.setListener(() -> invocationContext.set(currentTraceContext.get()));
    TraceContext parent = newTraceContext(SamplingFlags.SAMPLED);
    try (Scope scope = currentTraceContext.newScope(parent)) {
        GreeterGrpc.newStub(client).sayHello(HELLO_REQUEST, new StreamObserverAdapter(callback));
    }
    // ensures listener ran
    callback.join();
    assertThat(invocationContext.get()).isSameAs(parent);
    assertChildOf(testSpanHandler.takeRemoteSpan(CLIENT), parent);
}
Also used : AssertableCallback(brave.test.util.AssertableCallback) Scope(brave.propagation.CurrentTraceContext.Scope) TraceContext(brave.propagation.TraceContext) AtomicReference(java.util.concurrent.atomic.AtomicReference) HelloReply(io.grpc.examples.helloworld.HelloReply) Test(org.junit.Test)

Example 30 with HelloReply

use of io.grpc.examples.helloworld.HelloReply in project brave by openzipkin.

the class BaseITTracingClientInterceptor method messageTagging_streaming.

@Test
public void messageTagging_streaming() {
    initMessageTaggingClient();
    ScopedSpan span = tracing.tracer().startScopedSpan("parent");
    try {
        Iterator<HelloReply> replies = GreeterGrpc.newBlockingStub(client).sayHelloWithManyReplies(HELLO_REQUEST);
        assertThat(replies).toIterable().hasSize(10);
    } finally {
        span.finish();
    }
    assertThat(testSpanHandler.takeRemoteSpan(CLIENT).tags()).containsKey("grpc.message_send.1");
    // Response processing happens on the invocation (parent) trace context
    // Intentionally verbose here to show 10 replies
    assertThat(testSpanHandler.takeLocalSpan().tags()).containsKeys("grpc.message_recv.1", "grpc.message_recv.2", "grpc.message_recv.3", "grpc.message_recv.4", "grpc.message_recv.5", "grpc.message_recv.6", "grpc.message_recv.7", "grpc.message_recv.8", "grpc.message_recv.9", "grpc.message_recv.10");
}
Also used : HelloReply(io.grpc.examples.helloworld.HelloReply) ScopedSpan(brave.ScopedSpan) 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