List of usage examples for com.squareup.okhttp ConnectionPool evictAll
public void evictAll()
From source file:com.frostwire.android.gui.services.EngineService.java
License:Open Source License
private void stopOkHttp() { ConnectionPool pool = ConnectionPool.getDefault(); try {/*from w ww . j a va2 s . c o m*/ pool.evictAll(); } catch (Throwable e) { e.printStackTrace(); } try { synchronized (pool) { pool.notifyAll(); } } catch (Throwable e) { e.printStackTrace(); } }
From source file:com.raskasa.metrics.okhttp.InstrumentedOkHttpClientTest.java
License:Apache License
@Test public void connectionPoolIsInstrumented() throws Exception { server.enqueue(new MockResponse().setBody("one")); server.enqueue(new MockResponse().setBody("two")); HttpUrl baseUrl = server.url("/"); ConnectionPool pool = new ConnectionPool(Integer.MAX_VALUE, 100L); new ConnectionPoolProxy(pool, emptyRunnable); // Used so that the connection pool can be properly unit tested rawClient.setConnectionPool(pool);// w w w. ja va2 s . c o m InstrumentedOkHttpClient client = new InstrumentedOkHttpClient(registry, rawClient, null); assertThat(registry.getGauges().get(client.metricId("connection-pool-count")).getValue()).isEqualTo(0); assertThat(registry.getGauges().get(client.metricId("connection-pool-count-http")).getValue()).isEqualTo(0); assertThat(registry.getGauges().get(client.metricId("connection-pool-count-multiplexed")).getValue()) .isEqualTo(0); Request req1 = new Request.Builder().url(baseUrl).build(); Request req2 = new Request.Builder().url(baseUrl).build(); Response resp1 = client.newCall(req1).execute(); Response resp2 = client.newCall(req2).execute(); assertThat(registry.getGauges().get(client.metricId("connection-pool-count")).getValue()).isEqualTo(2); assertThat(registry.getGauges().get(client.metricId("connection-pool-count-http")).getValue()).isEqualTo(2); assertThat(registry.getGauges().get(client.metricId("connection-pool-count-multiplexed")).getValue()) .isEqualTo(0); resp1.body().close(); resp2.body().close(); pool.evictAll(); }