Search in sources :

Example 1 with BinaryLog

use of io.grpc.BinaryLog in project grpc-java by grpc.

the class ManagedChannelImplTest method binaryLogInstalled.

@Test
public void binaryLogInstalled() throws Exception {
    final SettableFuture<Boolean> intercepted = SettableFuture.create();
    channelBuilder.binlog = new BinaryLog() {

        @Override
        public void close() throws IOException {
        // noop
        }

        @Override
        public <ReqT, RespT> ServerMethodDefinition<?, ?> wrapMethodDefinition(ServerMethodDefinition<ReqT, RespT> oMethodDef) {
            return oMethodDef;
        }

        @Override
        public Channel wrapChannel(Channel channel) {
            return ClientInterceptors.intercept(channel, new ClientInterceptor() {

                @Override
                public <ReqT, RespT> ClientCall<ReqT, RespT> interceptCall(MethodDescriptor<ReqT, RespT> method, CallOptions callOptions, Channel next) {
                    intercepted.set(true);
                    return next.newCall(method, callOptions);
                }
            });
        }
    };
    createChannel();
    ClientCall<String, Integer> call = channel.newCall(method, CallOptions.DEFAULT);
    call.start(mockCallListener, new Metadata());
    assertTrue(intercepted.get());
}
Also used : ManagedChannel(io.grpc.ManagedChannel) Channel(io.grpc.Channel) Metadata(io.grpc.Metadata) IOException(java.io.IOException) CallOptions(io.grpc.CallOptions) MethodDescriptor(io.grpc.MethodDescriptor) BinaryLog(io.grpc.BinaryLog) ServerMethodDefinition(io.grpc.ServerMethodDefinition) ClientInterceptor(io.grpc.ClientInterceptor) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Test(org.junit.Test)

Example 2 with BinaryLog

use of io.grpc.BinaryLog in project grpc-java by grpc.

the class ServerImplTest method binaryLogInstalled.

@Test
public void binaryLogInstalled() throws Exception {
    final SettableFuture<Boolean> intercepted = SettableFuture.create();
    final ServerInterceptor interceptor = new ServerInterceptor() {

        @Override
        public <ReqT, RespT> Listener<ReqT> interceptCall(ServerCall<ReqT, RespT> call, Metadata headers, ServerCallHandler<ReqT, RespT> next) {
            intercepted.set(true);
            return next.startCall(call, headers);
        }
    };
    builder.binlog = new BinaryLog() {

        @Override
        public void close() throws IOException {
        // noop
        }

        @Override
        public <ReqT, RespT> ServerMethodDefinition<?, ?> wrapMethodDefinition(ServerMethodDefinition<ReqT, RespT> oMethodDef) {
            return ServerMethodDefinition.create(oMethodDef.getMethodDescriptor(), InternalServerInterceptors.interceptCallHandlerCreate(interceptor, oMethodDef.getServerCallHandler()));
        }

        @Override
        public Channel wrapChannel(Channel channel) {
            return channel;
        }
    };
    createAndStartServer();
    basicExchangeHelper(METHOD, "Lots of pizza, please", 314, 50);
    assertTrue(intercepted.get());
}
Also used : ServerCallHandler(io.grpc.ServerCallHandler) Channel(io.grpc.Channel) Metadata(io.grpc.Metadata) IOException(java.io.IOException) BinaryLog(io.grpc.BinaryLog) ServerMethodDefinition(io.grpc.ServerMethodDefinition) ServerCall(io.grpc.ServerCall) ServerInterceptor(io.grpc.ServerInterceptor) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Test(org.junit.Test)

Aggregations

BinaryLog (io.grpc.BinaryLog)2 Channel (io.grpc.Channel)2 Metadata (io.grpc.Metadata)2 ServerMethodDefinition (io.grpc.ServerMethodDefinition)2 IOException (java.io.IOException)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2 Test (org.junit.Test)2 CallOptions (io.grpc.CallOptions)1 ClientInterceptor (io.grpc.ClientInterceptor)1 ManagedChannel (io.grpc.ManagedChannel)1 MethodDescriptor (io.grpc.MethodDescriptor)1 ServerCall (io.grpc.ServerCall)1 ServerCallHandler (io.grpc.ServerCallHandler)1 ServerInterceptor (io.grpc.ServerInterceptor)1