Example usage for org.apache.http.impl.nio.conn CPoolEntry markRouteComplete

List of usage examples for org.apache.http.impl.nio.conn CPoolEntry markRouteComplete

Introduction

In this page you can find the example usage for org.apache.http.impl.nio.conn CPoolEntry markRouteComplete.

Prototype

public void markRouteComplete() 

Source Link

Usage

From source file:org.apache.http.impl.nio.conn.PoolingNHttpClientConnectionManager.java

@Override
public void routeComplete(final NHttpClientConnection managedConn, final HttpRoute route,
        final HttpContext context) {
    Args.notNull(managedConn, "Managed connection");
    Args.notNull(route, "HTTP route");
    synchronized (managedConn) {
        final CPoolEntry entry = CPoolProxy.getPoolEntry(managedConn);
        entry.markRouteComplete();
    }// w ww .  jav a2 s.  co m
}

From source file:org.apache.http.impl.nio.conn.TestPoolingHttpClientAsyncConnectionManager.java

@Test
public void testRequestReleaseConnection() throws Exception {
    final HttpHost target = new HttpHost("localhost");
    final HttpRoute route = new HttpRoute(target);
    final Future<NHttpClientConnection> future = connman.requestConnection(route, "some state", 1000L, 2000L,
            TimeUnit.MILLISECONDS, connCallback);
    Assert.assertNotNull(future);//from   ww  w .j  a  va2 s  .co m

    Mockito.verify(pool).lease(Matchers.same(route), Matchers.eq("some state"), Matchers.eq(1000L),
            Matchers.eq(2000L), Matchers.eq(TimeUnit.MILLISECONDS), poolEntryCallbackCaptor.capture());
    final FutureCallback<CPoolEntry> callaback = poolEntryCallbackCaptor.getValue();
    final Log log = Mockito.mock(Log.class);
    final CPoolEntry poolentry = new CPoolEntry(log, "some-id", route, conn, -1, TimeUnit.MILLISECONDS);
    poolentry.markRouteComplete();
    callaback.completed(poolentry);

    Assert.assertTrue(future.isDone());
    final NHttpClientConnection managedConn = future.get();
    Mockito.verify(connCallback).completed(Matchers.<NHttpClientConnection>any());

    Mockito.when(conn.isOpen()).thenReturn(Boolean.TRUE);
    connman.releaseConnection(managedConn, "new state", 5, TimeUnit.SECONDS);

    Mockito.verify(pool).release(poolentry, true);
    Assert.assertEquals("new state", poolentry.getState());
    final Calendar cal = Calendar.getInstance();
    cal.setTimeInMillis(poolentry.getUpdated());
    cal.add(Calendar.SECOND, 5);
    Assert.assertEquals(cal.getTimeInMillis(), poolentry.getExpiry());
}

From source file:org.apache.http.impl.nio.conn.TestPoolingHttpClientAsyncConnectionManager.java

@Test
public void testRequestConnectionFutureCancelled() throws Exception {
    final HttpHost target = new HttpHost("localhost");
    final HttpRoute route = new HttpRoute(target);
    final Future<NHttpClientConnection> future = connman.requestConnection(route, "some state", 1000L, 2000L,
            TimeUnit.MILLISECONDS, null);
    Assert.assertNotNull(future);//from   ww w .  j  a  va 2  s.co  m
    future.cancel(true);

    Mockito.verify(pool).lease(Matchers.same(route), Matchers.eq("some state"), Matchers.eq(1000L),
            Matchers.eq(2000L), Matchers.eq(TimeUnit.MILLISECONDS), poolEntryCallbackCaptor.capture());
    final FutureCallback<CPoolEntry> callaback = poolEntryCallbackCaptor.getValue();
    final Log log = Mockito.mock(Log.class);
    final CPoolEntry poolentry = new CPoolEntry(log, "some-id", route, conn, -1, TimeUnit.MILLISECONDS);
    poolentry.markRouteComplete();
    callaback.completed(poolentry);

    Mockito.verify(pool).release(poolentry, true);
}

From source file:org.apache.http.impl.nio.conn.TestPoolingHttpClientAsyncConnectionManager.java

@Test
public void testConnectionInitializeHttps() throws Exception {
    final HttpHost target = new HttpHost("somehost", 443, "https");
    final HttpRoute route = new HttpRoute(target, null, true);
    final HttpContext context = new BasicHttpContext();

    final Log log = Mockito.mock(Log.class);
    final CPoolEntry poolentry = new CPoolEntry(log, "some-id", route, conn, -1, TimeUnit.MILLISECONDS);
    poolentry.markRouteComplete();
    final NHttpClientConnection managedConn = CPoolProxy.newProxy(poolentry);

    Mockito.when(conn.getIOSession()).thenReturn(iosession);
    Mockito.when(sslStrategy.upgrade(target, iosession)).thenReturn(iosession);

    connman.startRoute(managedConn, route, context);

    Mockito.verify(sslStrategy).upgrade(target, iosession);
    Mockito.verify(conn).bind(iosession);
}

From source file:org.apache.http.impl.nio.conn.TestPoolingHttpClientAsyncConnectionManager.java

@Test(expected = UnsupportedSchemeException.class)
public void testConnectionInitializeUnknownScheme() throws Exception {
    final HttpHost target = new HttpHost("somehost", -1, "whatever");
    final HttpRoute route = new HttpRoute(target, null, true);
    final HttpContext context = new BasicHttpContext();

    final Log log = Mockito.mock(Log.class);
    final CPoolEntry poolentry = new CPoolEntry(log, "some-id", route, conn, -1, TimeUnit.MILLISECONDS);
    poolentry.markRouteComplete();
    final NHttpClientConnection managedConn = CPoolProxy.newProxy(poolentry);

    Mockito.when(conn.getIOSession()).thenReturn(iosession);
    Mockito.when(sslStrategy.upgrade(target, iosession)).thenReturn(iosession);

    connman.startRoute(managedConn, route, context);
}

From source file:org.apache.http.impl.nio.conn.TestPoolingHttpClientAsyncConnectionManager.java

@Test
public void testConnectionUpgrade() throws Exception {
    final HttpHost target = new HttpHost("somehost", 443, "https");
    final HttpRoute route = new HttpRoute(target);
    final HttpContext context = new BasicHttpContext();

    final Log log = Mockito.mock(Log.class);
    final CPoolEntry poolentry = new CPoolEntry(log, "some-id", route, conn, -1, TimeUnit.MILLISECONDS);
    poolentry.markRouteComplete();
    final NHttpClientConnection managedConn = CPoolProxy.newProxy(poolentry);

    Mockito.when(conn.getIOSession()).thenReturn(iosession);
    Mockito.when(sslStrategy.upgrade(target, iosession)).thenReturn(iosession);

    connman.upgrade(managedConn, route, context);

    Mockito.verify(sslStrategy).upgrade(target, iosession);
    Mockito.verify(conn).bind(iosession);
}

From source file:org.apache.http.impl.nio.conn.TestPoolingHttpClientAsyncConnectionManager.java

@Test(expected = UnsupportedSchemeException.class)
public void testConnectionUpgradeUnknownScheme() throws Exception {
    final HttpHost target = new HttpHost("somehost", -1, "whatever");
    final HttpRoute route = new HttpRoute(target);
    final HttpContext context = new BasicHttpContext();

    final Log log = Mockito.mock(Log.class);
    final CPoolEntry poolentry = new CPoolEntry(log, "some-id", route, conn, -1, TimeUnit.MILLISECONDS);
    poolentry.markRouteComplete();
    final NHttpClientConnection managedConn = CPoolProxy.newProxy(poolentry);

    Mockito.when(conn.getIOSession()).thenReturn(iosession);
    Mockito.when(sslStrategy.upgrade(target, iosession)).thenReturn(iosession);

    connman.upgrade(managedConn, route, context);
}

From source file:org.apache.http.impl.nio.conn.TestPoolingHttpClientAsyncConnectionManager.java

@Test(expected = UnsupportedSchemeException.class)
public void testConnectionUpgradeIllegalScheme() throws Exception {
    final HttpHost target = new HttpHost("somehost", 80, "http");
    final HttpRoute route = new HttpRoute(target);
    final HttpContext context = new BasicHttpContext();

    final Log log = Mockito.mock(Log.class);
    final CPoolEntry poolentry = new CPoolEntry(log, "some-id", route, conn, -1, TimeUnit.MILLISECONDS);
    poolentry.markRouteComplete();
    final NHttpClientConnection managedConn = CPoolProxy.newProxy(poolentry);

    Mockito.when(conn.getIOSession()).thenReturn(iosession);
    Mockito.when(sslStrategy.upgrade(target, iosession)).thenReturn(iosession);

    connman.upgrade(managedConn, route, context);
}

From source file:org.apache.http.impl.nio.conn.TestPoolingHttpClientAsyncConnectionManager.java

@Test
public void testConnectionRouteComplete() throws Exception {
    final HttpHost target = new HttpHost("somehost", 80, "http");
    final HttpRoute route = new HttpRoute(target);
    final HttpContext context = new BasicHttpContext();

    final Log log = Mockito.mock(Log.class);
    final CPoolEntry poolentry = new CPoolEntry(log, "some-id", route, conn, -1, TimeUnit.MILLISECONDS);
    poolentry.markRouteComplete();
    final NHttpClientConnection managedConn = CPoolProxy.newProxy(poolentry);

    Mockito.when(conn.getIOSession()).thenReturn(iosession);
    Mockito.when(sslStrategy.upgrade(target, iosession)).thenReturn(iosession);

    connman.startRoute(managedConn, route, context);
    connman.routeComplete(managedConn, route, context);

    Assert.assertTrue(connman.isRouteComplete(managedConn));
}