Search in sources :

Example 1 with HelloReply

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

the class ITTracingClientInterceptor method addsErrorTag_onCanceledFuture.

@Test
public void addsErrorTag_onCanceledFuture() throws Exception {
    server.enqueueDelay(TimeUnit.SECONDS.toMillis(1));
    ListenableFuture<HelloReply> resp = GreeterGrpc.newFutureStub(client).sayHello(HELLO_REQUEST);
    assumeTrue("lost race on cancel", resp.cancel(true));
    Span span = spans.take();
    assertThat(span.tags()).containsExactly(entry("error", "CANCELLED"), entry("grpc.status_code", "CANCELLED"));
}
Also used : HelloReply(io.grpc.examples.helloworld.HelloReply) Span(zipkin2.Span) Test(org.junit.Test)

Example 2 with HelloReply

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

the class ITTracingServerInterceptor method serverParserTestWithStreamingResponse.

@Test
public void serverParserTestWithStreamingResponse() throws Exception {
    grpcTracing = grpcTracing.toBuilder().serverParser(new GrpcServerParser() {

        int responsesSent = 0;

        @Override
        protected <M> void onMessageSent(M message, SpanCustomizer span) {
            span.tag("grpc.message_sent." + responsesSent++, message.toString());
        }
    }).build();
    init();
    Iterator<HelloReply> replies = GreeterGrpc.newBlockingStub(client).sayHelloWithManyReplies(HELLO_REQUEST);
    assertThat(replies).hasSize(10);
    // all response messages are tagged to the same span
    Span span = spans.take();
    assertThat(span.tags()).hasSize(10);
}
Also used : HelloReply(io.grpc.examples.helloworld.HelloReply) SpanCustomizer(brave.SpanCustomizer) Span(zipkin2.Span) Test(org.junit.Test)

Example 3 with HelloReply

use of io.grpc.examples.helloworld.HelloReply in project pinpoint by naver.

the class HelloWorldSimpleClient method greet.

public String greet(String name) {
    HelloRequest request = HelloRequest.newBuilder().setName(name).build();
    HelloReply response = blockingStub.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 4 with HelloReply

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

the class SafeMethodCachingInterceptorTest method invalidResponseMaxAge_usesDefault.

@Test
public void invalidResponseMaxAge_usesDefault() throws Exception {
    SafeMethodCachingInterceptor interceptorWithCustomMaxAge = SafeMethodCachingInterceptor.newSafeMethodCachingInterceptor(cache, 1);
    channelToUse = ClientInterceptors.intercept(baseChannel, interceptorWithCustomMaxAge);
    cacheControlDirectives.add("max-age=-10");
    HelloReply reply1 = ClientCalls.blockingUnaryCall(channelToUse, safeGreeterSayHelloMethod, CallOptions.DEFAULT, message);
    HelloReply reply2 = ClientCalls.blockingUnaryCall(channelToUse, safeGreeterSayHelloMethod, CallOptions.DEFAULT, message);
    assertEquals(reply1, reply2);
    // Wait for cache entry to expire
    sleepAtLeast(1001);
    assertNotEquals(reply1, ClientCalls.blockingUnaryCall(channelToUse, safeGreeterSayHelloMethod, CallOptions.DEFAULT, message));
    Truth.assertThat(cache.removedKeys).hasSize(1);
    assertEquals(new SafeMethodCachingInterceptor.Key(GreeterGrpc.getSayHelloMethod().getFullMethodName(), message), cache.removedKeys.get(0));
}
Also used : HelloReply(io.grpc.examples.helloworld.HelloReply) Test(org.junit.Test)

Example 5 with HelloReply

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

the class SafeMethodCachingInterceptorTest method afterDefaultMaxAge_cacheEntryInvalidated.

@Test
public void afterDefaultMaxAge_cacheEntryInvalidated() throws Exception {
    SafeMethodCachingInterceptor interceptorWithCustomMaxAge = SafeMethodCachingInterceptor.newSafeMethodCachingInterceptor(cache, 1);
    channelToUse = ClientInterceptors.intercept(baseChannel, interceptorWithCustomMaxAge);
    HelloReply reply1 = ClientCalls.blockingUnaryCall(channelToUse, safeGreeterSayHelloMethod, CallOptions.DEFAULT, message);
    HelloReply reply2 = ClientCalls.blockingUnaryCall(channelToUse, safeGreeterSayHelloMethod, CallOptions.DEFAULT, message);
    assertSame(reply1, reply2);
    // Wait for cache entry to expire
    sleepAtLeast(1001);
    assertNotEquals(reply1, ClientCalls.blockingUnaryCall(channelToUse, safeGreeterSayHelloMethod, CallOptions.DEFAULT, message));
    Truth.assertThat(cache.removedKeys).hasSize(1);
    assertEquals(new SafeMethodCachingInterceptor.Key(GreeterGrpc.getSayHelloMethod().getFullMethodName(), message), cache.removedKeys.get(0));
}
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