Search in sources :

Example 6 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 7 with MutableHandlerRegistry

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

the class PingPongServiceTestBase method setup.

@Before
public void setup() throws Exception {
    service = new PingPongService(NUM_PONGS_PER_PING);
    ServerServiceDefinition pingPongServiceDef = service.bindService();
    String serverName;
    if (useReverseProxy) {
        serverName = "proxy-" + SERVICE_NAME;
    } else {
        serverName = SERVICE_NAME;
    }
    // build a real server
    MutableHandlerRegistry realRegistry = new MutableHandlerRegistry();
    realServer = InProcessServerBuilder.forName(serverName).fallbackHandlerRegistry(realRegistry).directExecutor().build().start();
    realRegistry.addService(pingPongServiceDef);
    if (useReverseProxy) {
        proxyChannel = InProcessChannelBuilder.forName(serverName).usePlaintext().build();
        ProxyHandlerRegistry registry = ProxyHandlerRegistry.newBuilder().addService(pingPongServiceDef).setChannelFinder((serverCall, header) -> proxyChannel).build();
        proxyServer = InProcessServerBuilder.forName(SERVICE_NAME).fallbackHandlerRegistry(registry).directExecutor().build().start();
    } else {
        proxyServer = realServer;
    }
    clientChannel = InProcessChannelBuilder.forName(SERVICE_NAME).usePlaintext().build();
    client = PingPongServiceGrpc.newStub(clientChannel);
}
Also used : IntStream(java.util.stream.IntStream) ManagedChannel(io.grpc.ManagedChannel) CompletableFuture(java.util.concurrent.CompletableFuture) AtomicReference(java.util.concurrent.atomic.AtomicReference) InProcessServerBuilder(io.grpc.inprocess.InProcessServerBuilder) StreamObserver(io.grpc.stub.StreamObserver) PingPongService(org.apache.bookkeeper.tests.rpc.PingPongService) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) After(org.junit.After) ExceptionalFunction(org.apache.bookkeeper.common.util.ExceptionalFunction) PingPongServiceGrpc(org.bookkeeper.tests.proto.rpc.PingPongServiceGrpc) Server(io.grpc.Server) InProcessChannelBuilder(io.grpc.inprocess.InProcessChannelBuilder) ExecutorService(java.util.concurrent.ExecutorService) Before(org.junit.Before) Iterator(java.util.Iterator) PingPongServiceStub(org.bookkeeper.tests.proto.rpc.PingPongServiceGrpc.PingPongServiceStub) PingPongServiceBlockingStub(org.bookkeeper.tests.proto.rpc.PingPongServiceGrpc.PingPongServiceBlockingStub) Test(org.junit.Test) FutureUtils(org.apache.bookkeeper.common.concurrent.FutureUtils) PingRequest(org.bookkeeper.tests.proto.rpc.PingRequest) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue) Executors(java.util.concurrent.Executors) MutableHandlerRegistry(io.grpc.util.MutableHandlerRegistry) CountDownLatch(java.util.concurrent.CountDownLatch) Assert.assertNull(org.junit.Assert.assertNull) FutureUtils.result(org.apache.bookkeeper.common.concurrent.FutureUtils.result) Data(lombok.Data) PongResponse(org.bookkeeper.tests.proto.rpc.PongResponse) Assert.assertEquals(org.junit.Assert.assertEquals) ServerServiceDefinition(io.grpc.ServerServiceDefinition) PingPongService(org.apache.bookkeeper.tests.rpc.PingPongService) ServerServiceDefinition(io.grpc.ServerServiceDefinition) MutableHandlerRegistry(io.grpc.util.MutableHandlerRegistry) Before(org.junit.Before)

Example 8 with MutableHandlerRegistry

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

the class GrpcStatsIntegrationTest method setup.

@Before
public void setup() throws Exception {
    statsProvider = new TestStatsProvider();
    clientStatsLogger = statsProvider.getStatsLogger("client");
    serverStatsLogger = statsProvider.getStatsLogger("server");
    service = new PingPongService(NUM_PONGS_PER_PING);
    ServerServiceDefinition monitoredService = ServerInterceptors.intercept(service, MonitoringServerInterceptor.create(serverStatsLogger, true));
    MutableHandlerRegistry registry = new MutableHandlerRegistry();
    server = InProcessServerBuilder.forName(SERVICE_NAME).fallbackHandlerRegistry(registry).directExecutor().build().start();
    registry.addService(monitoredService);
    channel = InProcessChannelBuilder.forName(SERVICE_NAME).usePlaintext().build();
    monitoredChannel = ClientInterceptors.intercept(channel, MonitoringClientInterceptor.create(clientStatsLogger, true));
    client = PingPongServiceGrpc.newBlockingStub(monitoredChannel);
    clientNonBlocking = PingPongServiceGrpc.newStub(monitoredChannel);
}
Also used : TestStatsProvider(org.apache.bookkeeper.test.TestStatsProvider) PingPongService(org.apache.bookkeeper.tests.rpc.PingPongService) ServerServiceDefinition(io.grpc.ServerServiceDefinition) MutableHandlerRegistry(io.grpc.util.MutableHandlerRegistry) Before(org.junit.Before)

Example 9 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)

Example 10 with MutableHandlerRegistry

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

the class MaintenanceUnitTest method setUp.

@BeforeEach
public void setUp() throws IOException, URISyntaxException {
    observerQueue = new LinkedBlockingQueue<>();
    executor = Executors.newFixedThreadPool(2);
    serviceRegistry = new MutableHandlerRegistry();
    serviceRegistry.addService(new MaintenanceImplBase() {

        @Override
        public void snapshot(SnapshotRequest request, StreamObserver<SnapshotResponse> observer) {
            try {
                observerQueue.put(observer);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        }
    });
    fakeServer = NettyServerBuilder.forPort(TestUtil.findNextAvailablePort()).fallbackHandlerRegistry(serviceRegistry).directExecutor().build().start();
    client = Client.builder().endpoints(new URI("http://127.0.0.1:" + fakeServer.getPort())).build();
    maintenance = client.getMaintenanceClient();
}
Also used : MaintenanceImplBase(io.etcd.jetcd.api.MaintenanceGrpc.MaintenanceImplBase) SnapshotResponse(io.etcd.jetcd.api.SnapshotResponse) SnapshotRequest(io.etcd.jetcd.api.SnapshotRequest) MutableHandlerRegistry(io.grpc.util.MutableHandlerRegistry) URI(java.net.URI) BeforeEach(org.junit.jupiter.api.BeforeEach)

Aggregations

MutableHandlerRegistry (io.grpc.util.MutableHandlerRegistry)14 Metadata (io.grpc.Metadata)4 Server (io.grpc.Server)4 InProcessChannelBuilder (io.grpc.inprocess.InProcessChannelBuilder)4 InProcessServerBuilder (io.grpc.inprocess.InProcessServerBuilder)4 URI (java.net.URI)4 ServerInterceptor (io.grpc.ServerInterceptor)3 ServerServiceDefinition (io.grpc.ServerServiceDefinition)3 Client (io.etcd.jetcd.Client)2 AuthGrpc (io.etcd.jetcd.api.AuthGrpc)2 AuthenticateResponse (io.etcd.jetcd.api.AuthenticateResponse)2 KVGrpc (io.etcd.jetcd.api.KVGrpc)2 MaintenanceImplBase (io.etcd.jetcd.api.MaintenanceGrpc.MaintenanceImplBase)2 PutResponse (io.etcd.jetcd.api.PutResponse)2 SnapshotRequest (io.etcd.jetcd.api.SnapshotRequest)2 SnapshotResponse (io.etcd.jetcd.api.SnapshotResponse)2 PingPongService (org.apache.bookkeeper.tests.rpc.PingPongService)2 Before (org.junit.Before)2 RpcServer (com.alipay.sofa.jraft.rpc.RpcServer)1 Endpoint (com.alipay.sofa.jraft.util.Endpoint)1