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