当前位置: 首页>>代码示例>>Java>>正文


Java ConnectionRequest.get方法代码示例

本文整理汇总了Java中org.apache.http.conn.ConnectionRequest.get方法的典型用法代码示例。如果您正苦于以下问题:Java ConnectionRequest.get方法的具体用法?Java ConnectionRequest.get怎么用?Java ConnectionRequest.get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.http.conn.ConnectionRequest的用法示例。


在下文中一共展示了ConnectionRequest.get方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testReleaseNonReusable

import org.apache.http.conn.ConnectionRequest; //导入方法依赖的package包/类
@Test
public void testReleaseNonReusable() throws Exception {
    final HttpHost target = new HttpHost("localhost", 80);
    final HttpRoute route = new HttpRoute(target);

    final CPoolEntry entry = Mockito.spy(new CPoolEntry(LogFactory.getLog(getClass()), "id", route, conn,
            -1, TimeUnit.MILLISECONDS));
    entry.markRouteComplete();

    Mockito.when(future.isCancelled()).thenReturn(Boolean.FALSE);
    Mockito.when(future.get(1, TimeUnit.SECONDS)).thenReturn(entry);
    Mockito.when(pool.lease(route, null, null)).thenReturn(future);
    Mockito.when(conn.isOpen()).thenReturn(Boolean.FALSE);

    final ConnectionRequest connRequest1 = mgr.requestConnection(route, null);
    final HttpClientConnection conn1 = connRequest1.get(1, TimeUnit.SECONDS);
    Assert.assertNotNull(conn1);
    Assert.assertFalse(conn1.isOpen());

    mgr.releaseConnection(conn1, "some state", 0, TimeUnit.MILLISECONDS);

    Mockito.verify(pool).release(entry, false);
    Mockito.verify(entry, Mockito.never()).setState(Mockito.anyObject());
    Mockito.verify(entry, Mockito.never()).updateExpiry(Mockito.anyLong(), Mockito.eq(TimeUnit.MILLISECONDS));
}
 
开发者ID:MyPureCloud,项目名称:purecloud-iot,代码行数:26,代码来源:TestPoolingHttpClientConnectionManager.java

示例2: testAlreadyLeased

import org.apache.http.conn.ConnectionRequest; //导入方法依赖的package包/类
@Test(expected=IllegalStateException.class)
public void testAlreadyLeased() throws Exception {
    final HttpHost target = new HttpHost("somehost", 80);
    final HttpRoute route = new HttpRoute(target);

    Mockito.when(connFactory.create(
            Mockito.eq(route), Mockito.<ConnectionConfig>any())).thenReturn(conn);

    final ConnectionRequest connRequest1 = mgr.requestConnection(route, null);
    final HttpClientConnection conn1 = connRequest1.get(0, TimeUnit.MILLISECONDS);
    Assert.assertNotNull(conn1);
    mgr.releaseConnection(conn1, null, 100, TimeUnit.MILLISECONDS);

    mgr.getConnection(route, null);
    mgr.getConnection(route, null);
}
 
开发者ID:MyPureCloud,项目名称:purecloud-iot,代码行数:17,代码来源:TestBasicHttpClientConnectionManager.java

示例3: testLeaseFutureCancelled

import org.apache.http.conn.ConnectionRequest; //导入方法依赖的package包/类
@Test(expected=InterruptedException.class)
public void testLeaseFutureCancelled() throws Exception {
    final HttpHost target = new HttpHost("localhost", 80);
    final HttpRoute route = new HttpRoute(target);

    final CPoolEntry entry = new CPoolEntry(LogFactory.getLog(getClass()), "id", route, conn,
            -1, TimeUnit.MILLISECONDS);
    entry.markRouteComplete();

    Mockito.when(future.isCancelled()).thenReturn(Boolean.TRUE);
    Mockito.when(future.get(1, TimeUnit.SECONDS)).thenReturn(entry);
    Mockito.when(pool.lease(route, null, null)).thenReturn(future);

    final ConnectionRequest connRequest1 = mgr.requestConnection(route, null);
    connRequest1.get(1, TimeUnit.SECONDS);
}
 
开发者ID:MyPureCloud,项目名称:purecloud-iot,代码行数:17,代码来源:TestPoolingHttpClientConnectionManager.java

示例4: requestConnection

import org.apache.http.conn.ConnectionRequest; //导入方法依赖的package包/类
@Before
public void requestConnection() throws Exception {
  HttpHost host = new HttpHost(InetAddress.getLocalHost(), inbound.getPort());
  HttpRoute route = new HttpRoute(host, InetAddress.getLocalHost(), false);
  connManager = new BasicHttpClientConnectionManager();
  ConnectionRequest connRequest = connManager.requestConnection(route, null);
  conn = connRequest.get(10, TimeUnit.SECONDS);
  // Make two requests on the same connection
  connManager.connect(conn, route, 10000, new BasicHttpContext());
}
 
开发者ID:yarpc,项目名称:yarpc-java,代码行数:11,代码来源:HttpConnectionReuseTest.java

示例5: testReleaseOnEntityConsumeContent

import org.apache.http.conn.ConnectionRequest; //导入方法依赖的package包/类
@Test
public void testReleaseOnEntityConsumeContent() throws Exception {
    this.connManager.setDefaultMaxPerRoute(1);
    this.connManager.setMaxTotal(1);

    // Zero connections in the pool
    PoolStats stats = this.connManager.getTotalStats();
    Assert.assertEquals(0, stats.getAvailable());

    final HttpHost target = start();
    // Get some random data
    final HttpGet httpget = new HttpGet("/random/20000");
    final HttpResponse response = this.httpclient.execute(target, httpget);

    ConnectionRequest connreq = this.connManager.requestConnection(new HttpRoute(target), null);
    try {
        connreq.get(250, TimeUnit.MILLISECONDS);
        Assert.fail("ConnectionPoolTimeoutException should have been thrown");
    } catch (final ConnectionPoolTimeoutException expected) {
    }

    final HttpEntity e = response.getEntity();
    Assert.assertNotNull(e);
    EntityUtils.consume(e);

    // Expect one connection in the pool
    stats = this.connManager.getTotalStats();
    Assert.assertEquals(1, stats.getAvailable());

    // Make sure one connection is available
    connreq = this.connManager.requestConnection(new HttpRoute(target), null);
    final HttpClientConnection conn = connreq.get(250, TimeUnit.MILLISECONDS);

    this.connManager.releaseConnection(conn, null, -1, null);
}
 
开发者ID:MyPureCloud,项目名称:purecloud-iot,代码行数:36,代码来源:TestConnectionAutoRelease.java

示例6: testReleaseOnEntityWriteTo

import org.apache.http.conn.ConnectionRequest; //导入方法依赖的package包/类
@Test
public void testReleaseOnEntityWriteTo() throws Exception {
    this.connManager.setDefaultMaxPerRoute(1);
    this.connManager.setMaxTotal(1);

    // Zero connections in the pool
    PoolStats stats = this.connManager.getTotalStats();
    Assert.assertEquals(0, stats.getAvailable());

    final HttpHost target = start();
    // Get some random data
    final HttpGet httpget = new HttpGet("/random/20000");
    final HttpResponse response = this.httpclient.execute(target, httpget);

    ConnectionRequest connreq = this.connManager.requestConnection(new HttpRoute(target), null);
    try {
        connreq.get(250, TimeUnit.MILLISECONDS);
        Assert.fail("ConnectionPoolTimeoutException should have been thrown");
    } catch (final ConnectionPoolTimeoutException expected) {
    }

    final HttpEntity e = response.getEntity();
    Assert.assertNotNull(e);
    final ByteArrayOutputStream outsteam = new ByteArrayOutputStream();
    e.writeTo(outsteam);

    // Expect one connection in the pool
    stats = this.connManager.getTotalStats();
    Assert.assertEquals(1, stats.getAvailable());

    // Make sure one connection is available
    connreq = this.connManager.requestConnection(new HttpRoute(target), null);
    final HttpClientConnection conn = connreq.get(250, TimeUnit.MILLISECONDS);

    this.connManager.releaseConnection(conn, null, -1, null);
}
 
开发者ID:MyPureCloud,项目名称:purecloud-iot,代码行数:37,代码来源:TestConnectionAutoRelease.java

示例7: testReleaseOnAbort

import org.apache.http.conn.ConnectionRequest; //导入方法依赖的package包/类
@Test
public void testReleaseOnAbort() throws Exception {
    this.connManager.setDefaultMaxPerRoute(1);
    this.connManager.setMaxTotal(1);

    // Zero connections in the pool
    final PoolStats stats = this.connManager.getTotalStats();
    Assert.assertEquals(0, stats.getAvailable());

    final HttpHost target = start();

    // Get some random data
    final HttpGet httpget = new HttpGet("/random/20000");
    final HttpResponse response = this.httpclient.execute(target, httpget);

    ConnectionRequest connreq = this.connManager.requestConnection(new HttpRoute(target), null);
    try {
        connreq.get(250, TimeUnit.MILLISECONDS);
        Assert.fail("ConnectionPoolTimeoutException should have been thrown");
    } catch (final ConnectionPoolTimeoutException expected) {
    }

    final HttpEntity e = response.getEntity();
    Assert.assertNotNull(e);
    httpget.abort();

    // Expect zero connections in the pool
    Assert.assertEquals(0, this.connManager.getTotalStats().getAvailable());

    // Make sure one connection is available
    connreq = this.connManager.requestConnection(new HttpRoute(target), null);
    final HttpClientConnection conn = connreq.get(250, TimeUnit.MILLISECONDS);

    this.connManager.releaseConnection(conn, null, -1, null);
}
 
开发者ID:MyPureCloud,项目名称:purecloud-iot,代码行数:36,代码来源:TestConnectionAutoRelease.java

示例8: getConnection

import org.apache.http.conn.ConnectionRequest; //导入方法依赖的package包/类
private static HttpClientConnection getConnection(
        final HttpClientConnectionManager mgr,
        final HttpRoute route,
        final long timeout,
        final TimeUnit unit) throws ConnectionPoolTimeoutException, ExecutionException, InterruptedException {
    final ConnectionRequest connRequest = mgr.requestConnection(route, null);
    return connRequest.get(timeout, unit);
}
 
开发者ID:MyPureCloud,项目名称:purecloud-iot,代码行数:9,代码来源:TestConnectionManagement.java

示例9: testLeaseReleaseReusable

import org.apache.http.conn.ConnectionRequest; //导入方法依赖的package包/类
@Test
public void testLeaseReleaseReusable() throws Exception {
    final HttpHost target = new HttpHost("somehost", 80);
    final HttpRoute route = new HttpRoute(target);

    Mockito.when(connFactory.create(Mockito.eq(route), Mockito.<ConnectionConfig>any())).thenReturn(conn);

    final ConnectionRequest connRequest1 = mgr.requestConnection(route, null);
    final HttpClientConnection conn1 = connRequest1.get(0, TimeUnit.MILLISECONDS);
    Assert.assertNotNull(conn1);

    Mockito.verify(connFactory, Mockito.times(1)).create(
            Mockito.eq(route), Mockito.<ConnectionConfig>any());

    Mockito.when(conn.isOpen()).thenReturn(Boolean.TRUE);

    mgr.releaseConnection(conn1, null, 10000, TimeUnit.MILLISECONDS);

    Assert.assertEquals(route, mgr.getRoute());
    Assert.assertEquals(null, mgr.getState());

    final ConnectionRequest connRequest2 = mgr.requestConnection(route, null);
    final HttpClientConnection conn2 = connRequest2.get(0, TimeUnit.MILLISECONDS);
    Assert.assertNotNull(conn2);
    Assert.assertTrue(conn2.isOpen());

    Mockito.verify(connFactory, Mockito.times(1)).create(
            Mockito.eq(route), Mockito.<ConnectionConfig>any());
}
 
开发者ID:MyPureCloud,项目名称:purecloud-iot,代码行数:30,代码来源:TestBasicHttpClientConnectionManager.java

示例10: testLeaseDifferentRoute

import org.apache.http.conn.ConnectionRequest; //导入方法依赖的package包/类
@Test
public void testLeaseDifferentRoute() throws Exception {
    final HttpHost target1 = new HttpHost("somehost", 80);
    final HttpRoute route1 = new HttpRoute(target1);

    Mockito.when(connFactory.create(
            Mockito.<HttpRoute>any(), Mockito.<ConnectionConfig>any())).thenReturn(conn);

    final ConnectionRequest connRequest1 = mgr.requestConnection(route1, null);
    final HttpClientConnection conn1 = connRequest1.get(0, TimeUnit.MILLISECONDS);
    Assert.assertNotNull(conn1);

    Mockito.verify(connFactory, Mockito.times(1)).create(
            Mockito.eq(route1), Mockito.<ConnectionConfig>any());

    Mockito.when(conn.isOpen()).thenReturn(Boolean.TRUE, Boolean.FALSE);

    mgr.releaseConnection(conn1, null, 0, TimeUnit.MILLISECONDS);

    Assert.assertEquals(route1, mgr.getRoute());
    Assert.assertEquals(null, mgr.getState());

    final HttpHost target2 = new HttpHost("otherhost", 80);
    final HttpRoute route2 = new HttpRoute(target2);
    final ConnectionRequest connRequest2 = mgr.requestConnection(route2, null);
    final HttpClientConnection conn2 = connRequest2.get(0, TimeUnit.MILLISECONDS);
    Assert.assertNotNull(conn2);
    Assert.assertFalse(conn2.isOpen());

    Mockito.verify(conn).close();
    Mockito.verify(connFactory, Mockito.times(1)).create(
            Mockito.eq(route1), Mockito.<ConnectionConfig>any());
    Mockito.verify(connFactory, Mockito.times(1)).create(
            Mockito.eq(route2), Mockito.<ConnectionConfig>any());
}
 
开发者ID:MyPureCloud,项目名称:purecloud-iot,代码行数:36,代码来源:TestBasicHttpClientConnectionManager.java

示例11: testLeaseExpired

import org.apache.http.conn.ConnectionRequest; //导入方法依赖的package包/类
@Test
public void testLeaseExpired() throws Exception {
    final HttpHost target = new HttpHost("somehost", 80);
    final HttpRoute route = new HttpRoute(target);

    Mockito.when(connFactory.create(
            Mockito.eq(route), Mockito.<ConnectionConfig>any())).thenReturn(conn);

    final ConnectionRequest connRequest1 = mgr.requestConnection(route, null);
    final HttpClientConnection conn1 = connRequest1.get(0, TimeUnit.MILLISECONDS);
    Assert.assertNotNull(conn1);

    Mockito.verify(connFactory, Mockito.times(1)).create(
            Mockito.eq(route), Mockito.<ConnectionConfig>any());

    Mockito.when(conn.isOpen()).thenReturn(Boolean.TRUE, Boolean.FALSE);

    mgr.releaseConnection(conn1, null, 10, TimeUnit.MILLISECONDS);

    Assert.assertEquals(route, mgr.getRoute());
    Assert.assertEquals(null, mgr.getState());

    Thread.sleep(50);

    final ConnectionRequest connRequest2 = mgr.requestConnection(route, null);
    final HttpClientConnection conn2 = connRequest2.get(0, TimeUnit.MILLISECONDS);
    Assert.assertNotNull(conn2);
    Assert.assertFalse(conn2.isOpen());

    Mockito.verify(conn).close();
    Mockito.verify(connFactory, Mockito.times(2)).create(
            Mockito.eq(route), Mockito.<ConnectionConfig>any());
}
 
开发者ID:MyPureCloud,项目名称:purecloud-iot,代码行数:34,代码来源:TestBasicHttpClientConnectionManager.java

示例12: testShutdown

import org.apache.http.conn.ConnectionRequest; //导入方法依赖的package包/类
@Test
public void testShutdown() throws Exception {
    final HttpHost target = new HttpHost("somehost", 80);
    final HttpRoute route = new HttpRoute(target);

    Mockito.when(connFactory.create(
            Mockito.eq(route), Mockito.<ConnectionConfig>any())).thenReturn(conn);

    final ConnectionRequest connRequest1 = mgr.requestConnection(route, null);
    final HttpClientConnection conn1 = connRequest1.get(0, TimeUnit.MILLISECONDS);
    Assert.assertNotNull(conn1);

    Mockito.verify(connFactory, Mockito.times(1)).create(
            Mockito.eq(route), Mockito.<ConnectionConfig>any());

    Mockito.when(conn.isOpen()).thenReturn(Boolean.TRUE);

    mgr.releaseConnection(conn1, null, 0, TimeUnit.MILLISECONDS);

    mgr.shutdown();

    Mockito.verify(conn, Mockito.times(1)).shutdown();

    try {
        final ConnectionRequest connRequest2 = mgr.requestConnection(route, null);
        connRequest2.get(0, TimeUnit.MILLISECONDS);
        Assert.fail("IllegalStateException expected");
    } catch (final IllegalStateException ex) {
    }

    // Should have no effect
    mgr.closeExpiredConnections();
    mgr.closeIdleConnections(0L, TimeUnit.MILLISECONDS);
    mgr.shutdown();

    Mockito.verify(conn, Mockito.times(1)).shutdown();
}
 
开发者ID:MyPureCloud,项目名称:purecloud-iot,代码行数:38,代码来源:TestBasicHttpClientConnectionManager.java

示例13: testLeaseFutureTimeout

import org.apache.http.conn.ConnectionRequest; //导入方法依赖的package包/类
@Test(expected=ConnectionPoolTimeoutException.class)
public void testLeaseFutureTimeout() throws Exception {
    final HttpHost target = new HttpHost("localhost", 80);
    final HttpRoute route = new HttpRoute(target);

    Mockito.when(future.isCancelled()).thenReturn(Boolean.TRUE);
    Mockito.when(future.get(1, TimeUnit.SECONDS)).thenThrow(new TimeoutException());
    Mockito.when(pool.lease(route, null, null)).thenReturn(future);

    final ConnectionRequest connRequest1 = mgr.requestConnection(route, null);
    connRequest1.get(1, TimeUnit.SECONDS);
}
 
开发者ID:MyPureCloud,项目名称:purecloud-iot,代码行数:13,代码来源:TestPoolingHttpClientConnectionManager.java

示例14: testLeaseRelease

import org.apache.http.conn.ConnectionRequest; //导入方法依赖的package包/类
@Test
public void testLeaseRelease() throws Exception {
    final HttpHost target = new HttpHost("localhost", 80);
    final HttpRoute route = new HttpRoute(target);

    final CPoolEntry entry = new CPoolEntry(LogFactory.getLog(getClass()), "id", route, conn,
            -1, TimeUnit.MILLISECONDS);
    entry.markRouteComplete();

    Mockito.when(future.isCancelled()).thenReturn(Boolean.FALSE);
    Mockito.when(socketFactoryRegistry.lookup("http")).thenReturn(plainSocketFactory);
    Mockito.when(schemePortResolver.resolve(target)).thenReturn(80);
    Mockito.when(plainSocketFactory.createSocket(Mockito.<HttpContext>any())).thenReturn(socket);

    Mockito.when(conn.isOpen()).thenReturn(true);
    Mockito.when(future.isCancelled()).thenReturn(false);
    Mockito.when(future.get(1, TimeUnit.SECONDS)).thenReturn(entry);
    Mockito.when(pool.lease(route, null, null)).thenReturn(future);

    final ConnectionRequest connRequest1 = mgr.requestConnection(route, null);
    final HttpClientConnection conn1 = connRequest1.get(1, TimeUnit.SECONDS);
    Assert.assertNotNull(conn1);
    Assert.assertNotSame(conn, conn1);

    mgr.releaseConnection(conn1, null, 0, TimeUnit.MILLISECONDS);

    Mockito.verify(pool).release(entry, true);
}
 
开发者ID:MyPureCloud,项目名称:purecloud-iot,代码行数:29,代码来源:TestPoolingHttpClientConnectionManager.java

示例15: testReleaseRouteIncomplete

import org.apache.http.conn.ConnectionRequest; //导入方法依赖的package包/类
@Test
public void testReleaseRouteIncomplete() throws Exception {
    final HttpHost target = new HttpHost("localhost", 80);
    final HttpRoute route = new HttpRoute(target);

    final CPoolEntry entry = new CPoolEntry(LogFactory.getLog(getClass()), "id", route, conn,
            -1, TimeUnit.MILLISECONDS);

    Mockito.when(future.isCancelled()).thenReturn(Boolean.FALSE);
    Mockito.when(socketFactoryRegistry.lookup("http")).thenReturn(plainSocketFactory);
    Mockito.when(schemePortResolver.resolve(target)).thenReturn(80);
    Mockito.when(plainSocketFactory.createSocket(Mockito.<HttpContext>any())).thenReturn(socket);

    Mockito.when(conn.isOpen()).thenReturn(true);
    Mockito.when(future.isCancelled()).thenReturn(false);
    Mockito.when(future.get(1, TimeUnit.SECONDS)).thenReturn(entry);
    Mockito.when(pool.lease(route, null, null)).thenReturn(future);

    final ConnectionRequest connRequest1 = mgr.requestConnection(route, null);
    final HttpClientConnection conn1 = connRequest1.get(1, TimeUnit.SECONDS);
    Assert.assertNotNull(conn1);
    Assert.assertNotSame(conn, conn1);

    mgr.releaseConnection(conn1, null, 0, TimeUnit.MILLISECONDS);

    Mockito.verify(pool).release(entry, false);
}
 
开发者ID:MyPureCloud,项目名称:purecloud-iot,代码行数:28,代码来源:TestPoolingHttpClientConnectionManager.java


注:本文中的org.apache.http.conn.ConnectionRequest.get方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。