Example usage for com.squareup.okhttp OkHttpClient getConnectTimeout

List of usage examples for com.squareup.okhttp OkHttpClient getConnectTimeout

Introduction

In this page you can find the example usage for com.squareup.okhttp OkHttpClient getConnectTimeout.

Prototype

public int getConnectTimeout() 

Source Link

Document

Default connect timeout (in milliseconds).

Usage

From source file:com.raskasa.metrics.okhttp.InstrumentedOkHttpClientsTest.java

License:Apache License

@Test
public void instrumentDefaultClient() {
    OkHttpClient client = InstrumentedOkHttpClients.create(registry);

    // The connection, read, and write timeouts are the only configurations applied by default.
    assertThat(client.getConnectTimeout()).isEqualTo(10_000);
    assertThat(client.getReadTimeout()).isEqualTo(10_000);
    assertThat(client.getWriteTimeout()).isEqualTo(10_000);
}

From source file:com.raskasa.metrics.okhttp.InstrumentedOkHttpClientsTest.java

License:Apache License

@Test
public void instrumentAndNameDefaultClient() {
    OkHttpClient client = InstrumentedOkHttpClients.create(registry, "custom");

    // The connection, read, and write timeouts are the only configurations applied by default.
    assertThat(client.getConnectTimeout()).isEqualTo(10_000);
    assertThat(client.getReadTimeout()).isEqualTo(10_000);
    assertThat(client.getWriteTimeout()).isEqualTo(10_000);
}

From source file:com.raskasa.metrics.okhttp.InstrumentedOkHttpClientsTest.java

License:Apache License

private void assertThatClientsAreEqual(OkHttpClient clientA, OkHttpClient clientB) {
    assertThat(clientA.getDispatcher()).isEqualTo(clientB.getDispatcher());
    assertThat(clientA.getProxy()).isEqualTo(clientB.getProxy());
    assertThat(clientA.getProtocols()).isEqualTo(clientB.getProtocols());
    assertThat(clientA.getConnectionSpecs()).isEqualTo(clientB.getConnectionSpecs());
    assertThat(clientA.getProxySelector()).isEqualTo(clientB.getProxySelector());
    assertThat(clientA.getCookieHandler()).isEqualTo(clientB.getCookieHandler());
    assertThat(clientA.getCache()).isEqualTo(clientB.getCache());
    assertThat(clientA.getSocketFactory()).isEqualTo(clientB.getSocketFactory());
    assertThat(clientA.getSslSocketFactory()).isEqualTo(clientB.getSslSocketFactory());
    assertThat(clientA.getHostnameVerifier()).isEqualTo(clientB.getHostnameVerifier());
    assertThat(clientA.getCertificatePinner()).isEqualTo(clientB.getCertificatePinner());
    assertThat(clientA.getAuthenticator()).isEqualTo(clientB.getAuthenticator());
    assertThat(clientA.getConnectionPool()).isEqualTo(clientB.getConnectionPool());
    assertThat(clientA.getFollowSslRedirects()).isEqualTo(clientB.getFollowSslRedirects());
    assertThat(clientA.getFollowRedirects()).isEqualTo(clientB.getFollowRedirects());
    assertThat(clientA.getRetryOnConnectionFailure()).isEqualTo(clientB.getRetryOnConnectionFailure());
    assertThat(clientA.getConnectTimeout()).isEqualTo(clientB.getConnectTimeout());
    assertThat(clientA.getReadTimeout()).isEqualTo(clientB.getReadTimeout());
    assertThat(clientA.getWriteTimeout()).isEqualTo(clientB.getWriteTimeout());
}

From source file:com.spotify.apollo.http.client.HttpClientModuleTest.java

License:Apache License

/**
 * Ensure that the OkHttpClient instance provided by the module is configured as expected. This
 * duplicates tests in {@link com.spotify.apollo.http.client.OkHttpClientProviderTest} but
 * verifies that the provider is actually used.
 *//*  ww w.  j a v  a  2  s  .c  o m*/
@Test
public void testOkHttpClientIsConfigured() throws Exception {
    final Config config = ConfigFactory.parseString("http.client.connectTimeout: 7982");

    final Service service = Services.usingName("test").withModule(HttpClientModule.create()).build();

    try (Service.Instance i = service.start(new String[] {}, config)) {

        final OkHttpClient underlying = i.resolve(OkHttpClient.class);
        assertThat(underlying.getConnectTimeout(), is(7982));
    }

}