Skip to content
Permalink
Browse files
[POOL-402] Check blockWhenExhausted in hasBorrowWaiters (#116)
* Check blockWhenExhausted in hasBorrowWaiters

* Add jacoco plugin

* Add unite tests for getBlockWhenExhausted in hasBorrowWaiters

* Restore pom file
  • Loading branch information
Cp-John committed Dec 1, 2021
1 parent a12ff25 commit 22868002d800cd19600e06c9d2c599fe0e04a453
Showing 2 changed files with 30 additions and 1 deletion.
@@ -1280,7 +1280,7 @@ String getStatsString() {
* {@code false}
*/
private boolean hasBorrowWaiters() {
return poolMap.values().stream().anyMatch(deque -> deque != null && deque.getIdleObjects().hasTakeWaiters());
return getBlockWhenExhausted() && poolMap.values().stream().anyMatch(deque -> deque != null && deque.getIdleObjects().hasTakeWaiters());
}

/**
@@ -2608,6 +2608,35 @@ public void testInvalidateFreesCapacityForOtherKeys() throws Exception {
assertFalse(borrower.isAlive());
}

@Test
public void testReturnObjectWithBlockWhenExhausted() throws Exception {
gkoPool.setBlockWhenExhausted(true);
gkoPool.setMaxTotal(1);

// Test return object with no take waiters
String obj = gkoPool.borrowObject("0");
gkoPool.returnObject("0", obj);

// Test return object with a take waiter
final TestThread<String> testA = new TestThread<>(gkoPool, 1, 0, 500, false, null, "0");
final TestThread<String> testB = new TestThread<>(gkoPool, 1, 0, 0, false, null, "1");
final Thread threadA = new Thread(testA);
final Thread threadB = new Thread(testB);
threadA.start();
threadB.start();
threadA.join();
threadB.join();
}

@Test
public void testReturnObjectWithoutBlockWhenExhausted() throws Exception {
gkoPool.setBlockWhenExhausted(false);

// Test return object with no take waiters
String obj = gkoPool.borrowObject("0");
gkoPool.returnObject("0", obj);
}

}


0 comments on commit 2286800

Please sign in to comment.