Skip to content

Commit

Permalink
Merge 86dcbed into 90eab32
Browse files Browse the repository at this point in the history
  • Loading branch information
Cp-John committed Nov 17, 2021
2 parents 90eab32 + 86dcbed commit 71e2625
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 71e2625

Please sign in to comment.