Example usage for com.squareup.okhttp ConnectionPool getConnectionCount

List of usage examples for com.squareup.okhttp ConnectionPool getConnectionCount

Introduction

In this page you can find the example usage for com.squareup.okhttp ConnectionPool getConnectionCount.

Prototype

public synchronized int getConnectionCount() 

Source Link

Document

Returns total number of connections in the pool.

Usage

From source file:twitter4j.Http2ClientTest.java

License:Apache License

public void testNoPreferOption() throws Exception {
    AlternativeHttpClientImpl http = callOembed();

    // check HTTP/2.0
    Field f = http.getClass().getDeclaredField("okHttpClient");
    f.setAccessible(true);//from w  ww . j  a  v a2s. co m
    OkHttpClient client = (OkHttpClient) f.get(http);
    assertNotNull("ensure that OkHttpClient is used", client);

    ConnectionPool p = client.getConnectionPool();
    assertEquals(1, p.getConnectionCount());
    assertEquals(0, p.getHttpConnectionCount());
    assertEquals(1, p.getMultiplexedConnectionCount());

    assertEquals("h2", http.getLastRequestProtocol());
}

From source file:twitter4j.Http2ClientTest.java

License:Apache License

public void testSpdy() throws Exception {
    AlternativeHttpClientImpl.sPreferSpdy = true;
    AlternativeHttpClientImpl.sPreferHttp2 = false;
    AlternativeHttpClientImpl http = callOembed();

    // check SPDY
    Field f = http.getClass().getDeclaredField("okHttpClient");
    f.setAccessible(true);// w w  w .j  ava2  s .  c  om
    OkHttpClient client = (OkHttpClient) f.get(http);
    assertNotNull("ensure that OkHttpClient is used", client);

    ConnectionPool p = client.getConnectionPool();
    assertEquals(1, p.getConnectionCount());
    assertEquals(0, p.getHttpConnectionCount());
    assertEquals(1, p.getMultiplexedConnectionCount());

    assertEquals("spdy/3.1", http.getLastRequestProtocol());
}

From source file:twitter4j.Http2ClientTest.java

License:Apache License

public void testHttp2() throws Exception {
    AlternativeHttpClientImpl.sPreferSpdy = false;
    AlternativeHttpClientImpl.sPreferHttp2 = true;
    AlternativeHttpClientImpl http = callOembed();

    // check HTTP/2.0
    Field f = http.getClass().getDeclaredField("okHttpClient");
    f.setAccessible(true);/*  www.ja va  2 s .  com*/
    OkHttpClient client = (OkHttpClient) f.get(http);
    assertNotNull("ensure that OkHttpClient is used", client);

    ConnectionPool p = client.getConnectionPool();
    assertEquals(1, p.getConnectionCount());
    assertEquals(0, p.getHttpConnectionCount());
    assertEquals(1, p.getMultiplexedConnectionCount());

    assertEquals("h2", http.getLastRequestProtocol());
}

From source file:twitter4j.Http2ClientTest.java

License:Apache License

public void testNoSpdy() throws Exception {
    AlternativeHttpClientImpl.sPreferSpdy = false;
    AlternativeHttpClientImpl.sPreferHttp2 = false;

    AlternativeHttpClientImpl http = callOembed();

    // check not SPDY
    Field f = http.getClass().getDeclaredField("okHttpClient");
    f.setAccessible(true);/*from   w  w  w .j a v a 2  s . com*/
    OkHttpClient client = (OkHttpClient) f.get(http);

    ConnectionPool p = client.getConnectionPool();
    assertEquals(1, p.getConnectionCount());
    assertEquals(1, p.getHttpConnectionCount());
    assertEquals(0, p.getMultiplexedConnectionCount());

    assertEquals("http/1.1", http.getLastRequestProtocol());
}

From source file:twitter4j.SpdyHttpClientTest.java

License:Apache License

public void testNoPreferOption() throws Exception {
    AlternativeHttpClientImpl http = callOembed();

    // check HTTP/2.0
    Field f = http.getClass().getDeclaredField("client");
    f.setAccessible(true);//from   w w  w.j  av  a2 s .co  m
    OkHttpClient client = (OkHttpClient) f.get(http);
    assertNotNull("ensure that OkHttpClient is used", client);

    ConnectionPool p = client.getConnectionPool();
    assertEquals(1, p.getConnectionCount());
    assertEquals(0, p.getHttpConnectionCount());
    assertEquals(1, p.getSpdyConnectionCount());

    assertEquals("HTTP-draft-09/2.0", http.getLastRequestProtocol());
}

From source file:twitter4j.SpdyHttpClientTest.java

License:Apache License

public void testSpdy() throws Exception {
    AlternativeHttpClientImpl.sPreferSpdy = true;
    AlternativeHttpClientImpl.sPreferHttp2 = false;
    AlternativeHttpClientImpl http = callOembed();

    // check SPDY
    Field f = http.getClass().getDeclaredField("client");
    f.setAccessible(true);//w ww  . j a v  a  2 s  .co m
    OkHttpClient client = (OkHttpClient) f.get(http);
    assertNotNull("ensure that OkHttpClient is used", client);

    ConnectionPool p = client.getConnectionPool();
    assertEquals(1, p.getConnectionCount());
    assertEquals(0, p.getHttpConnectionCount());
    assertEquals(1, p.getSpdyConnectionCount());

    assertEquals("spdy/3.1", http.getLastRequestProtocol());
}

From source file:twitter4j.SpdyHttpClientTest.java

License:Apache License

public void testHttp2() throws Exception {
    AlternativeHttpClientImpl.sPreferSpdy = false;
    AlternativeHttpClientImpl.sPreferHttp2 = true;
    AlternativeHttpClientImpl http = callOembed();

    // check HTTP/2.0
    Field f = http.getClass().getDeclaredField("client");
    f.setAccessible(true);/* ww w .  j a  v a  2  s.co  m*/
    OkHttpClient client = (OkHttpClient) f.get(http);
    assertNotNull("ensure that OkHttpClient is used", client);

    ConnectionPool p = client.getConnectionPool();
    assertEquals(1, p.getConnectionCount());
    assertEquals(0, p.getHttpConnectionCount());
    assertEquals(1, p.getSpdyConnectionCount());

    assertEquals("HTTP-draft-09/2.0", http.getLastRequestProtocol());
}