Search in sources :

Example 1 with LoopResources

use of reactor.netty.resources.LoopResources in project spring-framework by spring-projects.

the class ReactorResourceFactoryTests method localResourcesViaSupplier.

@Test
void localResourcesViaSupplier() throws Exception {
    this.resourceFactory.setUseGlobalResources(false);
    this.resourceFactory.setConnectionProviderSupplier(() -> this.connectionProvider);
    this.resourceFactory.setLoopResourcesSupplier(() -> this.loopResources);
    this.resourceFactory.afterPropertiesSet();
    ConnectionProvider connectionProvider = this.resourceFactory.getConnectionProvider();
    LoopResources loopResources = this.resourceFactory.getLoopResources();
    assertThat(connectionProvider).isSameAs(this.connectionProvider);
    assertThat(loopResources).isSameAs(this.loopResources);
    verifyNoMoreInteractions(this.connectionProvider, this.loopResources);
    this.resourceFactory.destroy();
    // Managed (destroy disposes)..
    verify(this.connectionProvider).disposeLater();
    verify(this.loopResources).disposeLater(eq(Duration.ofSeconds(LoopResources.DEFAULT_SHUTDOWN_QUIET_PERIOD)), eq(Duration.ofSeconds(LoopResources.DEFAULT_SHUTDOWN_TIMEOUT)));
    verifyNoMoreInteractions(this.connectionProvider, this.loopResources);
}
Also used : LoopResources(reactor.netty.resources.LoopResources) ConnectionProvider(reactor.netty.resources.ConnectionProvider) Test(org.junit.jupiter.api.Test)

Example 2 with LoopResources

use of reactor.netty.resources.LoopResources in project spring-framework by spring-projects.

the class ReactorResourceFactoryTests method localResources.

@Test
void localResources() throws Exception {
    this.resourceFactory.setUseGlobalResources(false);
    this.resourceFactory.afterPropertiesSet();
    ConnectionProvider connectionProvider = this.resourceFactory.getConnectionProvider();
    LoopResources loopResources = this.resourceFactory.getLoopResources();
    assertThat(connectionProvider).isNotSameAs(HttpResources.get());
    assertThat(loopResources).isNotSameAs(HttpResources.get());
    // The below does not work since ConnectionPoolProvider simply checks if pool is empty.
    // assertFalse(connectionProvider.isDisposed());
    assertThat(loopResources.isDisposed()).isFalse();
    this.resourceFactory.destroy();
    assertThat(connectionProvider.isDisposed()).isTrue();
    assertThat(loopResources.isDisposed()).isTrue();
}
Also used : LoopResources(reactor.netty.resources.LoopResources) ConnectionProvider(reactor.netty.resources.ConnectionProvider) Test(org.junit.jupiter.api.Test)

Example 3 with LoopResources

use of reactor.netty.resources.LoopResources in project spring-framework by spring-projects.

the class ReactorResourceFactoryTests method externalResources.

@Test
void externalResources() throws Exception {
    this.resourceFactory.setUseGlobalResources(false);
    this.resourceFactory.setConnectionProvider(this.connectionProvider);
    this.resourceFactory.setLoopResources(this.loopResources);
    this.resourceFactory.afterPropertiesSet();
    ConnectionProvider connectionProvider = this.resourceFactory.getConnectionProvider();
    LoopResources loopResources = this.resourceFactory.getLoopResources();
    assertThat(connectionProvider).isSameAs(this.connectionProvider);
    assertThat(loopResources).isSameAs(this.loopResources);
    verifyNoMoreInteractions(this.connectionProvider, this.loopResources);
    this.resourceFactory.destroy();
    // Not managed (destroy has no impact)..
    verifyNoMoreInteractions(this.connectionProvider, this.loopResources);
}
Also used : LoopResources(reactor.netty.resources.LoopResources) ConnectionProvider(reactor.netty.resources.ConnectionProvider) Test(org.junit.jupiter.api.Test)

Example 4 with LoopResources

use of reactor.netty.resources.LoopResources in project spring-boot by spring-projects.

the class NettyReactiveWebServerFactory method createHttpServer.

private HttpServer createHttpServer() {
    HttpServer server = HttpServer.create();
    if (this.resourceFactory != null) {
        LoopResources resources = this.resourceFactory.getLoopResources();
        Assert.notNull(resources, "No LoopResources: is ReactorResourceFactory not initialized yet?");
        server = server.runOn(resources).bindAddress(this::getListenAddress);
    } else {
        server = server.bindAddress(this::getListenAddress);
    }
    if (getSsl() != null && getSsl().isEnabled()) {
        server = customizeSslConfiguration(server);
    }
    if (getCompression() != null && getCompression().getEnabled()) {
        CompressionCustomizer compressionCustomizer = new CompressionCustomizer(getCompression());
        server = compressionCustomizer.apply(server);
    }
    server = server.protocol(listProtocols()).forwarded(this.useForwardHeaders);
    return applyCustomizers(server);
}
Also used : LoopResources(reactor.netty.resources.LoopResources) HttpServer(reactor.netty.http.server.HttpServer)

Aggregations

LoopResources (reactor.netty.resources.LoopResources)4 Test (org.junit.jupiter.api.Test)3 ConnectionProvider (reactor.netty.resources.ConnectionProvider)3 HttpServer (reactor.netty.http.server.HttpServer)1