use of io.servicetalk.grpc.api.GrpcServerBuilder in project servicetalk by apple.
the class ExecutionStrategyTest method setUp.
private void setUp(ContextExecutionStrategy contextStrategy, RouteExecutionStrategy routeStrategy, RouteApi routeApi) throws Exception {
this.contextStrategy = contextStrategy;
this.routeStrategy = routeStrategy;
this.routeApi = routeApi;
GrpcServerBuilder builder = GrpcServers.forAddress(localAddress(0));
contextStrategy.configureContextExecutionStrategy(builder);
ServiceFactory serviceFactory = routeStrategy.getServiceFactory();
serverContext = builder.listenAndAwait(serviceFactory);
client = GrpcClients.forAddress(serverHostAndPort(serverContext)).initializeHttp(b -> b.executionStrategy(HttpExecutionStrategies.offloadNever())).buildBlocking(new ClientFactory());
}
use of io.servicetalk.grpc.api.GrpcServerBuilder in project servicetalk by apple.
the class KeepAliveTest method setUp.
private void setUp(final boolean keepAlivesFromClient, final Duration keepAliveIdleFor, final Duration idleTimeout) throws Exception {
this.idleTimeoutMillis = idleTimeout.toMillis();
GrpcServerBuilder serverBuilder = forAddress(localAddress(0)).initializeHttp(builder -> {
builder.executor(SERVER_CTX.executor()).ioExecutor(SERVER_CTX.ioExecutor()).executionStrategy(defaultStrategy());
if (!keepAlivesFromClient) {
builder.protocols(h2Config(keepAliveIdleFor));
} else {
builder.socketOption(IDLE_TIMEOUT, idleTimeoutMillis).protocols(h2Config(null));
}
});
ctx = serverBuilder.listenAndAwait(new ServiceFactory(new InfiniteStreamsService()));
GrpcClientBuilder<HostAndPort, InetSocketAddress> clientBuilder = GrpcClients.forAddress(serverHostAndPort(ctx)).initializeHttp(builder -> builder.executor(CLIENT_CTX.executor()).ioExecutor(CLIENT_CTX.ioExecutor()).executionStrategy(defaultStrategy()));
if (keepAlivesFromClient) {
clientBuilder.initializeHttp(builder -> builder.protocols(h2Config(keepAliveIdleFor)));
} else {
clientBuilder.initializeHttp(builder -> builder.socketOption(IDLE_TIMEOUT, idleTimeoutMillis).protocols(h2Config(null)));
}
client = clientBuilder.build(new ClientFactory());
}
use of io.servicetalk.grpc.api.GrpcServerBuilder in project servicetalk by apple.
the class TrailersOnlyErrorTest method testServiceFilterThrows.
@Test
void testServiceFilterThrows() throws Exception {
final BlockingQueue<Throwable> asyncErrors = new LinkedBlockingDeque<>();
final TesterService service = mockTesterService();
final GrpcServerBuilder serverBuilder = GrpcServers.forAddress(localAddress(0)).initializeHttp(builder -> builder.appendServiceFilter(svc -> new StreamingHttpServiceFilter(svc) {
@Override
public Single<StreamingHttpResponse> handle(final HttpServiceContext ctx, final StreamingHttpRequest request, final StreamingHttpResponseFactory responseFactory) {
throw DELIBERATE_EXCEPTION;
}
}));
try (ServerContext serverContext = serverBuilder.listenAndAwait(new Tester.ServiceFactory(service))) {
final GrpcClientBuilder<HostAndPort, InetSocketAddress> clientBuilder = GrpcClients.forAddress(serverHostAndPort(serverContext)).initializeHttp(builder -> builder.appendClientFilter(__ -> true, setupResponseVerifierFilter(asyncErrors)));
try (TesterClient client = clientBuilder.build(new Tester.ClientFactory())) {
verifyException(client.test(TestRequest.newBuilder().build()).toFuture(), UNKNOWN);
assertNoAsyncErrors(asyncErrors);
verifyException(client.testRequestStream(Publisher.from(TestRequest.newBuilder().build())).toFuture(), UNKNOWN);
assertNoAsyncErrors(asyncErrors);
verifyException(client.testResponseStream(TestRequest.newBuilder().build()).toFuture(), UNKNOWN);
assertNoAsyncErrors(asyncErrors);
verifyException(client.testBiDiStream(from(TestRequest.newBuilder().build()).concat(never())).toFuture(), UNKNOWN);
assertNoAsyncErrors(asyncErrors);
verifyException(client.testBiDiStream(from(TestRequest.newBuilder().build())).toFuture(), UNKNOWN);
assertNoAsyncErrors(asyncErrors);
}
}
}
Aggregations