This is an automated email from the ASF dual-hosted git repository. ggregory pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/commons-pool.git
The following commit(s) were added to refs/heads/master by this push: new ce4a44e Add PooledObject.getFullDuration(). ce4a44e is described below commit ce4a44e56bbedca9ba54d7a0348067d97b3c4318 Author: Gary Gregory <gardgreg...@gmail.com> AuthorDate: Thu Aug 19 20:24:41 2021 -0400 Add PooledObject.getFullDuration(). --- pom.xml | 6 +++--- src/changes/changes.xml | 8 +++++++- src/main/java/org/apache/commons/pool2/PooledObject.java | 10 ++++++++++ .../commons/pool2/impl/TestDefaultPooledObject.java | 15 +++++++++++++++ 4 files changed, 35 insertions(+), 4 deletions(-) diff --git a/pom.xml b/pom.xml index 41ef845..9925b6e 100644 --- a/pom.xml +++ b/pom.xml @@ -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> diff --git a/src/changes/changes.xml b/src/changes/changes.xml index 4682ffc..edcab58 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -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: diff --git a/src/main/java/org/apache/commons/pool2/PooledObject.java b/src/main/java/org/apache/commons/pool2/PooledObject.java index ae55dad..ac1d4b3 100644 --- a/src/main/java/org/apache/commons/pool2/PooledObject.java +++ b/src/main/java/org/apache/commons/pool2/PooledObject.java @@ -149,6 +149,16 @@ public interface PooledObject<T> extends Comparable<PooledObject<T>> { 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 * return an increased value). diff --git a/src/test/java/org/apache/commons/pool2/impl/TestDefaultPooledObject.java b/src/test/java/org/apache/commons/pool2/impl/TestDefaultPooledObject.java index 4bf779c..9ae69b1 100644 --- a/src/test/java/org/apache/commons/pool2/impl/TestDefaultPooledObject.java +++ b/src/test/java/org/apache/commons/pool2/impl/TestDefaultPooledObject.java @@ -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 class TestDefaultPooledObject { 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 *