@Override public void execute(final PoolEntry<T, C> entry) { if (entry.getExpiryDeadline().isBefore(now)) { entry.discardConnection(CloseMode.GRACEFUL); } }
@Override public void execute(final PoolEntry<T, C> entry) { if (entry.getExpiryDeadline().isBefore(now)) { entry.discardConnection(CloseMode.GRACEFUL); } }
@Override public void execute(final PoolEntry<T, C> entry) { if (entry.getExpiryDeadline().isBefore(now)) { entry.discardConnection(CloseMode.GRACEFUL); } }
@Override public void execute(final PoolEntry<T, C> entry) { if (entry.getExpiryDeadline().isBefore(now)) { entry.discardConnection(CloseMode.GRACEFUL); } }
private PoolEntry<T, C> getAvailableEntry(final Object state) { final PoolEntry<T, C> entry = available.poll(); if (entry != null) { if (entry.getExpiryDeadline().isExpired()) { entry.discardConnection(CloseMode.GRACEFUL); } if (!LangUtils.equals(entry.getState(), state)) { entry.discardConnection(CloseMode.GRACEFUL); } } return entry; }
private PoolEntry<T, C> getAvailableEntry(final Object state) { final PoolEntry<T, C> entry = available.poll(); if (entry != null) { if (entry.getExpiryDeadline().isExpired()) { entry.discardConnection(CloseMode.GRACEFUL); } if (!LangUtils.equals(entry.getState(), state)) { entry.discardConnection(CloseMode.GRACEFUL); } } return entry; }
public void release(final PoolEntry<T, C> releasedEntry, final boolean reusable) { removeLeased(releasedEntry); if (!reusable || releasedEntry.getExpiryDeadline().isExpired()) { releasedEntry.discardConnection(CloseMode.GRACEFUL);
public void release(final PoolEntry<T, C> releasedEntry, final boolean reusable) { removeLeased(releasedEntry); if (!reusable || releasedEntry.getExpiryDeadline().isExpired()) { releasedEntry.discardConnection(CloseMode.GRACEFUL);
break; if (entry.getExpiryDeadline().isExpired()) { entry.discardConnection(CloseMode.GRACEFUL); this.available.remove(entry);
break; if (entry.getExpiryDeadline().isExpired()) { entry.discardConnection(CloseMode.GRACEFUL); this.available.remove(entry);
@Test public void testValidInfinitely() 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.getValidityDeadline()); Assert.assertEquals(entry1.getValidityDeadline(), 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()); }
@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()); }