@Override public void execute(final PoolEntry<T, C> entry) { if (entry.getUpdated() <= deadline) { entry.discardConnection(CloseMode.GRACEFUL); } }
@Override public void execute(final PoolEntry<T, C> entry) { if (entry.getUpdated() <= deadline) { entry.discardConnection(CloseMode.GRACEFUL); } }
@Override public void execute(final PoolEntry<T, C> entry) { if (entry.getUpdated() <= deadline) { entry.discardConnection(CloseMode.GRACEFUL); } }
@Override public void execute(final PoolEntry<T, C> entry) { if (entry.getUpdated() <= deadline) { entry.discardConnection(CloseMode.GRACEFUL); } }
final ManagedHttpClientConnection conn = poolEntry.getConnection(); if (conn != null && poolEntry.getUpdated() + validateAfterInactivity.toMillis() <= System.currentTimeMillis()) { boolean stale; try {
final TimeValue timeValue = PoolingAsyncClientConnectionManager.this.validateAfterInactivity; if (TimeValue.isPositive(timeValue) && connection != null && poolEntry.getUpdated() + timeValue.toMillis() <= System.currentTimeMillis()) { final ProtocolVersion protocolVersion = connection.getProtocolVersion(); if (HttpVersion.HTTP_2_0.greaterEquals(protocolVersion)) {
@Test public void testBasics() throws Exception { final PoolEntry<String, HttpConnection> entry1 = new PoolEntry<>( "route1", TimeValue.of(10L, TimeUnit.MILLISECONDS), currentTimeSupplier); Assert.assertEquals("route1", entry1.getRoute()); Assert.assertEquals(0, entry1.getUpdated()); Assert.assertEquals(Deadline.MIN_VALUE, entry1.getExpiryDeadline()); entry1.assignConnection(Mockito.mock(HttpConnection.class)); final long now = System.currentTimeMillis(); Assert.assertEquals("route1", entry1.getRoute()); Assert.assertTrue(now >= entry1.getUpdated()); Assert.assertEquals(entry1.getValidityDeadline(), entry1.getExpiryDeadline()); Assert.assertEquals(entry1.getUpdated() + 10L, entry1.getValidityDeadline().getValue()); entry1.discardConnection(CloseMode.IMMEDIATE); Assert.assertEquals(0, entry1.getUpdated()); Assert.assertEquals(Deadline.MIN_VALUE, entry1.getExpiryDeadline()); }
@Test public void testExpiry() throws Exception { final PoolEntry<String, HttpConnection> entry1 = new PoolEntry<>( "route1", TimeValue.ZERO_MILLISECONDS, currentTimeSupplier); entry1.assignConnection(Mockito.mock(HttpConnection.class)); Assert.assertEquals(Deadline.MAX_VALUE, entry1.getExpiryDeadline()); entry1.updateExpiry(TimeValue.of(50L, TimeUnit.MILLISECONDS)); Assert.assertEquals(entry1.getUpdated() + 50L, entry1.getExpiryDeadline().getValue()); entry1.updateExpiry(TimeValue.ZERO_MILLISECONDS); Assert.assertEquals(Deadline.MAX_VALUE, entry1.getExpiryDeadline()); final PoolEntry<String, HttpConnection> entry2 = new PoolEntry<>( "route1", TimeValue.of(100L, TimeUnit.MILLISECONDS), currentTimeSupplier); entry2.assignConnection(Mockito.mock(HttpConnection.class)); final Deadline validityDeadline = entry2.getValidityDeadline(); Assert.assertEquals(entry2.getUpdated() + 100L, entry2.getExpiryDeadline().getValue()); entry2.updateExpiry(TimeValue.of(50L, TimeUnit.MILLISECONDS)); Assert.assertEquals(entry2.getUpdated() + 50L, entry2.getExpiryDeadline().getValue()); entry2.updateExpiry(TimeValue.of(150L, TimeUnit.MILLISECONDS)); Assert.assertEquals(validityDeadline, entry2.getExpiryDeadline()); }