Skip to content
Permalink
Browse files
Add PooledObject.getFullDuration().
  • Loading branch information
Gary Gregory committed Aug 20, 2021
1 parent 9564d3e commit ce4a44e56bbedca9ba54d7a0348067d97b3c4318
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 4 deletions.
@@ -28,7 +28,7 @@
</parent>

<artifactId>commons-pool2</artifactId>
<version>2.11.2-SNAPSHOT</version>
<version>2.12.0-SNAPSHOT</version>
<name>Apache Commons Pool</name>

<inceptionYear>2001</inceptionYear>
@@ -174,7 +174,7 @@
<commons.module.name>org.apache.commons.pool2</commons.module.name>
<commons.rc.version>RC1</commons.rc.version>
<!-- Java 8 -->
<commons.release.version>2.11.1</commons.release.version>
<commons.release.version>2.12.0</commons.release.version>
<commons.release.desc>(Java 8)</commons.release.desc>
<!-- Java 7 -->
<commons.release.2.version>2.6.2</commons.release.2.version>
@@ -200,7 +200,7 @@
<spotbugs.impl.version>4.3.0</spotbugs.impl.version>

<!-- Commons Release Plugin -->
<commons.bc.version>2.11.0</commons.bc.version>
<commons.bc.version>2.11.1</commons.bc.version>
<commons.release.isDistModule>true</commons.release.isDistModule>
<commons.releaseManagerName>Gary Gregory</commons.releaseManagerName>
<commons.releaseManagerKey>86fdc7e2a11262cb</commons.releaseManagerKey>
@@ -43,7 +43,13 @@ The <action> type attribute can be add,update,fix,remove.
<title>Apache Commons Pool Release Notes</title>
</properties>
<body>
<release version="2.11.1" date="2021-08-DD" description="This is a maintenance release (Java 8).">
<release version="2.12.0" date="2021-MM-DD" description="This is a maintenance release (Java 8).">
<!-- ADD -->
<action dev="ggregory" type="add" due-to="Gary Gregory">
Add PooledObject.getFullDuration().
</action>
</release>
<release version="2.11.1" date="2021-08-18" description="This is a maintenance release (Java 8).">
<!-- FIXES -->
<action dev="ggregory" type="fix" due-to="Gary Gregory">
Getting a PooledObject's active duration returns a negative duration when the object is borrowed but not returned. Affects:
@@ -148,6 +148,16 @@ default Instant getCreateInstant() {
@Deprecated
long getCreateTime();

/**
* Computes the duration since this object was created (using {@link Instant#now()}).
*
* @return The duration since this object was created.
* @since 2.12.0
*/
default Duration getFullDuration() {
return Duration.between(getCreateInstant(), Instant.now());
}

/**
* Gets the amount of time that this object last spend in the
* idle state (it may still be idle in which case subsequent calls will
@@ -17,8 +17,10 @@
package org.apache.commons.pool2.impl;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.lessThan;
import static org.hamcrest.Matchers.lessThanOrEqualTo;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertFalse;

import java.time.Duration;
@@ -98,6 +100,19 @@ public void testInitialStateCreateInstant() throws InterruptedException {
assertEquals(dpo.getCreateTime(), dpo.getLastUsedTime());
}

@Test
public void testInitialStateDuration() throws InterruptedException {
final PooledObject<Object> dpo = new DefaultPooledObject<>(new Object());
final Duration duration1 = dpo.getFullDuration();
assertNotNull(duration1);
assertFalse(duration1.isNegative());
Thread.sleep(100);
final Duration duration2 = dpo.getFullDuration();
assertNotNull(duration2);
assertFalse(duration2.isNegative());
assertThat(duration1, lessThan(duration2));
}

/**
* JIRA: POOL-279
*

0 comments on commit ce4a44e

Please sign in to comment.