Skip to content
Permalink
Browse files
Getting a PooledObject's active duration returns a negative duration
when the object is borrowed but not returned. Affects:
- PooledObject.getActiveDuration()
- PooledObject.getActiveTime()
- PooledObject.getActiveTimeMillis()
  • Loading branch information
Gary Gregory committed Aug 12, 2021
1 parent 3f8c121 commit cfc1464a8a306c819ff186fd167b29b7c1552096
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 7 deletions.
@@ -148,6 +148,12 @@
<artifactId>junit-jupiter</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-library</artifactId>
<version>2.2</version>
<scope>test</scope>
</dependency>
</dependencies>

<distributionManagement>
@@ -16,8 +16,9 @@
*/
package org.apache.commons.pool2.impl;

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

import java.util.ArrayList;
import java.util.List;
@@ -40,8 +41,8 @@ public void testGetActiveDuration() throws InterruptedException {
Thread.sleep(200);
assertFalse(dpo.getActiveDuration().isNegative());
assertFalse(dpo.getActiveDuration().isZero());
assertEquals(dpo.getActiveDuration().toMillis(), dpo.getActiveTimeMillis());
assertEquals(dpo.getActiveDuration(), dpo.getActiveTime());
assertThat(dpo.getActiveDuration().toMillis(), lessThanOrEqualTo(dpo.getActiveTimeMillis()));
assertThat(dpo.getActiveDuration(), lessThanOrEqualTo(dpo.getActiveTime()));
}

/**
@@ -18,6 +18,8 @@
package org.apache.commons.pool2.impl;


import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.lessThanOrEqualTo;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotEquals;
@@ -1907,16 +1909,16 @@ public void testGetActiveDuration() throws Exception {
Thread.sleep(200);
assertFalse(dpo.getActiveDuration().isNegative());
assertFalse(dpo.getActiveDuration().isZero());
assertEquals(dpo.getActiveDuration().toMillis(), dpo.getActiveTimeMillis());
assertEquals(dpo.getActiveDuration(), dpo.getActiveTime());
assertThat(dpo.getActiveDuration().toMillis(), lessThanOrEqualTo(dpo.getActiveTimeMillis()));
assertThat(dpo.getActiveDuration(), lessThanOrEqualTo(dpo.getActiveTime()));

// Return
genericObjectPool.returnObject(object);

assertFalse(dpo.getActiveDuration().isNegative());
assertFalse(dpo.getActiveDuration().isZero());
assertEquals(dpo.getActiveDuration().toMillis(), dpo.getActiveTimeMillis());
assertEquals(dpo.getActiveDuration(), dpo.getActiveTime());
assertThat(dpo.getActiveDuration().toMillis(), lessThanOrEqualTo(dpo.getActiveTimeMillis()));
assertThat(dpo.getActiveDuration(), lessThanOrEqualTo(dpo.getActiveTime()));
}

@Test

0 comments on commit cfc1464

Please sign in to comment.