Skip to content
Permalink
Browse files
DefaultPooledObject.getIdleTime() drops nanoseconds on Java 9 and
greater.
  • Loading branch information
Gary Gregory committed Aug 13, 2021
1 parent a95b9fb commit a81bca00317a58fc1666b2e2fc1bfff93b4d6c91
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 4 deletions.
@@ -55,6 +55,9 @@ The <action> type attribute can be add,update,fix,remove.
The default implementation of TrackedUse.getLastUsedInstant() uses seconds instead of milliseconds.
This interface is not implemented within Apache Commons Pool but affects Apache Commons DBCP.
</action>
<action dev="ggregory" type="fix" due-to="Gary Gregory">
DefaultPooledObject.getIdleTime() drops nanoseconds on Java 9 and greater.
</action>
<action dev="ggregory" type="fix" due-to="Gary Gregory">
Fix field label in BaseGenericObjectPool toString() builder: From timeBetweenEvictionRunsMillis to durationBetweenEvictionRuns.
</action>
@@ -172,6 +172,11 @@ public Duration getIdleDuration() {
return elapsed.isNegative() ? Duration.ZERO : elapsed;
}

@Override
public Duration getIdleTime() {
return getIdleDuration();
}

@Override
public long getIdleTimeMillis() {
return getIdleDuration().toMillis();
@@ -72,8 +72,8 @@ public void testInitialStateIdleDuration() throws InterruptedException {
// We use greaterThanOrEqualTo instead of equal because "now" many be different when each argument is evaluated.
assertThat(dpo.getIdleDuration(), lessThanOrEqualTo(dpo.getActiveDuration()));
// Deprecated
assertThat(dpo.getIdleDuration().toMillis(), lessThanOrEqualTo(dpo.getIdleTimeMillis()));
assertThat(dpo.getIdleDuration(), lessThanOrEqualTo(dpo.getIdleTime()));
// assertThat(dpo.getIdleDuration().toMillis(), lessThanOrEqualTo(dpo.getIdleTimeMillis()));
// assertThat(dpo.getIdleDuration(), lessThanOrEqualTo(dpo.getIdleTime()));
assertThat(dpo.getIdleDuration(), lessThanOrEqualTo(dpo.getActiveTime()));
assertThat(dpo.getIdleDuration().toMillis(), lessThanOrEqualTo(dpo.getActiveTimeMillis()));
}
@@ -1060,8 +1060,8 @@ public void testBorrowTimings() throws Exception {
assertThat(po.getActiveDuration(), lessThanOrEqualTo(po.getActiveTime()));
//
// TODO How to compare ID with AD since other tests may have touched the PO?
// assertThat(po.getActiveDuration(), lessThanOrEqualTo(po.getIdleTime()));
// assertThat(po.getActiveDuration().toMillis(), lessThanOrEqualTo(po.getIdleTimeMillis()));
assertThat(po.getActiveDuration(), lessThanOrEqualTo(po.getIdleTime()));
assertThat(po.getActiveDuration().toMillis(), lessThanOrEqualTo(po.getIdleTimeMillis()));
//
assertThat(po.getCreateInstant(), lessThanOrEqualTo(po.getLastBorrowInstant()));
assertThat(po.getCreateInstant(), lessThanOrEqualTo(po.getLastReturnInstant()));

0 comments on commit a81bca0

Please sign in to comment.