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