Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,39 @@ void testReleaseReusableAndClosedInCacheReturnedToPool() throws Exception {
Mockito.eq(true));
}

/**
* Same connection can only be released once.
* Attempting to release it again will throw: IllegalStateException("Pool entry is not present in the set of leased entries")
*
* @see org.apache.hc.core5.pool.LaxConnPool.PerRoutePool#removeLeased(PoolEntry)
* @see org.apache.hc.core5.pool.StrictConnPool#release(PoolEntry, boolean)
*/
@Test
void testReleaseNonReusableNotInCacheReturnedToPool() throws Exception {
final PoolEntry<String, HttpConnection> poolEntry = new PoolEntry<>(DEFAULT_ROUTE);
poolEntry.assignConnection(connection);
Mockito.when(connection.isOpen()).thenReturn(false);
final H2SharingConnPool.PerRoutePool<String, HttpConnection> routePool = h2SharingPool.getPerRoutePool(DEFAULT_ROUTE);
routePool.track(poolEntry);
routePool.track(poolEntry);

final AtomicReference<HttpConnection> connRef = new AtomicReference<>(connection);
Mockito.doAnswer(invocation -> {
final PoolEntry<String, HttpConnection> entry = invocation.getArgument(0);
if (!connRef.compareAndSet(entry.getConnection(), null)){
throw new IllegalStateException("Pool entry is not present in the set of leased entries");
}
return null;
}).when(connPool).release(Mockito.eq(poolEntry), Mockito.anyBoolean());

h2SharingPool.release(poolEntry, false);
h2SharingPool.release(poolEntry, false);

Mockito.verify(connPool).release(
Mockito.same(poolEntry),
Mockito.eq(false));
}

@Test
void testClose() throws Exception {
h2SharingPool.close();
Expand Down