Search in sources :

Example 6 with PoolResources

use of reactor.ipc.netty.resources.PoolResources in project reactor-netty by reactor.

the class WebsocketTest method closePool.

@Test
public void closePool() {
    PoolResources pr = PoolResources.fixed("wstest", 1);
    NettyContext httpServer = HttpServer.create(0).newHandler((in, out) -> out.sendWebsocket((i, o) -> o.options(opt -> opt.flushOnEach()).sendString(Mono.just("test").delayElement(Duration.ofMillis(100)).repeat()))).block(Duration.ofSeconds(30));
    Flux<String> ws = HttpClient.create(opts -> opts.port(httpServer.address().getPort()).poolResources(pr)).ws("/").flatMapMany(in -> in.receiveWebsocket().aggregateFrames().receive().asString());
    StepVerifier.create(Flux.range(1, 10).concatMap(i -> ws.take(2).log())).expectNextSequence(Flux.range(1, 20).map(v -> "test").toIterable()).expectComplete().verify();
    httpServer.dispose();
    pr.dispose();
}
Also used : CoreMatchers.is(org.hamcrest.CoreMatchers.is) StepVerifier(reactor.test.StepVerifier) Test(org.junit.Test) FluxProcessor(reactor.core.publisher.FluxProcessor) Mono(reactor.core.publisher.Mono) WebSocketHandshakeException(io.netty.handler.codec.http.websocketx.WebSocketHandshakeException) PoolResources(reactor.ipc.netty.resources.PoolResources) AtomicReference(java.util.concurrent.atomic.AtomicReference) ReplayProcessor(reactor.core.publisher.ReplayProcessor) TimeUnit(java.util.concurrent.TimeUnit) CountDownLatch(java.util.concurrent.CountDownLatch) Flux(reactor.core.publisher.Flux) Duration(java.time.Duration) After(org.junit.After) NettyContext(reactor.ipc.netty.NettyContext) Assert(org.junit.Assert) HttpServer(reactor.ipc.netty.http.server.HttpServer) PoolResources(reactor.ipc.netty.resources.PoolResources) NettyContext(reactor.ipc.netty.NettyContext) Test(org.junit.Test)

Example 7 with PoolResources

use of reactor.ipc.netty.resources.PoolResources in project cf-java-client by cloudfoundry.

the class _DefaultConnectionContext method dispose.

/**
 * Disposes resources created to service this connection context
 */
@PreDestroy
public final void dispose() {
    getConnectionPool().ifPresent(PoolResources::dispose);
    getThreadPool().dispose();
    try {
        ObjectName name = getByteBufAllocatorObjectName();
        if (ManagementFactory.getPlatformMBeanServer().isRegistered(name)) {
            ManagementFactory.getPlatformMBeanServer().unregisterMBean(name);
        }
    } catch (JMException e) {
        this.logger.error("Unable to register ByteBufAllocator MBean", e);
    }
}
Also used : PoolResources(reactor.ipc.netty.resources.PoolResources) JMException(javax.management.JMException) ObjectName(javax.management.ObjectName) PreDestroy(javax.annotation.PreDestroy)

Example 8 with PoolResources

use of reactor.ipc.netty.resources.PoolResources in project spring-cloud-gateway by spring-cloud.

the class GatewayAutoConfigurationTests method nettyHttpClientDefaults.

@Test
public void nettyHttpClientDefaults() {
    new ReactiveWebApplicationContextRunner().withConfiguration(AutoConfigurations.of(WebFluxAutoConfiguration.class, GatewayAutoConfiguration.class)).withPropertyValues("debug=true").run(context -> {
        assertThat(context).hasSingleBean(HttpClient.class);
        HttpClient httpClient = context.getBean(HttpClient.class);
        HttpClientOptions options = httpClient.options();
        PoolResources poolResources = options.getPoolResources();
        assertThat(poolResources).isNotNull();
        // TODO: howto test PoolResources
        ClientProxyOptions proxyOptions = options.getProxyOptions();
        assertThat(proxyOptions).isNull();
        SslContext sslContext = options.sslContext();
        assertThat(sslContext).isNull();
    });
}
Also used : WebFluxAutoConfiguration(org.springframework.boot.autoconfigure.web.reactive.WebFluxAutoConfiguration) PoolResources(reactor.ipc.netty.resources.PoolResources) ClientProxyOptions(reactor.ipc.netty.options.ClientProxyOptions) HttpClient(reactor.ipc.netty.http.client.HttpClient) HttpClientOptions(reactor.ipc.netty.http.client.HttpClientOptions) ReactiveWebApplicationContextRunner(org.springframework.boot.test.context.runner.ReactiveWebApplicationContextRunner) SslContext(io.netty.handler.ssl.SslContext) Test(org.junit.Test)

Example 9 with PoolResources

use of reactor.ipc.netty.resources.PoolResources in project spring-cloud-gateway by spring-cloud.

the class GatewayAutoConfigurationTests method nettyHttpClientConfigured.

@Test
public void nettyHttpClientConfigured() {
    new ReactiveWebApplicationContextRunner().withConfiguration(AutoConfigurations.of(WebFluxAutoConfiguration.class, GatewayAutoConfiguration.class)).withPropertyValues("spring.cloud.gateway.httpclient.ssl.use-insecure-trust-manager=true", "spring.cloud.gateway.httpclient.pool.type=fixed", "spring.cloud.gateway.httpclient.proxy.host=myhost").run(context -> {
        assertThat(context).hasSingleBean(HttpClient.class);
        HttpClient httpClient = context.getBean(HttpClient.class);
        HttpClientOptions options = httpClient.options();
        PoolResources poolResources = options.getPoolResources();
        assertThat(poolResources).isNotNull();
        // TODO: howto test PoolResources
        ClientProxyOptions proxyOptions = options.getProxyOptions();
        assertThat(proxyOptions).isNotNull();
        assertThat(proxyOptions.getAddress().get().getHostName()).isEqualTo("myhost");
        SslContext sslContext = options.sslContext();
        assertThat(sslContext).isNotNull();
    // TODO: howto test SslContext
    });
}
Also used : WebFluxAutoConfiguration(org.springframework.boot.autoconfigure.web.reactive.WebFluxAutoConfiguration) PoolResources(reactor.ipc.netty.resources.PoolResources) ClientProxyOptions(reactor.ipc.netty.options.ClientProxyOptions) HttpClient(reactor.ipc.netty.http.client.HttpClient) HttpClientOptions(reactor.ipc.netty.http.client.HttpClientOptions) ReactiveWebApplicationContextRunner(org.springframework.boot.test.context.runner.ReactiveWebApplicationContextRunner) SslContext(io.netty.handler.ssl.SslContext) Test(org.junit.Test)

Example 10 with PoolResources

use of reactor.ipc.netty.resources.PoolResources in project reactor-netty by reactor.

the class HttpServerTests method testIssue186.

@Test
public void testIssue186() {
    NettyContext server = HttpServer.create(0).newHandler((req, res) -> res.status(200).send()).block(Duration.ofSeconds(300));
    HttpClient client = HttpClient.create(ops -> ops.connectAddress(() -> server.address()).poolResources(PoolResources.fixed("test", 1)));
    try {
        doTestIssue186(client);
        doTestIssue186(client);
    } finally {
        server.dispose();
    }
}
Also used : HttpResources(reactor.ipc.netty.http.HttpResources) HttpHeaders(io.netty.handler.codec.http.HttpHeaders) StepVerifier(reactor.test.StepVerifier) DefaultFullHttpRequest(io.netty.handler.codec.http.DefaultFullHttpRequest) ByteBufAllocator(io.netty.buffer.ByteBufAllocator) URISyntaxException(java.net.URISyntaxException) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) TimeoutException(java.util.concurrent.TimeoutException) NettyOutbound(reactor.ipc.netty.NettyOutbound) ByteBuffer(java.nio.ByteBuffer) Unpooled(io.netty.buffer.Unpooled) HttpClientCodec(io.netty.handler.codec.http.HttpClientCodec) BlockingNettyContext(reactor.ipc.netty.tcp.BlockingNettyContext) Future(java.util.concurrent.Future) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Duration(java.time.Duration) Path(java.nio.file.Path) Context(reactor.util.context.Context) StandardOpenOption(java.nio.file.StandardOpenOption) HttpResponseStatus(io.netty.handler.codec.http.HttpResponseStatus) FileSystem(java.nio.file.FileSystem) InetSocketAddress(java.net.InetSocketAddress) HttpClientResponse(reactor.ipc.netty.http.client.HttpClientResponse) StandardCharsets(java.nio.charset.StandardCharsets) Executors(java.util.concurrent.Executors) CountDownLatch(java.util.concurrent.CountDownLatch) SSLException(javax.net.ssl.SSLException) LineBasedFrameDecoder(io.netty.handler.codec.LineBasedFrameDecoder) ByteBufFlux(reactor.ipc.netty.ByteBufFlux) HttpVersion(io.netty.handler.codec.http.HttpVersion) FluxSink(reactor.core.publisher.FluxSink) Tuple3(reactor.util.function.Tuple3) Tuple2(reactor.util.function.Tuple2) AsynchronousFileChannel(java.nio.channels.AsynchronousFileChannel) AtomicReference(java.util.concurrent.atomic.AtomicReference) Function(java.util.function.Function) StandardCopyOption(java.nio.file.StandardCopyOption) InsecureTrustManagerFactory(io.netty.handler.ssl.util.InsecureTrustManagerFactory) ByteBuf(io.netty.buffer.ByteBuf) Assert(org.testng.Assert) HttpClient(reactor.ipc.netty.http.client.HttpClient) Assertions.assertThatExceptionOfType(org.assertj.core.api.Assertions.assertThatExceptionOfType) ExecutorService(java.util.concurrent.ExecutorService) TcpClient(reactor.ipc.netty.tcp.TcpClient) SslContext(io.netty.handler.ssl.SslContext) Files(java.nio.file.Files) SelfSignedCertificate(io.netty.handler.ssl.util.SelfSignedCertificate) FutureMono(reactor.ipc.netty.FutureMono) CompletionHandler(java.nio.channels.CompletionHandler) HttpMethod(io.netty.handler.codec.http.HttpMethod) IOException(java.io.IOException) Test(org.junit.Test) Mono(reactor.core.publisher.Mono) CertificateException(java.security.cert.CertificateException) PoolResources(reactor.ipc.netty.resources.PoolResources) TimeUnit(java.util.concurrent.TimeUnit) Consumer(java.util.function.Consumer) DefaultHttpContent(io.netty.handler.codec.http.DefaultHttpContent) AtomicLong(java.util.concurrent.atomic.AtomicLong) Flux(reactor.core.publisher.Flux) Paths(java.nio.file.Paths) NettyContext(reactor.ipc.netty.NettyContext) SslContextBuilder(io.netty.handler.ssl.SslContextBuilder) HttpHeaderNames(io.netty.handler.codec.http.HttpHeaderNames) FileSystems(java.nio.file.FileSystems) HttpClient(reactor.ipc.netty.http.client.HttpClient) BlockingNettyContext(reactor.ipc.netty.tcp.BlockingNettyContext) NettyContext(reactor.ipc.netty.NettyContext) Test(org.junit.Test)

Aggregations

PoolResources (reactor.ipc.netty.resources.PoolResources)21 Test (org.junit.Test)18 Mono (reactor.core.publisher.Mono)17 Duration (java.time.Duration)16 Flux (reactor.core.publisher.Flux)15 NettyContext (reactor.ipc.netty.NettyContext)15 InetSocketAddress (java.net.InetSocketAddress)14 CountDownLatch (java.util.concurrent.CountDownLatch)14 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)12 StepVerifier (reactor.test.StepVerifier)12 SslContext (io.netty.handler.ssl.SslContext)11 HttpHeaderNames (io.netty.handler.codec.http.HttpHeaderNames)10 AtomicReference (java.util.concurrent.atomic.AtomicReference)10 FutureMono (reactor.ipc.netty.FutureMono)10 HttpServer (reactor.ipc.netty.http.server.HttpServer)10 Unpooled (io.netty.buffer.Unpooled)9 HttpResponseStatus (io.netty.handler.codec.http.HttpResponseStatus)9 HttpVersion (io.netty.handler.codec.http.HttpVersion)9 SslContextBuilder (io.netty.handler.ssl.SslContextBuilder)9 InsecureTrustManagerFactory (io.netty.handler.ssl.util.InsecureTrustManagerFactory)9