Skip to content
Merged
Show file tree
Hide file tree
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 @@ -25,6 +25,11 @@ public interface PoolStatus {
*/
int busy();

/**
* Return total number of free + busy connections in the pool.
*/
int size();

/**
* Return the number of threads waiting for connections.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -934,6 +934,11 @@ public int busy() {
return busy;
}

@Override
public int size() {
return free + busy;
}

@Override
public int waiting() {
return waiting;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,42 @@ void getConnection_expect_poolGrowsAboveMin() throws SQLException {
assertThat(status.maxSize()).isEqualTo(4);
}

@Test
void status_size_isBusyPlusFree() throws SQLException {
PoolStatus initial = pool.status(false);
assertThat(initial.size()).isEqualTo(initial.busy() + initial.free());

Connection con1 = pool.getConnection();
Connection con2 = pool.getConnection();
Connection con3 = pool.getConnection();

PoolStatus allBusy = pool.status(false);
assertThat(allBusy.busy()).isEqualTo(3);
assertThat(allBusy.free()).isEqualTo(0);
assertThat(allBusy.size()).isEqualTo(3);
assertThat(allBusy.size()).isEqualTo(allBusy.busy() + allBusy.free());

con2.rollback();
con2.close();

PoolStatus mixed = pool.status(false);
assertThat(mixed.busy()).isEqualTo(2);
assertThat(mixed.free()).isEqualTo(1);
assertThat(mixed.size()).isEqualTo(3);
assertThat(mixed.size()).isEqualTo(mixed.busy() + mixed.free());

con1.rollback();
con1.close();
con3.rollback();
con3.close();

PoolStatus allFree = pool.status(false);
assertThat(allFree.busy()).isEqualTo(0);
assertThat(allFree.free()).isEqualTo(3);
assertThat(allFree.size()).isEqualTo(3);
assertThat(allFree.size()).isEqualTo(allFree.busy() + allFree.free());
}

@Test
void getConnection_explicitUserPassword() throws SQLException {
Connection connection = pool.getConnection("sa", "");
Expand Down
Loading