use of org.apache.http.impl.conn.PoolingHttpClientConnectionManager in project tutorials by eugenp.
the class HttpClientConnectionManagementLiveTest method whenHttpClientChecksStaleConns_thenNoExceptions.
// 8
@Test
public final // 8.1
void whenHttpClientChecksStaleConns_thenNoExceptions() {
poolingConnManager = new PoolingHttpClientConnectionManager();
client = HttpClients.custom().setDefaultRequestConfig(RequestConfig.custom().setStaleConnectionCheckEnabled(true).build()).setConnectionManager(poolingConnManager).build();
}
use of org.apache.http.impl.conn.PoolingHttpClientConnectionManager in project tutorials by eugenp.
the class HttpClientConnectionManagementLiveTest method whenClosingConnectionsandManager_thenCloseWithNoExceptions1.
// 9
@Test(expected = IllegalStateException.class)
public final // 9.1
void whenClosingConnectionsandManager_thenCloseWithNoExceptions1() throws InterruptedException, ExecutionException, IOException, HttpException {
poolingConnManager = new PoolingHttpClientConnectionManager();
client = HttpClients.custom().setConnectionManager(poolingConnManager).build();
final HttpGet get = new HttpGet("http://google.com");
response = client.execute(get);
EntityUtils.consume(response.getEntity());
response.close();
client.close();
poolingConnManager.close();
poolingConnManager.shutdown();
client.execute(get);
assertTrue(response.getEntity() == null);
}
use of org.apache.http.impl.conn.PoolingHttpClientConnectionManager in project tutorials by eugenp.
the class HttpClientConnectionManagementLiveTest method whenCustomizedIdleConnMonitor_thenEliminateIdleConns.
@Test
@Ignore("Very Long Running")
public final /*tester*/
void whenCustomizedIdleConnMonitor_thenEliminateIdleConns() throws InterruptedException, IOException {
poolingConnManager = new PoolingHttpClientConnectionManager();
client = HttpClients.custom().setConnectionManager(poolingConnManager).build();
final IdleConnectionMonitorThread staleMonitor = new IdleConnectionMonitorThread(poolingConnManager);
final HttpGet get = new HttpGet("http://google.com");
// test this with new HttpGet("http://iotechperu.com")----First test will fail b/c there is redirect connection at that site
final TesterVersion_MultiHttpClientConnThread thread1 = new TesterVersion_MultiHttpClientConnThread(client, get, poolingConnManager);
final TesterVersion_MultiHttpClientConnThread thread2 = new TesterVersion_MultiHttpClientConnThread(client, get, poolingConnManager);
final TesterVersion_MultiHttpClientConnThread thread3 = new TesterVersion_MultiHttpClientConnThread(client, get, poolingConnManager);
staleMonitor.start();
thread1.start();
thread1.join();
thread2.start();
thread2.join();
thread3.start();
assertTrue(poolingConnManager.getTotalStats().getAvailable() == 1);
thread3.join(32000);
assertTrue(poolingConnManager.getTotalStats().getAvailable() == 0);
}
use of org.apache.http.impl.conn.PoolingHttpClientConnectionManager in project tutorials by eugenp.
the class HttpClientConnectionManagementLiveTest method whenConfiguringTimeOut_thenNoExceptions.
// 7
@Test
public final // 7.1
void whenConfiguringTimeOut_thenNoExceptions() {
route = new HttpRoute(new HttpHost("localhost", 80));
poolingConnManager = new PoolingHttpClientConnectionManager();
poolingConnManager.setSocketConfig(route.getTargetHost(), SocketConfig.custom().setSoTimeout(5000).build());
assertTrue(poolingConnManager.getSocketConfig(route.getTargetHost()).getSoTimeout() == 5000);
}
use of org.apache.http.impl.conn.PoolingHttpClientConnectionManager in project tutorials by eugenp.
the class HttpClientConnectionManagementLiveTest method whenConnectionsNeededGreaterThanMaxTotal_thenLeaseMasTotalandReuse.
@Test
public final // @Ignore
void whenConnectionsNeededGreaterThanMaxTotal_thenLeaseMasTotalandReuse() throws InterruptedException {
final HttpGet get = new HttpGet("http://echo.200please.com");
poolingConnManager = new PoolingHttpClientConnectionManager();
poolingConnManager.setDefaultMaxPerRoute(5);
poolingConnManager.setMaxTotal(5);
client = HttpClients.custom().setConnectionManager(poolingConnManager).build();
final MultiHttpClientConnThread[] threads = new MultiHttpClientConnThread[10];
for (int i = 0; i < threads.length; i++) {
threads[i] = new MultiHttpClientConnThread(client, get, poolingConnManager);
}
for (final MultiHttpClientConnThread thread : threads) {
thread.start();
}
for (final MultiHttpClientConnThread thread : threads) {
thread.join(10000);
}
}
Aggregations