Skip to content

Commit

Permalink
Add tests for ManagedPool#getCurrentAllocatedCount and getCurrentInUs…
Browse files Browse the repository at this point in the history
…eCount
  • Loading branch information
chrisvest committed Jun 2, 2024
1 parent dd1fd2d commit aee9fe3
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/main/java/stormpot/AllocationController.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,12 @@ abstract class AllocationController<T extends Poolable> {
abstract long countLeakedObjects();

/**
* @see ManagedPool#getAllocatedSize()
* @see ManagedPool#getCurrentAllocatedCount()
*/
abstract int allocatedSize();

/**
* @see ManagedPool#getInUse()
* @see ManagedPool#getCurrentInUseCount()
*/
abstract int inUse();
}
4 changes: 2 additions & 2 deletions src/main/java/stormpot/BlazePool.java
Original file line number Diff line number Diff line change
Expand Up @@ -379,12 +379,12 @@ public long getLeakedObjectsCount() {
}

@Override
public int getAllocatedSize() {
public int getCurrentAllocatedCount() {
return allocator.allocatedSize();
}

@Override
public int getInUse() {
public int getCurrentInUseCount() {
return allocator.inUse();
}
}
7 changes: 5 additions & 2 deletions src/main/java/stormpot/ManagedPool.java
Original file line number Diff line number Diff line change
Expand Up @@ -190,9 +190,12 @@ public interface ManagedPool {
*
* The default implementation of this interface methods returns {@code -1}.
*
* Unlike {@link #getAllocationCount()}, this returns only the number of objects currently in the pool,
* which typically would be the same as {@link #getTargetSize()}.
*
* @return The current approximate number of allocated objects.
*/
default int getAllocatedSize() {
default int getCurrentAllocatedCount() {
return -1;
}

Expand All @@ -208,7 +211,7 @@ default int getAllocatedSize() {
*
* @return number of objects currently in use
*/
default int getInUse() {
default int getCurrentInUseCount() {
return -1;
}
}
12 changes: 12 additions & 0 deletions src/test/java/blackbox/AbstractPoolTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -913,6 +913,18 @@ void managedPoolMustGivePoolState() throws Exception {
assertTrue(managedPool.isShutDown());
}

@Test
void managedPoolMustGiveNumberOfAllocatedAndInUseObjects() throws Exception {
createOneObjectPool();
pool.claim(longTimeout).release(); // Ensure the single object is allocated
ManagedPool managedPool = pool.getManagedPool();
assertThat(managedPool.getCurrentAllocatedCount()).isOne();
assertThat(managedPool.getCurrentInUseCount()).isZero();
T obj = pool.claim(longTimeout);
assertThat(managedPool.getCurrentInUseCount()).isOne();
obj.release();
}

@ParameterizedTest
@EnumSource(Taps.class)
void applyMustThrowOnNullTimeout(Taps taps) {
Expand Down

0 comments on commit aee9fe3

Please sign in to comment.