use of io.servicetalk.transport.api.ServerContext in project servicetalk by apple.
the class AbstractHttpServiceAsyncContextTest method connectionAcceptorContextDoesNotLeak.
final void connectionAcceptorContextDoesNotLeak(boolean serverUseImmediate) throws Exception {
try (ServerContext ctx = serverWithEmptyAsyncContextService(HttpServers.forAddress(localAddress(0)).appendConnectionAcceptorFilter(original -> new DelegatingConnectionAcceptor(context -> {
AsyncContext.put(K1, "v1");
return completed();
})), serverUseImmediate);
StreamingHttpClient client = HttpClients.forResolvedAddress(serverHostAndPort(ctx)).buildStreaming();
StreamingHttpConnection connection = client.reserveConnection(client.get("/")).toFuture().get()) {
makeClientRequestWithId(connection, "1");
makeClientRequestWithId(connection, "2");
}
}
use of io.servicetalk.transport.api.ServerContext in project servicetalk by apple.
the class DefaultHealthServiceTest method clearWatch.
@Test
void clearWatch() throws Exception {
DefaultHealthService service = new DefaultHealthService();
try (ServerContext serverCtx = GrpcServers.forAddress(localAddress(0)).listenAndAwait(service)) {
try (Health.BlockingHealthClient client = GrpcClients.forResolvedAddress((InetSocketAddress) serverCtx.listenAddress()).buildBlocking(new Health.ClientFactory())) {
assertThat(service.clearStatus(OVERALL_SERVICE_NAME), equalTo(true));
BlockingIterator<HealthCheckResponse> itr = client.watch(newRequest(OVERALL_SERVICE_NAME)).iterator();
assertThat(itr.next().getStatus(), equalTo(SERVICE_UNKNOWN));
assertThat(service.setStatus(OVERALL_SERVICE_NAME, SERVING), equalTo(true));
assertThat(itr.next().getStatus(), equalTo(SERVING));
}
}
}
use of io.servicetalk.transport.api.ServerContext in project servicetalk by apple.
the class DefaultHealthServiceTest method defaultCheck.
@Test
void defaultCheck() throws Exception {
DefaultHealthService service = new DefaultHealthService();
try (ServerContext serverCtx = GrpcServers.forAddress(localAddress(0)).listenAndAwait(service)) {
try (Health.BlockingHealthClient client = GrpcClients.forResolvedAddress((InetSocketAddress) serverCtx.listenAddress()).buildBlocking(new Health.ClientFactory())) {
assertThat(client.check(newRequest(OVERALL_SERVICE_NAME)).getStatus(), equalTo(SERVING));
assertThat(service.setStatus(OVERALL_SERVICE_NAME, NOT_SERVING), equalTo(true));
assertThat(client.check(newRequest(OVERALL_SERVICE_NAME)).getStatus(), equalTo(NOT_SERVING));
}
}
}
use of io.servicetalk.transport.api.ServerContext in project servicetalk by apple.
the class BackendStarter method start.
ServerContext start(int listenPort, String name, StreamingHttpService service) throws Exception {
// Starting the server will start listening for incoming client requests.
final ServerContext ctx = HttpServers.forPort(listenPort).ioExecutor(ioExecutor).appendServiceFilter(new ErrorResponseGeneratingServiceFilter(name)).listenStreamingAndAwait(service);
LOGGER.info("Started {} listening on {}.", name, ctx.listenAddress());
return ctx;
}
use of io.servicetalk.transport.api.ServerContext in project servicetalk by apple.
the class BackendsStarter method main.
public static void main(String[] args) throws Exception {
// Create an AutoCloseable representing all resources used in this example.
try (CompositeCloseable resources = newCompositeCloseable()) {
// Shared IoExecutor for the application.
IoExecutor ioExecutor = resources.prepend(createIoExecutor());
// This is a single Completable used to await closing of all backends started by this class. It is used to
// provide a way to not let main() exit.
Completable allServicesOnClose = completed();
BackendStarter starter = new BackendStarter(ioExecutor, resources);
final ServerContext recommendationService = starter.start(RECOMMENDATIONS_BACKEND_ADDRESS.port(), RECOMMENDATION_SERVICE_NAME, newRecommendationsService());
allServicesOnClose = allServicesOnClose.merge(recommendationService.onClose());
final ServerContext metadataService = starter.start(METADATA_BACKEND_ADDRESS.port(), METADATA_SERVICE_NAME, newMetadataService());
allServicesOnClose = allServicesOnClose.merge(metadataService.onClose());
final ServerContext userService = starter.start(USER_BACKEND_ADDRESS.port(), USER_SERVICE_NAME, newUserService());
allServicesOnClose = allServicesOnClose.merge(userService.onClose());
final ServerContext ratingService = starter.start(RATINGS_BACKEND_ADDRESS.port(), RATING_SERVICE_NAME, newRatingService());
allServicesOnClose = allServicesOnClose.merge(ratingService.onClose());
// Await termination of all backends started by this class.
allServicesOnClose.toFuture().get();
}
}
Aggregations