@Test @DisplayName("Keep alive doesn't prevent a connection from being used for a different route") public void test1() throws IOException, InterruptedException { connMgr.setDefaultMaxPerRoute(5); connMgr.setMaxTotal(5); CloseableHttpClient httpClient = HttpClients.custom() .setConnectionManager(connMgr) .setDefaultRequestConfig(requestConfig) .setKeepAliveStrategy((response, context) -> 10000l) .build(); StepVerifier.create(Flux.range(1, 5) .parallel(10) .runOn(Schedulers.parallel()) .map(i -> "https: .flatMap(uri -> Mono.fromCallable(new HttpHeadTask(httpClient, uri)) .delayElement(Duration.ofMillis(3000l)))) .recordWith(ArrayList::new) .expectNextCount(5) .consumeRecordedWith(results -> assertThat(results) .hasSize(5) .allSatisfy(verifier)) .verifyComplete(); HttpHeadTask headFromYahooTask = new HttpHeadTask(httpClient, "https: assertThat(headFromYahooTask.call()).isEqualTo("www.yahoo.com"); httpClient.close(); }
@Override public String call() { CloseableHttpResponse response = null; try { response = httpClient.execute(httpHead, context); response.getEntity(); log.info("Successfully received response from: {}.", httpHead.getURI().getHost()); return httpHead.getURI().getHost(); } catch (IOException ex) { log.error("Something bad happened while getting from: {}.", ex, httpHead.getURI().getHost()); return ""; } finally { if (response != null) { try { response.close(); } catch (IOException e) { log.error("Failed to close response: {}.", e, httpHead.getURI().getHost()); } } } }
HttpHeadTask implements Callable<String> { @Override public String call() { CloseableHttpResponse response = null; try { response = httpClient.execute(httpHead, context); response.getEntity(); log.info("Successfully received response from: {}.", httpHead.getURI().getHost()); return httpHead.getURI().getHost(); } catch (IOException ex) { log.error("Something bad happened while getting from: {}.", ex, httpHead.getURI().getHost()); return ""; } finally { if (response != null) { try { response.close(); } catch (IOException e) { log.error("Failed to close response: {}.", e, httpHead.getURI().getHost()); } } } } }
HttpHeadTask implements Callable<String> { @Override public String call() { CloseableHttpResponse response = null; try { response = httpClient.execute(httpHead, context); response.getEntity(); log.info("Successfully received response from: {}.", httpHead.getURI().getHost()); return httpHead.getURI().getHost(); } catch (IOException ex) { log.error("Something bad happened while getting from: {}.", ex, httpHead.getURI().getHost()); return ""; } finally { if (response != null) { try { response.close(); } catch (IOException e) { log.error("Failed to close response: {}.", e, httpHead.getURI().getHost()); } } } } HttpHeadTask(CloseableHttpClient httpClient, String uri); }
HttpHeadTask implements Callable<String> { @Override public String call() { CloseableHttpResponse response = null; try { response = httpClient.execute(httpHead, context); response.getEntity(); log.info("Successfully received response from: {}.", httpHead.getURI().getHost()); return httpHead.getURI().getHost(); } catch (IOException ex) { log.error("Something bad happened while getting from: {}.", ex, httpHead.getURI().getHost()); return ""; } finally { if (response != null) { try { response.close(); } catch (IOException e) { log.error("Failed to close response: {}.", e, httpHead.getURI().getHost()); } } } } HttpHeadTask(CloseableHttpClient httpClient, String uri); @Override String call(); }
HttpHeadTask implements Callable<String> { @Override public String call() { CloseableHttpResponse response = null; try { response = httpClient.execute(httpHead, context); response.getEntity(); log.info("Successfully received response from: {}.", httpHead.getURI().getHost()); return httpHead.getURI().getHost(); } catch (IOException ex) { log.error("Something bad happened while getting from: {}.", ex, httpHead.getURI().getHost()); return ""; } finally { if (response != null) { try { response.close(); } catch (IOException e) { log.error("Failed to close response: {}.", e, httpHead.getURI().getHost()); } } } } HttpHeadTask(CloseableHttpClient httpClient, String uri); @Override String call();  }