Search in sources :

Example 31 with ConnectionPool

use of okhttp3.ConnectionPool in project twitter4j by yusuke.

the class Http2ClientTest method testNoPreferOption.

@Test
void testNoPreferOption() throws Exception {
    // no prefer option
    if (alpnBootJarFoundInBootClassPath && ellipticCurvesExtensionFoundInClassPath) {
        AlternativeHttpClientImpl http = callOembed();
        // check HTTP/2.0
        Field f = http.getClass().getDeclaredField("okHttpClient");
        f.setAccessible(true);
        OkHttpClient client = (OkHttpClient) f.get(http);
        assertNotNull(client, "ensure that OkHttpClient is used");
        ConnectionPool p = client.connectionPool();
        assertEquals(1, p.connectionCount());
        assertEquals(Protocol.HTTP_2, http.getLastRequestProtocol());
    }
    // http2
    if (alpnBootJarFoundInBootClassPath && ellipticCurvesExtensionFoundInClassPath) {
        AlternativeHttpClientImpl.sPreferHttp2 = true;
        AlternativeHttpClientImpl http = callOembed();
        // check HTTP/2.0
        Field f = http.getClass().getDeclaredField("okHttpClient");
        f.setAccessible(true);
        OkHttpClient client = (OkHttpClient) f.get(http);
        assertNotNull(client, "ensure that OkHttpClient is used");
        ConnectionPool p = client.connectionPool();
        assertEquals(1, p.connectionCount());
        assertEquals(Protocol.HTTP_2, http.getLastRequestProtocol());
    }
}
Also used : ConnectionPool(okhttp3.ConnectionPool) Field(java.lang.reflect.Field) OkHttpClient(okhttp3.OkHttpClient) Test(org.junit.jupiter.api.Test)

Aggregations

ConnectionPool (okhttp3.ConnectionPool)12 Test (org.junit.Test)12 OkHttpClient (okhttp3.OkHttpClient)10 MockResponse (okhttp3.mockwebserver.MockResponse)8 IOException (java.io.IOException)5 RealConnection (okhttp3.internal.connection.RealConnection)5 Field (java.lang.reflect.Field)4 Dispatcher (okhttp3.Dispatcher)3 Socket (java.net.Socket)2 Level (java.util.logging.Level)2 SimpleFormatter (java.util.logging.SimpleFormatter)2 HttpCodec (okhttp3.internal.http.HttpCodec)2 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)2 BuckConfig (com.facebook.buck.cli.BuckConfig)1 BuckEventBus (com.facebook.buck.event.BuckEventBus)1 DirCacheExperimentEvent (com.facebook.buck.event.DirCacheExperimentEvent)1 BytesReceivedEvent (com.facebook.buck.event.NetworkEvent.BytesReceivedEvent)1 ProjectFilesystem (com.facebook.buck.io.ProjectFilesystem)1 CommandThreadFactory (com.facebook.buck.log.CommandThreadFactory)1 Logger (com.facebook.buck.log.Logger)1