Search in sources :

Example 1 with HTTP_EXECUTION_STRATEGY_KEY

use of io.servicetalk.http.api.HttpContextKeys.HTTP_EXECUTION_STRATEGY_KEY in project servicetalk by apple.

the class HttpStreamingClientOverrideOffloadingTest method reserveRespectsDisable.

@ParameterizedTest
@EnumSource(Params.class)
void reserveRespectsDisable(final Params params) throws Exception {
    setUp(params);
    StreamingHttpRequest request = client.get("/");
    request.context().put(HTTP_EXECUTION_STRATEGY_KEY, this.overridingStrategy);
    client.reserveConnection(request).beforeOnSuccess(__ -> {
        if (isInvalidThread()) {
            throw new AssertionError("Invalid thread found providing the connection. Thread: " + currentThread());
        }
    }).toFuture().get().closeAsync().toFuture().get();
}
Also used : StreamingHttpResponse(io.servicetalk.http.api.StreamingHttpResponse) EnumSource(org.junit.jupiter.params.provider.EnumSource) Thread.currentThread(java.lang.Thread.currentThread) HttpExecutionStrategies.defaultStrategy(io.servicetalk.http.api.HttpExecutionStrategies.defaultStrategy) StreamingHttpClient(io.servicetalk.http.api.StreamingHttpClient) NettyIoExecutors.createIoExecutor(io.servicetalk.transport.netty.NettyIoExecutors.createIoExecutor) Single.succeeded(io.servicetalk.concurrent.api.Single.succeeded) HttpExecutionStrategy(io.servicetalk.http.api.HttpExecutionStrategy) Executor(io.servicetalk.concurrent.api.Executor) Matchers.hasSize(org.hamcrest.Matchers.hasSize) StreamingHttpRequest(io.servicetalk.http.api.StreamingHttpRequest) AddressUtils.serverHostAndPort(io.servicetalk.transport.netty.internal.AddressUtils.serverHostAndPort) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Nullable(javax.annotation.Nullable) AddressUtils.localAddress(io.servicetalk.transport.netty.internal.AddressUtils.localAddress) ServerContext(io.servicetalk.transport.api.ServerContext) Predicate(java.util.function.Predicate) AsyncCloseables.newCompositeCloseable(io.servicetalk.concurrent.api.AsyncCloseables.newCompositeCloseable) InetSocketAddress(java.net.InetSocketAddress) HTTP_EXECUTION_STRATEGY_KEY(io.servicetalk.http.api.HttpContextKeys.HTTP_EXECUTION_STRATEGY_KEY) SingleAddressHttpClientBuilder(io.servicetalk.http.api.SingleAddressHttpClientBuilder) IoExecutor(io.servicetalk.transport.api.IoExecutor) AfterEach(org.junit.jupiter.api.AfterEach) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) Executors.newCachedThreadExecutor(io.servicetalk.concurrent.api.Executors.newCachedThreadExecutor) HostAndPort(io.servicetalk.transport.api.HostAndPort) ConcurrentLinkedQueue(java.util.concurrent.ConcurrentLinkedQueue) HttpExecutionStrategies.offloadNever(io.servicetalk.http.api.HttpExecutionStrategies.offloadNever) StreamingHttpRequest(io.servicetalk.http.api.StreamingHttpRequest) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 2 with HTTP_EXECUTION_STRATEGY_KEY

use of io.servicetalk.http.api.HttpContextKeys.HTTP_EXECUTION_STRATEGY_KEY in project servicetalk by apple.

the class HttpClientOverrideOffloadingTest method reserveRespectsDisable.

@ParameterizedTest
@EnumSource(Params.class)
void reserveRespectsDisable(final Params params) throws Exception {
    setUp(params);
    ConcurrentLinkedQueue<AssertionError> errors = new ConcurrentLinkedQueue<>();
    HttpRequest request = client.get("/");
    request.context().put(HTTP_EXECUTION_STRATEGY_KEY, this.overridingStrategy);
    client.reserveConnection(request).beforeOnSuccess(__ -> {
        if (isInvalidThread()) {
            errors.add(new AssertionError("Invalid thread found providing the connection. Thread: " + currentThread()));
        }
    }).toFuture().get().closeAsync().toFuture().get();
    assertThat("Unexpected errors: " + errors, errors, hasSize(0));
}
Also used : HttpRequest(io.servicetalk.http.api.HttpRequest) EnumSource(org.junit.jupiter.params.provider.EnumSource) Thread.currentThread(java.lang.Thread.currentThread) HttpExecutionStrategies.defaultStrategy(io.servicetalk.http.api.HttpExecutionStrategies.defaultStrategy) HttpRequest(io.servicetalk.http.api.HttpRequest) NettyIoExecutors.createIoExecutor(io.servicetalk.transport.netty.NettyIoExecutors.createIoExecutor) Single.succeeded(io.servicetalk.concurrent.api.Single.succeeded) HttpExecutionStrategy(io.servicetalk.http.api.HttpExecutionStrategy) Executor(io.servicetalk.concurrent.api.Executor) HttpClient(io.servicetalk.http.api.HttpClient) Matchers.hasSize(org.hamcrest.Matchers.hasSize) AddressUtils.serverHostAndPort(io.servicetalk.transport.netty.internal.AddressUtils.serverHostAndPort) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Nullable(javax.annotation.Nullable) AddressUtils.localAddress(io.servicetalk.transport.netty.internal.AddressUtils.localAddress) ServerContext(io.servicetalk.transport.api.ServerContext) Predicate(java.util.function.Predicate) AsyncCloseables.newCompositeCloseable(io.servicetalk.concurrent.api.AsyncCloseables.newCompositeCloseable) InetSocketAddress(java.net.InetSocketAddress) HTTP_EXECUTION_STRATEGY_KEY(io.servicetalk.http.api.HttpContextKeys.HTTP_EXECUTION_STRATEGY_KEY) SingleAddressHttpClientBuilder(io.servicetalk.http.api.SingleAddressHttpClientBuilder) IoExecutor(io.servicetalk.transport.api.IoExecutor) AfterEach(org.junit.jupiter.api.AfterEach) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) Executors.newCachedThreadExecutor(io.servicetalk.concurrent.api.Executors.newCachedThreadExecutor) HostAndPort(io.servicetalk.transport.api.HostAndPort) ConcurrentLinkedQueue(java.util.concurrent.ConcurrentLinkedQueue) HttpExecutionStrategies.offloadNever(io.servicetalk.http.api.HttpExecutionStrategies.offloadNever) ConcurrentLinkedQueue(java.util.concurrent.ConcurrentLinkedQueue) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 3 with HTTP_EXECUTION_STRATEGY_KEY

use of io.servicetalk.http.api.HttpContextKeys.HTTP_EXECUTION_STRATEGY_KEY in project servicetalk by apple.

the class HttpStreamingClientOverrideOffloadingTest method requestRespectsDisable.

@ParameterizedTest
@EnumSource(Params.class)
void requestRespectsDisable(final Params params) throws Exception {
    setUp(params);
    ConcurrentLinkedQueue<AssertionError> errors = new ConcurrentLinkedQueue<>();
    StreamingHttpRequest req = client.get("/").transformPayloadBody(p -> p.beforeRequest(__ -> {
        if (isInvalidThread()) {
            errors.add(new AssertionError("Invalid thread called request-n. Thread: " + currentThread()));
        }
    }));
    req.context().put(HTTP_EXECUTION_STRATEGY_KEY, this.overridingStrategy);
    client.request(req).beforeOnSuccess(__ -> {
        if (isInvalidThread()) {
            errors.add(new AssertionError("Invalid thread called response metadata. " + "Thread: " + currentThread()));
        }
    }).flatMapPublisher(StreamingHttpResponse::payloadBody).beforeOnNext(__ -> {
        if (isInvalidThread()) {
            errors.add(new AssertionError("Invalid thread called response payload onNext. " + "Thread: " + currentThread()));
        }
    }).beforeOnComplete(() -> {
        if (isInvalidThread()) {
            errors.add(new AssertionError("Invalid thread called response payload onComplete. " + "Thread: " + currentThread()));
        }
    }).toFuture().get();
    assertThat("Unexpected errors: " + errors, errors, hasSize(0));
}
Also used : StreamingHttpResponse(io.servicetalk.http.api.StreamingHttpResponse) EnumSource(org.junit.jupiter.params.provider.EnumSource) Thread.currentThread(java.lang.Thread.currentThread) HttpExecutionStrategies.defaultStrategy(io.servicetalk.http.api.HttpExecutionStrategies.defaultStrategy) StreamingHttpClient(io.servicetalk.http.api.StreamingHttpClient) NettyIoExecutors.createIoExecutor(io.servicetalk.transport.netty.NettyIoExecutors.createIoExecutor) Single.succeeded(io.servicetalk.concurrent.api.Single.succeeded) HttpExecutionStrategy(io.servicetalk.http.api.HttpExecutionStrategy) Executor(io.servicetalk.concurrent.api.Executor) Matchers.hasSize(org.hamcrest.Matchers.hasSize) StreamingHttpRequest(io.servicetalk.http.api.StreamingHttpRequest) AddressUtils.serverHostAndPort(io.servicetalk.transport.netty.internal.AddressUtils.serverHostAndPort) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Nullable(javax.annotation.Nullable) AddressUtils.localAddress(io.servicetalk.transport.netty.internal.AddressUtils.localAddress) ServerContext(io.servicetalk.transport.api.ServerContext) Predicate(java.util.function.Predicate) AsyncCloseables.newCompositeCloseable(io.servicetalk.concurrent.api.AsyncCloseables.newCompositeCloseable) InetSocketAddress(java.net.InetSocketAddress) HTTP_EXECUTION_STRATEGY_KEY(io.servicetalk.http.api.HttpContextKeys.HTTP_EXECUTION_STRATEGY_KEY) SingleAddressHttpClientBuilder(io.servicetalk.http.api.SingleAddressHttpClientBuilder) IoExecutor(io.servicetalk.transport.api.IoExecutor) AfterEach(org.junit.jupiter.api.AfterEach) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) Executors.newCachedThreadExecutor(io.servicetalk.concurrent.api.Executors.newCachedThreadExecutor) HostAndPort(io.servicetalk.transport.api.HostAndPort) ConcurrentLinkedQueue(java.util.concurrent.ConcurrentLinkedQueue) HttpExecutionStrategies.offloadNever(io.servicetalk.http.api.HttpExecutionStrategies.offloadNever) StreamingHttpRequest(io.servicetalk.http.api.StreamingHttpRequest) ConcurrentLinkedQueue(java.util.concurrent.ConcurrentLinkedQueue) StreamingHttpResponse(io.servicetalk.http.api.StreamingHttpResponse) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

AsyncCloseables.newCompositeCloseable (io.servicetalk.concurrent.api.AsyncCloseables.newCompositeCloseable)3 Executor (io.servicetalk.concurrent.api.Executor)3 Executors.newCachedThreadExecutor (io.servicetalk.concurrent.api.Executors.newCachedThreadExecutor)3 Single.succeeded (io.servicetalk.concurrent.api.Single.succeeded)3 HTTP_EXECUTION_STRATEGY_KEY (io.servicetalk.http.api.HttpContextKeys.HTTP_EXECUTION_STRATEGY_KEY)3 HttpExecutionStrategies.defaultStrategy (io.servicetalk.http.api.HttpExecutionStrategies.defaultStrategy)3 HttpExecutionStrategies.offloadNever (io.servicetalk.http.api.HttpExecutionStrategies.offloadNever)3 HttpExecutionStrategy (io.servicetalk.http.api.HttpExecutionStrategy)3 SingleAddressHttpClientBuilder (io.servicetalk.http.api.SingleAddressHttpClientBuilder)3 HostAndPort (io.servicetalk.transport.api.HostAndPort)3 IoExecutor (io.servicetalk.transport.api.IoExecutor)3 ServerContext (io.servicetalk.transport.api.ServerContext)3 NettyIoExecutors.createIoExecutor (io.servicetalk.transport.netty.NettyIoExecutors.createIoExecutor)3 AddressUtils.localAddress (io.servicetalk.transport.netty.internal.AddressUtils.localAddress)3 AddressUtils.serverHostAndPort (io.servicetalk.transport.netty.internal.AddressUtils.serverHostAndPort)3 Thread.currentThread (java.lang.Thread.currentThread)3 InetSocketAddress (java.net.InetSocketAddress)3 ConcurrentLinkedQueue (java.util.concurrent.ConcurrentLinkedQueue)3 Predicate (java.util.function.Predicate)3 Nullable (javax.annotation.Nullable)3