Search in sources :

Example 66 with ServerContext

use of io.servicetalk.transport.api.ServerContext in project servicetalk by apple.

the class DefaultHealthServiceTest method defaultWatch.

@Test
void defaultWatch() 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())) {
            BlockingIterator<HealthCheckResponse> itr = client.watch(newRequest(OVERALL_SERVICE_NAME)).iterator();
            assertThat(itr.next().getStatus(), equalTo(SERVING));
            assertThat(service.setStatus(OVERALL_SERVICE_NAME, NOT_SERVING), equalTo(true));
            assertThat(itr.next().getStatus(), equalTo(NOT_SERVING));
        }
    }
}
Also used : ServerContext(io.servicetalk.transport.api.ServerContext) HealthCheckResponse(io.servicetalk.health.v1.HealthCheckResponse) Health(io.servicetalk.health.v1.Health) InetSocketAddress(java.net.InetSocketAddress) Test(org.junit.jupiter.api.Test)

Example 67 with ServerContext

use of io.servicetalk.transport.api.ServerContext in project servicetalk by apple.

the class DefaultHealthServiceTest method statusChangeCheck.

@Test
void statusChangeCheck() throws Exception {
    DefaultHealthService service = new DefaultHealthService();
    String serviceName = "service";
    ServingStatus serviceStatus = NOT_SERVING;
    service.setStatus(serviceName, serviceStatus);
    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(serviceName)).getStatus(), equalTo(serviceStatus));
        }
    }
}
Also used : ServingStatus(io.servicetalk.health.v1.HealthCheckResponse.ServingStatus) ServerContext(io.servicetalk.transport.api.ServerContext) Health(io.servicetalk.health.v1.Health) InetSocketAddress(java.net.InetSocketAddress) Test(org.junit.jupiter.api.Test)

Example 68 with ServerContext

use of io.servicetalk.transport.api.ServerContext in project servicetalk by apple.

the class ClosureTest method startServerAndClose.

private void startServerAndClose(final ServiceFactory serviceFactory, final CloseSignal signal) throws Exception {
    ServerContext serverContext = forAddress(localAddress(0)).listenAndAwait(serviceFactory);
    if (closeGracefully) {
        serverContext.closeGracefully();
    } else {
        serverContext.close();
    }
    signal.await();
}
Also used : ServerContext(io.servicetalk.transport.api.ServerContext)

Example 69 with ServerContext

use of io.servicetalk.transport.api.ServerContext in project servicetalk by apple.

the class FlushStrategyOnServerTest method setUp.

private void setUp(final Param param) {
    this.interceptor = new OutboundWriteEventsInterceptor();
    this.headersFactory = DefaultHttpHeadersFactory.INSTANCE;
    final StreamingHttpService service = (ctx, request, responseFactory) -> {
        StreamingHttpResponse resp = responseFactory.ok();
        if (request.headers().get(USE_EMPTY_RESP_BODY) == null) {
            resp.payloadBody(from("Hello", "World"), appSerializerUtf8FixLen());
        }
        if (request.headers().get(USE_AGGREGATED_RESP) != null) {
            return resp.toResponse().map(HttpResponse::toStreamingResponse);
        }
        return succeeded(resp);
    };
    final DefaultHttpExecutionContext httpExecutionContext = new DefaultHttpExecutionContext(DEFAULT_ALLOCATOR, globalExecutionContext().ioExecutor(), EXECUTOR_RULE.executor(), param.executionStrategy);
    final ReadOnlyHttpServerConfig config = new HttpServerConfig().asReadOnly();
    final ReadOnlyTcpServerConfig tcpReadOnly = new TcpServerConfig().asReadOnly();
    try {
        serverContext = TcpServerBinder.bind(localAddress(0), tcpReadOnly, true, httpExecutionContext, null, (channel, observer) -> {
            final ConnectionObserver connectionObserver = config.tcpConfig().transportObserver().onNewConnection(channel.localAddress(), channel.remoteAddress());
            return initChannel(channel, httpExecutionContext, config, new TcpServerChannelInitializer(tcpReadOnly, connectionObserver).andThen(channel1 -> channel1.pipeline().addLast(interceptor)), service, true, connectionObserver);
        }, connection -> connection.process(true)).map(delegate -> new NettyHttpServerContext(delegate, service, httpExecutionContext)).toFuture().get();
    } catch (Exception e) {
        fail(e);
    }
    client = HttpClients.forSingleAddress(serverHostAndPort(serverContext)).protocols(h1Default()).buildBlocking();
}
Also used : DefaultHttpExecutionContext(io.servicetalk.http.api.DefaultHttpExecutionContext) TcpServerChannelInitializer(io.servicetalk.tcp.netty.internal.TcpServerChannelInitializer) TcpServerConfig(io.servicetalk.tcp.netty.internal.TcpServerConfig) ReadOnlyTcpServerConfig(io.servicetalk.tcp.netty.internal.ReadOnlyTcpServerConfig) ChannelPromise(io.netty.channel.ChannelPromise) HttpExecutionStrategies.defaultStrategy(io.servicetalk.http.api.HttpExecutionStrategies.defaultStrategy) Executor(io.servicetalk.concurrent.api.Executor) HttpExecutionStrategies.offloadNone(io.servicetalk.http.api.HttpExecutionStrategies.offloadNone) GlobalExecutionContext.globalExecutionContext(io.servicetalk.transport.netty.internal.GlobalExecutionContext.globalExecutionContext) BlockingHttpClient(io.servicetalk.http.api.BlockingHttpClient) ChannelOutboundHandlerAdapter(io.netty.channel.ChannelOutboundHandlerAdapter) ExecutorExtension(io.servicetalk.concurrent.api.ExecutorExtension) HttpResponse(io.servicetalk.http.api.HttpResponse) TRANSFER_ENCODING(io.servicetalk.http.api.HttpHeaderNames.TRANSFER_ENCODING) BlockingQueue(java.util.concurrent.BlockingQueue) DefaultHttpHeadersFactory(io.servicetalk.http.api.DefaultHttpHeadersFactory) HttpExecutionStrategies.customStrategyBuilder(io.servicetalk.http.api.HttpExecutionStrategies.customStrategyBuilder) StreamingHttpService(io.servicetalk.http.api.StreamingHttpService) Matchers.greaterThan(org.hamcrest.Matchers.greaterThan) Matchers.is(org.hamcrest.Matchers.is) Assertions.fail(org.junit.jupiter.api.Assertions.fail) StreamingHttpResponse(io.servicetalk.http.api.StreamingHttpResponse) DEFAULT_ALLOCATOR(io.servicetalk.buffer.netty.BufferAllocators.DEFAULT_ALLOCATOR) StreamingHttpRequests.newTransportRequest(io.servicetalk.http.api.StreamingHttpRequests.newTransportRequest) HttpHeaders(io.servicetalk.http.api.HttpHeaders) EnumSource(org.junit.jupiter.params.provider.EnumSource) NettyHttpServer.initChannel(io.servicetalk.http.netty.NettyHttpServer.initChannel) ChannelHandlerContext(io.netty.channel.ChannelHandlerContext) ConnectionObserver(io.servicetalk.transport.api.ConnectionObserver) HttpProtocolConfigs.h1Default(io.servicetalk.http.netty.HttpProtocolConfigs.h1Default) RegisterExtension(org.junit.jupiter.api.extension.RegisterExtension) Single.succeeded(io.servicetalk.concurrent.api.Single.succeeded) HttpSerializers.appSerializerUtf8FixLen(io.servicetalk.http.api.HttpSerializers.appSerializerUtf8FixLen) HttpExecutionStrategy(io.servicetalk.http.api.HttpExecutionStrategy) StreamingHttpRequest(io.servicetalk.http.api.StreamingHttpRequest) AddressUtils.serverHostAndPort(io.servicetalk.transport.netty.internal.AddressUtils.serverHostAndPort) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Publisher.from(io.servicetalk.concurrent.api.Publisher.from) CHUNKED(io.servicetalk.http.api.HttpHeaderValues.CHUNKED) AddressUtils.localAddress(io.servicetalk.transport.netty.internal.AddressUtils.localAddress) ServerContext(io.servicetalk.transport.api.ServerContext) GET(io.servicetalk.http.api.HttpRequestMethod.GET) TcpServerBinder(io.servicetalk.tcp.netty.internal.TcpServerBinder) NettyHttpServerContext(io.servicetalk.http.netty.NettyHttpServer.NettyHttpServerContext) AfterEach(org.junit.jupiter.api.AfterEach) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) LinkedBlockingDeque(java.util.concurrent.LinkedBlockingDeque) HttpHeadersFactory(io.servicetalk.http.api.HttpHeadersFactory) HTTP_1_1(io.servicetalk.http.api.HttpProtocolVersion.HTTP_1_1) NettyHttpServerContext(io.servicetalk.http.netty.NettyHttpServer.NettyHttpServerContext) TcpServerChannelInitializer(io.servicetalk.tcp.netty.internal.TcpServerChannelInitializer) DefaultHttpExecutionContext(io.servicetalk.http.api.DefaultHttpExecutionContext) TcpServerConfig(io.servicetalk.tcp.netty.internal.TcpServerConfig) ReadOnlyTcpServerConfig(io.servicetalk.tcp.netty.internal.ReadOnlyTcpServerConfig) ConnectionObserver(io.servicetalk.transport.api.ConnectionObserver) StreamingHttpService(io.servicetalk.http.api.StreamingHttpService) ReadOnlyTcpServerConfig(io.servicetalk.tcp.netty.internal.ReadOnlyTcpServerConfig) StreamingHttpResponse(io.servicetalk.http.api.StreamingHttpResponse)

Example 70 with ServerContext

use of io.servicetalk.transport.api.ServerContext in project servicetalk by apple.

the class H2PriorKnowledgeFeatureParityTest method h2LayerFiltersOutProhibitedH1HeadersOnServerSide.

@Test
void h2LayerFiltersOutProhibitedH1HeadersOnServerSide() throws Exception {
    setUp(DEFAULT, true);
    try (ServerContext serverContext = HttpServers.forAddress(localAddress(0)).protocols(HttpProtocol.HTTP_2.config).enableWireLogging("servicetalk-tests-wire-logger", LogLevel.TRACE, () -> true).listenBlockingAndAwait((ctx, request, responseFactory) -> addProhibitedHeaders(responseFactory.ok()));
        BlockingHttpClient client = forSingleAddress(serverHostAndPort(serverContext)).protocols(HttpProtocol.HTTP_2.config).enableWireLogging("servicetalk-tests-wire-logger", LogLevel.TRACE, () -> true).executionStrategy(clientExecutionStrategy).buildBlocking()) {
        HttpResponse response = client.request(client.get("/"));
        assertThat(response.status(), is(OK));
        for (CharSequence headerName : PROHIBITED_HEADERS) {
            assertThat("Unexpected headerName: " + headerName, response.headers().contains(headerName), is(false));
        }
    }
}
Also used : ServerContext(io.servicetalk.transport.api.ServerContext) BlockingHttpClient(io.servicetalk.http.api.BlockingHttpClient) HttpResponse(io.servicetalk.http.api.HttpResponse) StreamingHttpResponse(io.servicetalk.http.api.StreamingHttpResponse) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) Test(org.junit.jupiter.api.Test)

Aggregations

ServerContext (io.servicetalk.transport.api.ServerContext)106 Test (org.junit.jupiter.api.Test)57 BlockingHttpClient (io.servicetalk.http.api.BlockingHttpClient)42 HttpResponse (io.servicetalk.http.api.HttpResponse)39 AddressUtils.serverHostAndPort (io.servicetalk.transport.netty.internal.AddressUtils.serverHostAndPort)34 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)34 AddressUtils.localAddress (io.servicetalk.transport.netty.internal.AddressUtils.localAddress)33 StreamingHttpResponse (io.servicetalk.http.api.StreamingHttpResponse)28 InetSocketAddress (java.net.InetSocketAddress)27 MatcherAssert.assertThat (org.hamcrest.MatcherAssert.assertThat)26 StreamingHttpRequest (io.servicetalk.http.api.StreamingHttpRequest)24 MethodSource (org.junit.jupiter.params.provider.MethodSource)22 HostAndPort (io.servicetalk.transport.api.HostAndPort)20 Single (io.servicetalk.concurrent.api.Single)19 Single.succeeded (io.servicetalk.concurrent.api.Single.succeeded)19 StreamingHttpClient (io.servicetalk.http.api.StreamingHttpClient)16 ClientSslConfigBuilder (io.servicetalk.transport.api.ClientSslConfigBuilder)15 OK (io.servicetalk.http.api.HttpResponseStatus.OK)14 DefaultTestCerts (io.servicetalk.test.resources.DefaultTestCerts)14 AtomicReference (java.util.concurrent.atomic.AtomicReference)14