Search in sources :

Example 1 with PoolAcquireTimeoutException

use of reactor.netty.internal.shaded.reactor.pool.PoolAcquireTimeoutException in project reactor-netty by reactor.

the class Http2Tests method doTestMaxActiveStreams.

void doTestMaxActiveStreams(HttpClient baseClient, int maxActiveStreams, int concurrency, int prefetch, int expectedOnNext, int expectedOnError) throws Exception {
    Http2SslContextSpec serverCtx = Http2SslContextSpec.forServer(ssc.certificate(), ssc.privateKey());
    Http2SslContextSpec clientCtx = Http2SslContextSpec.forClient().configure(builder -> builder.trustManager(InsecureTrustManagerFactory.INSTANCE));
    disposableServer = createServer().protocol(HttpProtocol.H2).secure(spec -> spec.sslContext(serverCtx)).route(routes -> routes.post("/echo", (req, res) -> res.send(req.receive().aggregate().retain().delayElement(Duration.ofMillis(100))))).http2Settings(setting -> setting.maxConcurrentStreams(maxActiveStreams)).bindNow();
    HttpClient client = baseClient.port(disposableServer.port()).protocol(HttpProtocol.H2).secure(spec -> spec.sslContext(clientCtx)).wiretap(true);
    CountDownLatch latch = new CountDownLatch(1);
    List<? extends Signal<? extends String>> list = Flux.range(0, 2).flatMapDelayError(i -> client.post().uri("/echo").send(ByteBufFlux.fromString(Mono.just("doTestMaxActiveStreams"))).responseContent().aggregate().asString().materialize(), concurrency, prefetch).collectList().doFinally(fin -> latch.countDown()).block(Duration.ofSeconds(30));
    assertThat(latch.await(30, TimeUnit.SECONDS)).as("latch 30s").isTrue();
    assertThat(list).isNotNull().hasSize(2);
    int onNext = 0;
    int onError = 0;
    String msg = "Pool#acquire(Duration) has been pending for more than the configured timeout of 10ms";
    for (int i = 0; i < 2; i++) {
        Signal<? extends String> signal = list.get(i);
        if (signal.isOnNext()) {
            onNext++;
        } else if (signal.getThrowable() instanceof PoolAcquireTimeoutException && signal.getThrowable().getMessage().contains(msg)) {
            onError++;
        }
    }
    assertThat(onNext).isEqualTo(expectedOnNext);
    assertThat(onError).isEqualTo(expectedOnError);
}
Also used : IntStream(java.util.stream.IntStream) StepVerifier(reactor.test.StepVerifier) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) BaseHttpTest(reactor.netty.BaseHttpTest) Tuple2(reactor.util.function.Tuple2) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) InsecureTrustManagerFactory(io.netty.handler.ssl.util.InsecureTrustManagerFactory) ProtocolSslContextSpec(reactor.netty.tcp.SslProvider.ProtocolSslContextSpec) ByteBuf(io.netty.buffer.ByteBuf) BeforeAll(org.junit.jupiter.api.BeforeAll) ByteBufFlux(reactor.netty.ByteBufFlux) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Duration(java.time.Duration) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) ByteBufMono(reactor.netty.ByteBufMono) SelfSignedCertificate(io.netty.handler.ssl.util.SelfSignedCertificate) Predicate(java.util.function.Predicate) Publisher(org.reactivestreams.Publisher) Mono(reactor.core.publisher.Mono) Signal(reactor.core.publisher.Signal) CertificateException(java.security.cert.CertificateException) Test(org.junit.jupiter.api.Test) TimeUnit(java.util.concurrent.TimeUnit) Flux(reactor.core.publisher.Flux) CountDownLatch(java.util.concurrent.CountDownLatch) HttpServer(reactor.netty.http.server.HttpServer) List(java.util.List) PoolAcquireTimeoutException(reactor.netty.internal.shaded.reactor.pool.PoolAcquireTimeoutException) ConnectionProvider(reactor.netty.resources.ConnectionProvider) HttpClient(reactor.netty.http.client.HttpClient) HttpClient(reactor.netty.http.client.HttpClient) PoolAcquireTimeoutException(reactor.netty.internal.shaded.reactor.pool.PoolAcquireTimeoutException) CountDownLatch(java.util.concurrent.CountDownLatch)

Aggregations

ByteBuf (io.netty.buffer.ByteBuf)1 InsecureTrustManagerFactory (io.netty.handler.ssl.util.InsecureTrustManagerFactory)1 SelfSignedCertificate (io.netty.handler.ssl.util.SelfSignedCertificate)1 CertificateException (java.security.cert.CertificateException)1 Duration (java.time.Duration)1 List (java.util.List)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 ThreadLocalRandom (java.util.concurrent.ThreadLocalRandom)1 TimeUnit (java.util.concurrent.TimeUnit)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 Predicate (java.util.function.Predicate)1 IntStream (java.util.stream.IntStream)1 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)1 BeforeAll (org.junit.jupiter.api.BeforeAll)1 Test (org.junit.jupiter.api.Test)1 Publisher (org.reactivestreams.Publisher)1 Flux (reactor.core.publisher.Flux)1 Mono (reactor.core.publisher.Mono)1 Signal (reactor.core.publisher.Signal)1