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