Search in sources :

Example 1 with DeadlineTimeoutException

use of org.apache.hc.core5.util.DeadlineTimeoutException in project httpcomponents-core by apache.

the class TestStrictConnPool method testLeaseRequestLockTimeout.

@Test
public void testLeaseRequestLockTimeout() throws Exception {
    final StrictConnPool<String, HttpConnection> pool = new StrictConnPool<>(1, 1);
    final CountDownLatch lockHeld = new CountDownLatch(1);
    final Thread holdInternalLock = new HoldInternalLockThread(pool, lockHeld);
    // Start a thread to grab the internal conn pool lock
    holdInternalLock.start();
    // Wait until we know the internal lock is held
    lockHeld.await();
    // Attempt to get a connection while lock is held
    final Future<PoolEntry<String, HttpConnection>> future2 = pool.lease("somehost", null, Timeout.ofMilliseconds(10), null);
    final ExecutionException executionException = Assertions.assertThrows(ExecutionException.class, () -> future2.get());
    Assertions.assertTrue(executionException.getCause() instanceof DeadlineTimeoutException);
    // Cleanup
    holdInternalLock.interrupt();
}
Also used : DeadlineTimeoutException(org.apache.hc.core5.util.DeadlineTimeoutException) HttpConnection(org.apache.hc.core5.http.HttpConnection) CountDownLatch(java.util.concurrent.CountDownLatch) ExecutionException(java.util.concurrent.ExecutionException) Test(org.junit.jupiter.api.Test)

Aggregations

CountDownLatch (java.util.concurrent.CountDownLatch)1 ExecutionException (java.util.concurrent.ExecutionException)1 HttpConnection (org.apache.hc.core5.http.HttpConnection)1 DeadlineTimeoutException (org.apache.hc.core5.util.DeadlineTimeoutException)1 Test (org.junit.jupiter.api.Test)1