Search in sources :

Example 6 with Http2SslContextSpec

use of reactor.netty.http.Http2SslContextSpec in project reactor-netty by reactor.

the class PooledConnectionProviderDefaultMetricsTest method testConnectionProviderMetricsEnableAndHttpClientMetricsDisabledHttp2.

@Test
void testConnectionProviderMetricsEnableAndHttpClientMetricsDisabledHttp2() throws Exception {
    Http2SslContextSpec serverCtx = Http2SslContextSpec.forServer(ssc.certificate(), ssc.privateKey());
    Http2SslContextSpec clientCtx = Http2SslContextSpec.forClient().configure(builder -> builder.trustManager(InsecureTrustManagerFactory.INSTANCE));
    ConnectionProvider provider = ConnectionProvider.builder("test4").maxConnections(1).pendingAcquireMaxCount(10).metrics(true).lifo().build();
    try {
        doTest(createServer().protocol(HttpProtocol.H2).secure(spec -> spec.sslContext(serverCtx)), createClient(provider, () -> disposableServer.address()).protocol(HttpProtocol.H2).secure(spec -> spec.sslContext(clientCtx)), "test4", false, 1, 10);
    } finally {
        provider.disposeLater().block(Duration.ofSeconds(5));
    }
}
Also used : Http2SslContextSpec(reactor.netty.http.Http2SslContextSpec) TOTAL_CONNECTIONS(reactor.netty.Metrics.TOTAL_CONNECTIONS) BeforeEach(org.junit.jupiter.api.BeforeEach) MAX_CONNECTIONS(reactor.netty.Metrics.MAX_CONNECTIONS) SimpleMeterRegistry(io.micrometer.api.instrument.simple.SimpleMeterRegistry) HttpProtocol(reactor.netty.http.HttpProtocol) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Http2SslContextSpec(reactor.netty.http.Http2SslContextSpec) BaseHttpTest(reactor.netty.BaseHttpTest) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) NAME(reactor.netty.Metrics.NAME) Function(java.util.function.Function) PENDING_STREAMS(reactor.netty.Metrics.PENDING_STREAMS) InsecureTrustManagerFactory(io.netty.handler.ssl.util.InsecureTrustManagerFactory) CONNECTION_PROVIDER_PREFIX(reactor.netty.Metrics.CONNECTION_PROVIDER_PREFIX) BeforeAll(org.junit.jupiter.api.BeforeAll) ACTIVE_CONNECTIONS(reactor.netty.Metrics.ACTIVE_CONNECTIONS) Duration(java.time.Duration) PENDING_CONNECTIONS(reactor.netty.Metrics.PENDING_CONNECTIONS) SelfSignedCertificate(io.netty.handler.ssl.util.SelfSignedCertificate) Mono(reactor.core.publisher.Mono) CertificateException(java.security.cert.CertificateException) Test(org.junit.jupiter.api.Test) TimeUnit(java.util.concurrent.TimeUnit) IDLE_CONNECTIONS(reactor.netty.Metrics.IDLE_CONNECTIONS) CountDownLatch(java.util.concurrent.CountDownLatch) AfterEach(org.junit.jupiter.api.AfterEach) HttpServer(reactor.netty.http.server.HttpServer) MAX_PENDING_CONNECTIONS(reactor.netty.Metrics.MAX_PENDING_CONNECTIONS) MeterRegistry(io.micrometer.api.instrument.MeterRegistry) Metrics(io.micrometer.api.instrument.Metrics) ACTIVE_STREAMS(reactor.netty.Metrics.ACTIVE_STREAMS) Gauge(io.micrometer.api.instrument.Gauge) HttpClient(reactor.netty.http.client.HttpClient) BaseHttpTest(reactor.netty.BaseHttpTest) Test(org.junit.jupiter.api.Test)

Example 7 with Http2SslContextSpec

use of reactor.netty.http.Http2SslContextSpec in project reactor-netty by reactor.

the class PooledConnectionProviderDefaultMetricsTest method testConnectionProviderMetricsDisabledAndHttpClientMetricsEnabledHttp2.

@Test
void testConnectionProviderMetricsDisabledAndHttpClientMetricsEnabledHttp2() throws Exception {
    // by default, when the max number of pending acquire is not specified, it will bet set to 2 * max-connection
    // (see PoolFactory from PoolConnectionProvider.java)
    Http2SslContextSpec serverCtx = Http2SslContextSpec.forServer(ssc.certificate(), ssc.privateKey());
    Http2SslContextSpec clientCtx = Http2SslContextSpec.forClient().configure(builder -> builder.trustManager(InsecureTrustManagerFactory.INSTANCE));
    ConnectionProvider provider = ConnectionProvider.create("test2", 1);
    try {
        doTest(createServer().protocol(HttpProtocol.H2).secure(spec -> spec.sslContext(serverCtx)), createClient(provider, () -> disposableServer.address()).protocol(HttpProtocol.H2).secure(spec -> spec.sslContext(clientCtx)), "test2", true, 1, 2);
    } finally {
        provider.disposeLater().block(Duration.ofSeconds(5));
    }
}
Also used : Http2SslContextSpec(reactor.netty.http.Http2SslContextSpec) TOTAL_CONNECTIONS(reactor.netty.Metrics.TOTAL_CONNECTIONS) BeforeEach(org.junit.jupiter.api.BeforeEach) MAX_CONNECTIONS(reactor.netty.Metrics.MAX_CONNECTIONS) SimpleMeterRegistry(io.micrometer.api.instrument.simple.SimpleMeterRegistry) HttpProtocol(reactor.netty.http.HttpProtocol) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Http2SslContextSpec(reactor.netty.http.Http2SslContextSpec) BaseHttpTest(reactor.netty.BaseHttpTest) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) NAME(reactor.netty.Metrics.NAME) Function(java.util.function.Function) PENDING_STREAMS(reactor.netty.Metrics.PENDING_STREAMS) InsecureTrustManagerFactory(io.netty.handler.ssl.util.InsecureTrustManagerFactory) CONNECTION_PROVIDER_PREFIX(reactor.netty.Metrics.CONNECTION_PROVIDER_PREFIX) BeforeAll(org.junit.jupiter.api.BeforeAll) ACTIVE_CONNECTIONS(reactor.netty.Metrics.ACTIVE_CONNECTIONS) Duration(java.time.Duration) PENDING_CONNECTIONS(reactor.netty.Metrics.PENDING_CONNECTIONS) SelfSignedCertificate(io.netty.handler.ssl.util.SelfSignedCertificate) Mono(reactor.core.publisher.Mono) CertificateException(java.security.cert.CertificateException) Test(org.junit.jupiter.api.Test) TimeUnit(java.util.concurrent.TimeUnit) IDLE_CONNECTIONS(reactor.netty.Metrics.IDLE_CONNECTIONS) CountDownLatch(java.util.concurrent.CountDownLatch) AfterEach(org.junit.jupiter.api.AfterEach) HttpServer(reactor.netty.http.server.HttpServer) MAX_PENDING_CONNECTIONS(reactor.netty.Metrics.MAX_PENDING_CONNECTIONS) MeterRegistry(io.micrometer.api.instrument.MeterRegistry) Metrics(io.micrometer.api.instrument.Metrics) ACTIVE_STREAMS(reactor.netty.Metrics.ACTIVE_STREAMS) Gauge(io.micrometer.api.instrument.Gauge) HttpClient(reactor.netty.http.client.HttpClient) BaseHttpTest(reactor.netty.BaseHttpTest) Test(org.junit.jupiter.api.Test)

Example 8 with Http2SslContextSpec

use of reactor.netty.http.Http2SslContextSpec in project reactor-netty by reactor.

the class DefaultPooledConnectionProviderTest method testIssue1982H2.

@ParameterizedTest
@MethodSource("h2CompatibleCombinations")
void testIssue1982H2(HttpProtocol[] serverProtocols, HttpProtocol[] clientProtocols) throws Exception {
    Http2SslContextSpec serverCtx = Http2SslContextSpec.forServer(ssc.certificate(), ssc.privateKey());
    Http2SslContextSpec clientCtx = Http2SslContextSpec.forClient().configure(builder -> builder.trustManager(InsecureTrustManagerFactory.INSTANCE));
    doTestIssue1982(serverProtocols, clientProtocols, serverCtx, clientCtx);
}
Also used : Http2SslContextSpec(reactor.netty.http.Http2SslContextSpec) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 9 with Http2SslContextSpec

use of reactor.netty.http.Http2SslContextSpec in project reactor-netty by reactor.

the class DefaultPooledConnectionProviderTest method testConnectionReturnedToParentPoolWhenNoActiveStreams.

@Test
void testConnectionReturnedToParentPoolWhenNoActiveStreams() throws Exception {
    Http2SslContextSpec serverCtx = Http2SslContextSpec.forServer(ssc.certificate(), ssc.privateKey());
    Http2SslContextSpec clientCtx = Http2SslContextSpec.forClient().configure(builder -> builder.trustManager(InsecureTrustManagerFactory.INSTANCE));
    disposableServer = createServer().wiretap(false).protocol(HttpProtocol.H2).secure(spec -> spec.sslContext(serverCtx)).route(routes -> routes.post("/", (req, res) -> res.send(req.receive().retain()))).bindNow();
    int requestsNum = 10;
    CountDownLatch latch = new CountDownLatch(1);
    DefaultPooledConnectionProvider provider = (DefaultPooledConnectionProvider) ConnectionProvider.create("testConnectionReturnedToParentPoolWhenNoActiveStreams", 5);
    AtomicInteger counter = new AtomicInteger();
    HttpClient client = createClient(provider, disposableServer.port()).wiretap(false).protocol(HttpProtocol.H2).secure(spec -> spec.sslContext(clientCtx)).observe((conn, state) -> {
        if (state == ConnectionObserver.State.CONNECTED) {
            counter.incrementAndGet();
        }
        if (state == ConnectionObserver.State.RELEASED && counter.decrementAndGet() == 0) {
            latch.countDown();
        }
    });
    try {
        Flux.range(0, requestsNum).flatMap(i -> client.post().uri("/").send(ByteBufMono.fromString(Mono.just("testConnectionReturnedToParentPoolWhenNoActiveStreams"))).responseContent().aggregate().asString()).blockLast(Duration.ofSeconds(5));
        assertThat(latch.await(5, TimeUnit.SECONDS)).isTrue();
        assertThat(provider.channelPools).hasSize(1);
        @SuppressWarnings({ "unchecked", "rawtypes" }) InstrumentedPool<DefaultPooledConnectionProvider.PooledConnection> channelPool = provider.channelPools.values().toArray(new InstrumentedPool[0])[0];
        InstrumentedPool.PoolMetrics metrics = channelPool.metrics();
        assertThat(metrics.acquiredSize()).isEqualTo(0);
        assertThat(metrics.allocatedSize()).isEqualTo(metrics.idleSize());
    } finally {
        provider.disposeLater().block(Duration.ofSeconds(5));
    }
}
Also used : Http2SslContextSpec(reactor.netty.http.Http2SslContextSpec) StepVerifier(reactor.test.StepVerifier) Http11SslContextSpec(reactor.netty.http.Http11SslContextSpec) SocketAddress(java.net.SocketAddress) PoolShutdownException(reactor.netty.internal.shaded.reactor.pool.PoolShutdownException) HttpProtocol(reactor.netty.http.HttpProtocol) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Http2SslContextSpec(reactor.netty.http.Http2SslContextSpec) BaseHttpTest(reactor.netty.BaseHttpTest) Disabled(org.junit.jupiter.api.Disabled) StringUtils(org.apache.commons.lang3.StringUtils) Nullable(reactor.util.annotation.Nullable) AtomicReference(java.util.concurrent.atomic.AtomicReference) ConcurrentMap(java.util.concurrent.ConcurrentMap) ChannelHandlerContext(io.netty.channel.ChannelHandlerContext) InsecureTrustManagerFactory(io.netty.handler.ssl.util.InsecureTrustManagerFactory) ConnectionObserver(reactor.netty.ConnectionObserver) ChannelPromise(io.netty.channel.ChannelPromise) BeforeAll(org.junit.jupiter.api.BeforeAll) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Duration(java.time.Duration) ByteBufMono(reactor.netty.ByteBufMono) DefaultChannelPromise(io.netty.channel.DefaultChannelPromise) MethodSource(org.junit.jupiter.params.provider.MethodSource) ValueSource(org.junit.jupiter.params.provider.ValueSource) ChannelOutboundHandlerAdapter(io.netty.channel.ChannelOutboundHandlerAdapter) SslContext(io.netty.handler.ssl.SslContext) SelfSignedCertificate(io.netty.handler.ssl.util.SelfSignedCertificate) InstrumentedPool(reactor.netty.internal.shaded.reactor.pool.InstrumentedPool) HttpResponseStatus(io.netty.handler.codec.http.HttpResponseStatus) Mono(reactor.core.publisher.Mono) IOException(java.io.IOException) Signal(reactor.core.publisher.Signal) CertificateException(java.security.cert.CertificateException) InetSocketAddress(java.net.InetSocketAddress) Channel(io.netty.channel.Channel) Test(org.junit.jupiter.api.Test) TimeUnit(java.util.concurrent.TimeUnit) Flux(reactor.core.publisher.Flux) CountDownLatch(java.util.concurrent.CountDownLatch) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) HttpServer(reactor.netty.http.server.HttpServer) SSLException(javax.net.ssl.SSLException) List(java.util.List) SslProvider(io.netty.handler.ssl.SslProvider) SslContextBuilder(io.netty.handler.ssl.SslContextBuilder) HttpHeaderNames(io.netty.handler.codec.http.HttpHeaderNames) HttpClient(reactor.netty.http.client.HttpClient) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) HttpClient(reactor.netty.http.client.HttpClient) InstrumentedPool(reactor.netty.internal.shaded.reactor.pool.InstrumentedPool) CountDownLatch(java.util.concurrent.CountDownLatch) BaseHttpTest(reactor.netty.BaseHttpTest) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 10 with Http2SslContextSpec

use of reactor.netty.http.Http2SslContextSpec in project reactor-netty by reactor.

the class HttpClientTest method testConnectionLifeTimeFixedPoolHttp2_1.

@Test
void testConnectionLifeTimeFixedPoolHttp2_1() throws Exception {
    Http2SslContextSpec serverCtx = Http2SslContextSpec.forServer(ssc.certificate(), ssc.privateKey());
    Http2SslContextSpec clientCtx = Http2SslContextSpec.forClient().configure(builder -> builder.trustManager(InsecureTrustManagerFactory.INSTANCE));
    ConnectionProvider provider = ConnectionProvider.builder("testConnectionLifeTimeFixedPoolHttp2_1").maxConnections(1).pendingAcquireTimeout(Duration.ofMillis(100)).maxLifeTime(Duration.ofMillis(30)).build();
    try {
        ChannelId[] ids = doTestConnectionLifeTime(createServer().protocol(HttpProtocol.H2).secure(spec -> spec.sslContext(serverCtx)), createClient(provider, () -> disposableServer.address()).protocol(HttpProtocol.H2).secure(spec -> spec.sslContext(clientCtx)));
        assertThat(ids[0]).isNotEqualTo(ids[1]);
    } finally {
        provider.disposeLater().block(Duration.ofSeconds(5));
    }
}
Also used : Http2SslContextSpec(reactor.netty.http.Http2SslContextSpec) Arrays(java.util.Arrays) HttpHeaders(io.netty.handler.codec.http.HttpHeaders) StepVerifier(reactor.test.StepVerifier) DefaultChannelGroup(io.netty.channel.group.DefaultChannelGroup) Tuples(reactor.util.function.Tuples) Disabled(org.junit.jupiter.api.Disabled) HttpClientCodec(io.netty.handler.codec.http.HttpClientCodec) HttpResources(reactor.netty.http.HttpResources) TcpClient(reactor.netty.tcp.TcpClient) Future(java.util.concurrent.Future) Loggers(reactor.util.Loggers) DomainSocketAddress(io.netty.channel.unix.DomainSocketAddress) BeforeAll(org.junit.jupiter.api.BeforeAll) Duration(java.time.Duration) CharsetUtil(io.netty.util.CharsetUtil) Path(java.nio.file.Path) LoopResources(reactor.netty.resources.LoopResources) HttpObjectDecoder(io.netty.handler.codec.http.HttpObjectDecoder) Context(reactor.util.context.Context) Set(java.util.Set) ConnectionPoolMetrics(reactor.netty.resources.ConnectionPoolMetrics) StandardCharsets(java.nio.charset.StandardCharsets) Executors(java.util.concurrent.Executors) CountDownLatch(java.util.concurrent.CountDownLatch) SSLException(javax.net.ssl.SSLException) AddressResolverGroup(io.netty.resolver.AddressResolverGroup) HttpServer(reactor.netty.http.server.HttpServer) LogLevel(io.netty.handler.logging.LogLevel) DefaultFullHttpResponse(io.netty.handler.codec.http.DefaultFullHttpResponse) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) SocketUtils(reactor.netty.SocketUtils) HttpProtocol(reactor.netty.http.HttpProtocol) Nullable(reactor.util.annotation.Nullable) ArrayList(java.util.ArrayList) InsecureTrustManagerFactory(io.netty.handler.ssl.util.InsecureTrustManagerFactory) SslProvider(reactor.netty.tcp.SslProvider) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) Assertions.assertThatExceptionOfType(org.assertj.core.api.Assertions.assertThatExceptionOfType) SslContext(io.netty.handler.ssl.SslContext) Files(java.nio.file.Files) Publisher(org.reactivestreams.Publisher) IOException(java.io.IOException) Mono(reactor.core.publisher.Mono) Field(java.lang.reflect.Field) Channel(io.netty.channel.Channel) AtomicLong(java.util.concurrent.atomic.AtomicLong) DefaultEventExecutor(io.netty.util.concurrent.DefaultEventExecutor) Flux(reactor.core.publisher.Flux) FutureMono(reactor.netty.FutureMono) Paths(java.nio.file.Paths) SslContextBuilder(io.netty.handler.ssl.SslContextBuilder) HttpHeaderNames(io.netty.handler.codec.http.HttpHeaderNames) ConnectionProvider(reactor.netty.resources.ConnectionProvider) DnsAddressResolverGroup(io.netty.resolver.dns.DnsAddressResolverGroup) Sinks(reactor.core.publisher.Sinks) SocketAddress(java.net.SocketAddress) Http11SslContextSpec(reactor.netty.http.Http11SslContextSpec) ByteBufAllocator(io.netty.buffer.ByteBufAllocator) URISyntaxException(java.net.URISyntaxException) BiFunction(java.util.function.BiFunction) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) ChannelId(io.netty.channel.ChannelId) Http2SslContextSpec(reactor.netty.http.Http2SslContextSpec) TimeoutException(java.util.concurrent.TimeoutException) BaseHttpTest(reactor.netty.BaseHttpTest) ByteBuffer(java.nio.ByteBuffer) Unpooled(io.netty.buffer.Unpooled) TransportConfig(reactor.netty.transport.TransportConfig) SocketChannel(java.nio.channels.SocketChannel) HttpResponseEncoder(io.netty.handler.codec.http.HttpResponseEncoder) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ByteBufFlux(reactor.netty.ByteBufFlux) NettyPipeline(reactor.netty.NettyPipeline) Logger(reactor.util.Logger) ByteBufMono(reactor.netty.ByteBufMono) URI(java.net.URI) ChannelDuplexHandler(io.netty.channel.ChannelDuplexHandler) ChannelGroup(io.netty.channel.group.ChannelGroup) ReadTimeoutHandler(io.netty.handler.timeout.ReadTimeoutHandler) StandardOpenOption(java.nio.file.StandardOpenOption) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HttpResponseStatus(io.netty.handler.codec.http.HttpResponseStatus) InetSocketAddress(java.net.InetSocketAddress) NioEventLoopGroup(io.netty.channel.nio.NioEventLoopGroup) Objects(java.util.Objects) Test(org.junit.jupiter.api.Test) List(java.util.List) HttpVersion(io.netty.handler.codec.http.HttpVersion) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Tuple2(reactor.util.function.Tuple2) AtomicReference(java.util.concurrent.atomic.AtomicReference) Function(java.util.function.Function) Queues(reactor.util.concurrent.Queues) Charset(java.nio.charset.Charset) ByteBuf(io.netty.buffer.ByteBuf) Connection(reactor.netty.Connection) ExecutorService(java.util.concurrent.ExecutorService) HttpHeaderValues(io.netty.handler.codec.http.HttpHeaderValues) SelfSignedCertificate(io.netty.handler.ssl.util.SelfSignedCertificate) HttpMethod(io.netty.handler.codec.http.HttpMethod) CertificateException(java.security.cert.CertificateException) ServerSocketChannel(java.nio.channels.ServerSocketChannel) TimeUnit(java.util.concurrent.TimeUnit) Consumer(java.util.function.Consumer) ConcurrentSkipListSet(java.util.concurrent.ConcurrentSkipListSet) TcpServer(reactor.netty.tcp.TcpServer) ChannelHandler(io.netty.channel.ChannelHandler) HttpContentDecompressor(io.netty.handler.codec.http.HttpContentDecompressor) ChannelId(io.netty.channel.ChannelId) ConnectionProvider(reactor.netty.resources.ConnectionProvider) BaseHttpTest(reactor.netty.BaseHttpTest) Test(org.junit.jupiter.api.Test)

Aggregations

Http2SslContextSpec (reactor.netty.http.Http2SslContextSpec)32 SelfSignedCertificate (io.netty.handler.ssl.util.SelfSignedCertificate)27 Test (org.junit.jupiter.api.Test)27 HttpProtocol (reactor.netty.http.HttpProtocol)27 InsecureTrustManagerFactory (io.netty.handler.ssl.util.InsecureTrustManagerFactory)26 Duration (java.time.Duration)26 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)26 Mono (reactor.core.publisher.Mono)26 BaseHttpTest (reactor.netty.BaseHttpTest)26 CertificateException (java.security.cert.CertificateException)25 BeforeAll (org.junit.jupiter.api.BeforeAll)25 List (java.util.List)24 TimeUnit (java.util.concurrent.TimeUnit)24 Flux (reactor.core.publisher.Flux)24 Http11SslContextSpec (reactor.netty.http.Http11SslContextSpec)24 Channel (io.netty.channel.Channel)22 HttpHeaderNames (io.netty.handler.codec.http.HttpHeaderNames)22 HttpResponseStatus (io.netty.handler.codec.http.HttpResponseStatus)22 SocketAddress (java.net.SocketAddress)22 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)22