code: @Test public void maxConnections() throws IOException, InterruptedException {
    ConnectionPool pool=new ConnectionPool(2,KEEP_ALIVE_DURATION_MS);
    assertEquals(0,pool.getConnectionCount());
    pool.recycle(httpA);
    assertEquals(1,pool.getConnectionCount());
    assertEquals(1,pool.getHttpConnectionCount());
    assertEquals(0,pool.getSpdyConnectionCount());
    pool.recycle(httpB);
    assertEquals(2,pool.getConnectionCount());
    assertEquals(2,pool.getHttpConnectionCount());
    assertEquals(0,pool.getSpdyConnectionCount());
    pool.recycle(httpC);
    Thread.sleep(50);
    assertEquals(2,pool.getConnectionCount());
    assertEquals(2,pool.getHttpConnectionCount());
    assertEquals(0,pool.getSpdyConnectionCount());
    pool.share(spdyA);
    Thread.sleep(50);
    assertEquals(2,pool.getConnectionCount());
    assertEquals(1,pool.getHttpConnectionCount());
    assertEquals(1,pool.getSpdyConnectionCount());
    Connection recycledHttpConnection=pool.get(httpAddress);
    assertNotNull(recycledHttpConnection);
    assertTrue(recycledHttpConnection.isAlive());
    assertEquals(1,pool.getConnectionCount());
    assertEquals(0,pool.getHttpConnectionCount());
    assertEquals(1,pool.getSpdyConnectionCount());
    Connection sharedSpdyConnection=pool.get(spdyAddress);
    assertNotNull(sharedSpdyConnection);
    assertEquals(spdyA,sharedSpdyConnection);
    assertEquals(1,pool.getConnectionCount());
    assertEquals(0,pool.getHttpConnectionCount());
    assertEquals(1,pool.getSpdyConnectionCount());
    pool.recycle(httpC);
    Thread.sleep(50);
    assertEquals(2,pool.getConnectionCount());
    assertEquals(1,pool.getHttpConnectionCount());
    assertEquals(1,pool.getSpdyConnectionCount());
    recycledHttpConnection=pool.get(httpAddress);
    assertNotNull(recycledHttpConnection);
    assertTrue(recycledHttpConnection.isAlive());
    assertEquals(1,pool.getConnectionCount());
    assertEquals(0,pool.getHttpConnectionCount());
    assertEquals(1,pool.getSpdyConnectionCount());
    sharedSpdyConnection=pool.get(spdyAddress);
    assertEquals(spdyA,sharedSpdyConnection);
    assertNotNull(sharedSpdyConnection);
    assertEquals(1,pool.getConnectionCount());
    assertEquals(0,pool.getHttpConnectionCount());
    assertEquals(1,pool.getSpdyConnectionCount());
    pool.recycle(httpD);
    Thread.sleep(50);
    assertEquals(2,pool.getConnectionCount());
    assertEquals(1,pool.getHttpConnectionCount());
    assertEquals(1,pool.getSpdyConnectionCount());
    pool.recycle(httpE);
    Thread.sleep(50);
    assertEquals(2,pool.getConnectionCount());
    assertEquals(2,pool.getHttpConnectionCount());
    assertEquals(0,pool.getSpdyConnectionCount());
  }
  