Search in sources :

Example 1 with MutableHandlerRegistry

use of io.grpc.util.MutableHandlerRegistry in project bookkeeper by apache.

the class TestGrpcServer method testCreateLocalServer.

@Test
public void testCreateLocalServer() {
    GrpcServer server = new GrpcServer(mock(RangeStoreImpl.class), StorageServerConfiguration.of(compConf), null, name.getMethodName(), new MutableHandlerRegistry(), NullStatsLogger.INSTANCE);
    server.start();
    assertEquals(-1, server.getGrpcServer().getPort());
    server.close();
}
Also used : MutableHandlerRegistry(io.grpc.util.MutableHandlerRegistry) RangeStoreImpl(org.apache.bookkeeper.stream.storage.impl.RangeStoreImpl) Test(org.junit.Test)

Example 2 with MutableHandlerRegistry

use of io.grpc.util.MutableHandlerRegistry in project jetcd by coreos.

the class GrpcServerExtension method beforeEach.

/**
 * Before the test has started, create the server and channel.
 */
@Override
public void beforeEach(ExtensionContext context) throws Exception {
    serverName = UUID.randomUUID().toString();
    serviceRegistry = new MutableHandlerRegistry();
    InProcessServerBuilder serverBuilder = InProcessServerBuilder.forName(serverName).fallbackHandlerRegistry(serviceRegistry);
    if (useDirectExecutor) {
        serverBuilder.directExecutor();
    }
    server = serverBuilder.build().start();
    InProcessChannelBuilder channelBuilder = InProcessChannelBuilder.forName(serverName);
    if (useDirectExecutor) {
        channelBuilder.directExecutor();
    }
    channel = channelBuilder.build();
}
Also used : InProcessChannelBuilder(io.grpc.inprocess.InProcessChannelBuilder) MutableHandlerRegistry(io.grpc.util.MutableHandlerRegistry) InProcessServerBuilder(io.grpc.inprocess.InProcessServerBuilder)

Example 3 with MutableHandlerRegistry

use of io.grpc.util.MutableHandlerRegistry in project jetcd by coreos.

the class AuthUnitTest method testHeaders.

@Test
public void testHeaders() throws Exception {
    MutableHandlerRegistry serviceRegistry = new MutableHandlerRegistry();
    serviceRegistry.addService(new AuthGrpc.AuthImplBase() {

        @Override
        public void authenticate(io.etcd.jetcd.api.AuthenticateRequest request, io.grpc.stub.StreamObserver<io.etcd.jetcd.api.AuthenticateResponse> responseObserver) {
            responseObserver.onNext(AuthenticateResponse.newBuilder().setToken("token").build());
        }
    });
    serviceRegistry.addService(new KVGrpc.KVImplBase() {

        @Override
        public void put(io.etcd.jetcd.api.PutRequest request, io.grpc.stub.StreamObserver<io.etcd.jetcd.api.PutResponse> responseObserver) {
            responseObserver.onNext(PutResponse.newBuilder().build());
        }
    });
    Server server = null;
    Client client = null;
    try {
        Metadata intercepted = new Metadata();
        server = NettyServerBuilder.forPort(0).fallbackHandlerRegistry(serviceRegistry).intercept(new ServerInterceptor() {

            @Override
            public <ReqT, RespT> ServerCall.Listener<ReqT> interceptCall(ServerCall<ReqT, RespT> call, Metadata headers, ServerCallHandler<ReqT, RespT> next) {
                if (AUTHENTICATE_METHOD_NAME.equals(call.getMethodDescriptor().getFullMethodName())) {
                    intercepted.merge(headers);
                }
                return next.startCall(new ForwardingServerCall.SimpleForwardingServerCall<>(call) {
                }, headers);
            }
        }).directExecutor().build().start();
        client = Client.builder().endpoints(new URI("http://127.0.0.1:" + server.getPort())).user(user).password(userPass).authHeader("foo-a", "foo-auth").header("bar-h", "bar").build();
        client.getKVClient().put(key, value).get(30, TimeUnit.SECONDS);
        assertThat(intercepted.keys()).contains("foo-a");
    } finally {
        if (client != null) {
            client.close();
        }
        if (server != null) {
            server.shutdownNow();
        }
    }
}
Also used : AuthenticateResponse(io.etcd.jetcd.api.AuthenticateResponse) Server(io.grpc.Server) Metadata(io.grpc.Metadata) PutResponse(io.etcd.jetcd.api.PutResponse) URI(java.net.URI) Client(io.etcd.jetcd.Client) MutableHandlerRegistry(io.grpc.util.MutableHandlerRegistry) KVGrpc(io.etcd.jetcd.api.KVGrpc) AuthGrpc(io.etcd.jetcd.api.AuthGrpc) ServerInterceptor(io.grpc.ServerInterceptor) Test(org.junit.jupiter.api.Test)

Example 4 with MutableHandlerRegistry

use of io.grpc.util.MutableHandlerRegistry in project grpc-java by grpc.

the class HandlerRegistryBenchmark method setup.

/**
   * Set up the registry.
   */
@Setup(Level.Trial)
public void setup() throws Exception {
    registry = new MutableHandlerRegistry();
    fullMethodNames = new ArrayList<String>(serviceCount * methodCountPerService);
    for (int serviceIndex = 0; serviceIndex < serviceCount; ++serviceIndex) {
        String serviceName = randomString();
        ServerServiceDefinition.Builder serviceBuilder = ServerServiceDefinition.builder(new ServiceDescriptor(serviceName));
        for (int methodIndex = 0; methodIndex < methodCountPerService; ++methodIndex) {
            String methodName = randomString();
            MethodDescriptor<Void, Void> methodDescriptor = MethodDescriptor.<Void, Void>newBuilder().setType(MethodDescriptor.MethodType.UNKNOWN).setFullMethodName(MethodDescriptor.generateFullMethodName(serviceName, methodName)).setRequestMarshaller(TestMethodDescriptors.voidMarshaller()).setResponseMarshaller(TestMethodDescriptors.voidMarshaller()).build();
            serviceBuilder.addMethod(methodDescriptor, new ServerCallHandler<Void, Void>() {

                @Override
                public Listener<Void> startCall(ServerCall<Void, Void> call, Metadata headers) {
                    return null;
                }
            });
            fullMethodNames.add(methodDescriptor.getFullMethodName());
        }
        registry.addService(serviceBuilder.build());
    }
}
Also used : Listener(io.grpc.ServerCall.Listener) MutableHandlerRegistry(io.grpc.util.MutableHandlerRegistry) Metadata(io.grpc.Metadata) ServiceDescriptor(io.grpc.ServiceDescriptor) ServerServiceDefinition(io.grpc.ServerServiceDefinition) Setup(org.openjdk.jmh.annotations.Setup)

Example 5 with MutableHandlerRegistry

use of io.grpc.util.MutableHandlerRegistry in project grpc-java by grpc.

the class GrpcServerRule method before.

/**
 * Before the test has started, create the server and channel.
 */
@Override
protected void before() throws Throwable {
    serverName = UUID.randomUUID().toString();
    serviceRegistry = new MutableHandlerRegistry();
    InProcessServerBuilder serverBuilder = InProcessServerBuilder.forName(serverName).fallbackHandlerRegistry(serviceRegistry);
    if (useDirectExecutor) {
        serverBuilder.directExecutor();
    }
    server = serverBuilder.build().start();
    InProcessChannelBuilder channelBuilder = InProcessChannelBuilder.forName(serverName);
    if (useDirectExecutor) {
        channelBuilder.directExecutor();
    }
    channel = channelBuilder.build();
}
Also used : InProcessChannelBuilder(io.grpc.inprocess.InProcessChannelBuilder) MutableHandlerRegistry(io.grpc.util.MutableHandlerRegistry) InProcessServerBuilder(io.grpc.inprocess.InProcessServerBuilder)

Aggregations

MutableHandlerRegistry (io.grpc.util.MutableHandlerRegistry)6 Metadata (io.grpc.Metadata)2 InProcessChannelBuilder (io.grpc.inprocess.InProcessChannelBuilder)2 InProcessServerBuilder (io.grpc.inprocess.InProcessServerBuilder)2 URI (java.net.URI)2 Client (io.etcd.jetcd.Client)1 AuthGrpc (io.etcd.jetcd.api.AuthGrpc)1 AuthenticateResponse (io.etcd.jetcd.api.AuthenticateResponse)1 KVGrpc (io.etcd.jetcd.api.KVGrpc)1 MaintenanceImplBase (io.etcd.jetcd.api.MaintenanceGrpc.MaintenanceImplBase)1 PutResponse (io.etcd.jetcd.api.PutResponse)1 SnapshotRequest (io.etcd.jetcd.api.SnapshotRequest)1 SnapshotResponse (io.etcd.jetcd.api.SnapshotResponse)1 Server (io.grpc.Server)1 Listener (io.grpc.ServerCall.Listener)1 ServerInterceptor (io.grpc.ServerInterceptor)1 ServerServiceDefinition (io.grpc.ServerServiceDefinition)1 ServiceDescriptor (io.grpc.ServiceDescriptor)1 RangeStoreImpl (org.apache.bookkeeper.stream.storage.impl.RangeStoreImpl)1 Test (org.junit.Test)1