/** * Before the test has started, create the server and channel. */ @Override protected void before() throws Throwable { serviceRegistry = new MutableHandlerRegistry(); NettyServerBuilder serverBuilder = NettyServerBuilder .forPort(0) .fallbackHandlerRegistry(serviceRegistry); if (useDirectExecutor) { serverBuilder.directExecutor(); } configureServerBuilder.accept(serverBuilder); server = serverBuilder.build().start(); port = server.getPort(); NettyChannelBuilder channelBuilder = NettyChannelBuilder.forAddress("localhost", port).usePlaintext(true); configureChannelBuilder.accept(channelBuilder); channel = channelBuilder.build(); }
/** * 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(); }
/** * 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(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()); } }
/** * Returns the service registry for this service. The registry is used to add service instances * (e.g. {@link io.grpc.BindableService} or {@link io.grpc.ServerServiceDefinition} to the server. */ public final MutableHandlerRegistry getServiceRegistry() { return serviceRegistry; }
/** * Returns the service registry for this service. The registry is used to add service instances * (e.g. {@link BindableService} or {@link ServerServiceDefinition} to the server. */ public final MutableHandlerRegistry getServiceRegistry() { return serviceRegistry; }