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());
}
}
Aggregations