Search in sources :

Example 21 with ServerInterceptor

use of io.grpc.ServerInterceptor in project brave by openzipkin.

the class BaseITTracingServerInterceptor method userInterceptor_throwsOnOnHalfClose.

@Test
public void userInterceptor_throwsOnOnHalfClose() throws IOException {
    init(new ServerInterceptor() {

        @Override
        public <ReqT, RespT> ServerCall.Listener<ReqT> interceptCall(ServerCall<ReqT, RespT> call, Metadata metadata, ServerCallHandler<ReqT, RespT> next) {
            return new SimpleForwardingServerCallListener<ReqT>(next.startCall(call, metadata)) {

                @Override
                public void onHalfClose() {
                    throw new IllegalStateException("I'm a bad interceptor.");
                }
            };
        }
    });
    assertThatThrownBy(() -> GreeterGrpc.newBlockingStub(client).sayHello(HELLO_REQUEST)).isInstanceOf(StatusRuntimeException.class);
    testSpanHandler.takeRemoteSpanWithErrorMessage(Span.Kind.SERVER, "I'm a bad interceptor.");
}
Also used : SimpleForwardingServerCallListener(io.grpc.ForwardingServerCallListener.SimpleForwardingServerCallListener) ServerInterceptor(io.grpc.ServerInterceptor) Metadata(io.grpc.Metadata) Test(org.junit.Test)

Example 22 with ServerInterceptor

use of io.grpc.ServerInterceptor in project brave by openzipkin.

the class BaseITTracingServerInterceptor method userInterceptor_throwsOnClose.

@Test
public void userInterceptor_throwsOnClose() throws IOException {
    init(new ServerInterceptor() {

        @Override
        public <ReqT, RespT> ServerCall.Listener<ReqT> interceptCall(ServerCall<ReqT, RespT> call, Metadata metadata, ServerCallHandler<ReqT, RespT> next) {
            return next.startCall(new SimpleForwardingServerCall<ReqT, RespT>(call) {

                @Override
                public void close(Status status, Metadata trailers) {
                    throw new IllegalStateException("I'm a bad interceptor.");
                }
            }, metadata);
        }
    });
    assertThatThrownBy(() -> GreeterGrpc.newBlockingStub(client).sayHello(HELLO_REQUEST)).isInstanceOf(StatusRuntimeException.class);
    testSpanHandler.takeRemoteSpanWithErrorMessage(Span.Kind.SERVER, "I'm a bad interceptor.");
}
Also used : Status(io.grpc.Status) SimpleForwardingServerCallListener(io.grpc.ForwardingServerCallListener.SimpleForwardingServerCallListener) ServerInterceptor(io.grpc.ServerInterceptor) Metadata(io.grpc.Metadata) SimpleForwardingServerCall(io.grpc.ForwardingServerCall.SimpleForwardingServerCall) Test(org.junit.Test)

Example 23 with ServerInterceptor

use of io.grpc.ServerInterceptor in project brave by openzipkin.

the class BaseITTracingServerInterceptor method userInterceptor_throwsOnStartCall.

// Make sure we work well with bad user interceptors.
@Test
public void userInterceptor_throwsOnStartCall() throws IOException {
    init(new ServerInterceptor() {

        @Override
        public <ReqT, RespT> ServerCall.Listener<ReqT> interceptCall(ServerCall<ReqT, RespT> call, Metadata metadata, ServerCallHandler<ReqT, RespT> next) {
            throw new IllegalStateException("I'm a bad interceptor.");
        }
    });
    assertThatThrownBy(() -> GreeterGrpc.newBlockingStub(client).sayHello(HELLO_REQUEST)).isInstanceOf(StatusRuntimeException.class);
    testSpanHandler.takeRemoteSpanWithErrorMessage(Span.Kind.SERVER, "I'm a bad interceptor.");
}
Also used : SimpleForwardingServerCallListener(io.grpc.ForwardingServerCallListener.SimpleForwardingServerCallListener) ServerInterceptor(io.grpc.ServerInterceptor) Metadata(io.grpc.Metadata) Test(org.junit.Test)

Example 24 with ServerInterceptor

use of io.grpc.ServerInterceptor in project brave by openzipkin.

the class BaseITTracingServerInterceptor method init.

void init(@Nullable ServerInterceptor userInterceptor) throws IOException {
    stop();
    // tracing interceptor needs to go last
    ServerInterceptor tracingInterceptor = grpcTracing.newServerInterceptor();
    ServerInterceptor[] interceptors = userInterceptor != null ? new ServerInterceptor[] { userInterceptor, tracingInterceptor } : new ServerInterceptor[] { tracingInterceptor };
    server = ServerBuilder.forPort(PickUnusedPort.get()).addService(ServerInterceptors.intercept(new GreeterImpl(grpcTracing), interceptors)).build().start();
    client = usePlainText(ManagedChannelBuilder.forAddress("localhost", server.getPort())).build();
}
Also used : ServerInterceptor(io.grpc.ServerInterceptor)

Example 25 with ServerInterceptor

use of io.grpc.ServerInterceptor in project sonarlint-core by SonarSource.

the class Daemon method start.

public void start(int port, Path sonarlintHome) {
    try {
        LOGGER.info("Starting server on port {}", port);
        ServerInterceptor interceptor = new ExceptionInterceptor();
        server = NettyServerBuilder.forAddress(new InetSocketAddress("localhost", port)).addService(ServerInterceptors.intercept(new ConnectedSonarLintImpl(this), interceptor)).addService(ServerInterceptors.intercept(new StandaloneSonarLintImpl(this, Utils.getAnalyzers(sonarlintHome)), interceptor)).build().start();
        LOGGER.info("Server started, listening on {}", port);
        Runtime.getRuntime().addShutdownHook(new Thread() {

            @Override
            public void run() {
                LOGGER.info("JVM is shutting down");
                if (!server.isShutdown()) {
                    Daemon.this.stop();
                }
            }
        });
        server.awaitTermination();
    } catch (Exception e) {
        // grpc threads are daemon, so should not hang process
        LOGGER.error("Error running daemon", e);
    }
}
Also used : InetSocketAddress(java.net.InetSocketAddress) ServerInterceptor(io.grpc.ServerInterceptor) ExceptionInterceptor(org.sonarlint.daemon.interceptors.ExceptionInterceptor) StandaloneSonarLintImpl(org.sonarlint.daemon.services.StandaloneSonarLintImpl) ConnectedSonarLintImpl(org.sonarlint.daemon.services.ConnectedSonarLintImpl)

Aggregations

ServerInterceptor (io.grpc.ServerInterceptor)37 Metadata (io.grpc.Metadata)23 Test (org.junit.Test)15 ServerCall (io.grpc.ServerCall)10 ServerCallHandler (io.grpc.ServerCallHandler)9 SimpleForwardingServerCallListener (io.grpc.ForwardingServerCallListener.SimpleForwardingServerCallListener)7 Server (io.grpc.Server)6 IOException (java.io.IOException)6 SimpleForwardingServerCall (io.grpc.ForwardingServerCall.SimpleForwardingServerCall)4 Status (io.grpc.Status)4 ManagedChannel (io.grpc.ManagedChannel)3 Listener (io.grpc.ServerCall.Listener)3 ServerTransportFilter (io.grpc.ServerTransportFilter)3 InetSocketAddress (java.net.InetSocketAddress)3 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)3 TraceContext (brave.propagation.TraceContext)2 GrpcStreamConfiguration (com.navercorp.pinpoint.collector.grpc.config.GrpcStreamConfiguration)2 DefaultServerRequestFactory (com.navercorp.pinpoint.collector.receiver.grpc.service.DefaultServerRequestFactory)2 StreamExecutorServerInterceptorFactory (com.navercorp.pinpoint.collector.receiver.grpc.service.StreamExecutorServerInterceptorFactory)2 MetadataServerTransportFilter (com.navercorp.pinpoint.grpc.server.MetadataServerTransportFilter)2