@Test public 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(); assertSame(this.connectionProvider, connectionProvider); assertSame(this.loopResources, loopResources); verifyNoMoreInteractions(this.connectionProvider, this.loopResources); this.resourceFactory.destroy(); // Not managed (destroy has no impact).. verifyNoMoreInteractions(this.connectionProvider, this.loopResources); }
@Test public void globalResourcesWithConsumer() throws Exception { AtomicBoolean invoked = new AtomicBoolean(false); this.resourceFactory.addGlobalResourcesConsumer(httpResources -> invoked.set(true)); this.resourceFactory.afterPropertiesSet(); assertTrue(invoked.get()); this.resourceFactory.destroy(); }
private static HttpClient initHttpClient(ReactorResourceFactory resourceFactory) { ConnectionProvider provider = resourceFactory.getConnectionProvider(); LoopResources resources = resourceFactory.getLoopResources(); Assert.notNull(provider, "No ConnectionProvider: is ReactorResourceFactory not initialized yet?"); Assert.notNull(resources, "No LoopResources: is ReactorResourceFactory not initialized yet?"); return HttpClient.create(provider).tcpConfiguration(tcpClient -> tcpClient.runOn(resources)); }
@Test public 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(); assertSame(this.connectionProvider, connectionProvider); assertSame(this.loopResources, loopResources); verifyNoMoreInteractions(this.connectionProvider, this.loopResources); this.resourceFactory.destroy(); // Managed (destroy disposes).. verify(this.connectionProvider).dispose(); verify(this.loopResources).dispose(); verifyNoMoreInteractions(this.connectionProvider, this.loopResources); }
@Test public void globalResources() throws Exception { this.resourceFactory.setUseGlobalResources(true); this.resourceFactory.afterPropertiesSet(); HttpResources globalResources = HttpResources.get(); assertSame(globalResources, this.resourceFactory.getConnectionProvider()); assertSame(globalResources, this.resourceFactory.getLoopResources()); assertFalse(globalResources.isDisposed()); this.resourceFactory.destroy(); assertTrue(globalResources.isDisposed()); }
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.tcpConfiguration((tcpServer) -> tcpServer.runOn(resources) .addressSupplier(this::getListenAddress)); } else { server = server.tcpConfiguration( (tcpServer) -> tcpServer.addressSupplier(this::getListenAddress)); } if (getSsl() != null && getSsl().isEnabled()) { SslServerCustomizer sslServerCustomizer = new SslServerCustomizer(getSsl(), getHttp2(), getSslStoreProvider()); server = sslServerCustomizer.apply(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); }
@Before public void setUp() { this.factory = new ReactorResourceFactory(); this.factory.afterPropertiesSet(); this.server = new MockWebServer(); this.webClient = WebClient .builder() .clientConnector(initConnector()) .baseUrl(this.server.url("/").toString()) .build(); }
@After public void shutDown() throws InterruptedException { waitForDataBufferRelease(Duration.ofSeconds(2)); this.factory.destroy(); }
@Test public void localResources() throws Exception { this.resourceFactory.setUseGlobalResources(false); this.resourceFactory.afterPropertiesSet(); ConnectionProvider connectionProvider = this.resourceFactory.getConnectionProvider(); LoopResources loopResources = this.resourceFactory.getLoopResources(); assertNotSame(HttpResources.get(), connectionProvider); assertNotSame(HttpResources.get(), loopResources); // The below does not work since ConnectionPoolProvider simply checks if pool is empty. // assertFalse(connectionProvider.isDisposed()); assertFalse(loopResources.isDisposed()); this.resourceFactory.destroy(); assertTrue(connectionProvider.isDisposed()); assertTrue(loopResources.isDisposed()); }
private static HttpClient initHttpClient(ReactorResourceFactory resourceFactory) { ConnectionProvider provider = resourceFactory.getConnectionProvider(); LoopResources resources = resourceFactory.getLoopResources(); Assert.notNull(provider, "No ConnectionProvider: is ReactorResourceFactory not initialized yet?"); Assert.notNull(resources, "No LoopResources: is ReactorResourceFactory not initialized yet?"); return HttpClient.create(provider).tcpConfiguration(tcpClient -> tcpClient.runOn(resources)); }
private static HttpClient initHttpClient(ReactorResourceFactory resourceFactory) { ConnectionProvider provider = resourceFactory.getConnectionProvider(); LoopResources resources = resourceFactory.getLoopResources(); Assert.notNull(provider, "No ConnectionProvider: is ReactorResourceFactory not initialized yet?"); Assert.notNull(resources, "No LoopResources: is ReactorResourceFactory not initialized yet?"); return HttpClient.create(provider).tcpConfiguration(tcpClient -> tcpClient.runOn(resources)); }