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 b57da6c1 Refactor test to use Durations instead of magic numbers
b57da6c1 is described below
commit b57da6c175e631592665402b9b6bccf21e7390ed
Author: Gary Gregory <[email protected]>
AuthorDate: Sun Dec 1 15:55:22 2024 -0500
Refactor test to use Durations instead of magic numbers
---
.../commons/pool3/impl/TestGenericObjectPool.java | 26 +++++++++++-----------
1 file changed, 13 insertions(+), 13 deletions(-)
diff --git
a/src/test/java/org/apache/commons/pool3/impl/TestGenericObjectPool.java
b/src/test/java/org/apache/commons/pool3/impl/TestGenericObjectPool.java
index 94ee7a57..3c78fca6 100644
--- a/src/test/java/org/apache/commons/pool3/impl/TestGenericObjectPool.java
+++ b/src/test/java/org/apache/commons/pool3/impl/TestGenericObjectPool.java
@@ -51,6 +51,7 @@ import java.util.concurrent.atomic.AtomicInteger;
import javax.management.MBeanServer;
import javax.management.ObjectName;
+import org.apache.commons.lang3.ThreadUtils;
import org.apache.commons.lang3.time.DurationUtils;
import org.apache.commons.pool3.BasePooledObjectFactory;
import org.apache.commons.pool3.ObjectPool;
@@ -819,7 +820,7 @@ public class TestGenericObjectPool extends
TestBaseObjectPool {
}
private BasePooledObjectFactory<String, RuntimeException>
createDefaultPooledObjectFactory() {
- return new BasePooledObjectFactory<String, RuntimeException>() {
+ return new BasePooledObjectFactory<>() {
@Override
public String create() {
// fake
@@ -835,7 +836,7 @@ public class TestGenericObjectPool extends
TestBaseObjectPool {
}
private BasePooledObjectFactory<String, RuntimeException>
createNullPooledObjectFactory() {
- return new BasePooledObjectFactory<String, RuntimeException>() {
+ return new BasePooledObjectFactory<>() {
@Override
public String create() {
// fake
@@ -850,12 +851,11 @@ public class TestGenericObjectPool extends
TestBaseObjectPool {
};
}
- private BasePooledObjectFactory<String, InterruptedException>
createSlowObjectFactory(
- final long elapsedTimeMillis) {
- return new BasePooledObjectFactory<String, InterruptedException>() {
+ private BasePooledObjectFactory<String, InterruptedException>
createSlowObjectFactory(final Duration sleepDuration) {
+ return new BasePooledObjectFactory<>() {
@Override
public String create() throws InterruptedException {
- Thread.sleep(elapsedTimeMillis);
+ ThreadUtils.sleep(sleepDuration);
return "created";
}
@@ -1074,7 +1074,7 @@ public class TestGenericObjectPool extends
TestBaseObjectPool {
@Test/* maxWaitMillis x2 + padding */
@Timeout(value = 1200, unit = TimeUnit.MILLISECONDS)
public void testBorrowObjectOverrideMaxWaitLarge() throws Exception {
- try (final GenericObjectPool<String, InterruptedException> pool = new
GenericObjectPool<>(createSlowObjectFactory(60_000))) {
+ try (final GenericObjectPool<String, InterruptedException> pool = new
GenericObjectPool<>(createSlowObjectFactory(Duration.ofSeconds(60)))) {
pool.setMaxTotal(1);
pool.setMaxWait(Duration.ofMillis(1_000)); // large
pool.setBlockWhenExhausted(false);
@@ -1097,7 +1097,7 @@ public class TestGenericObjectPool extends
TestBaseObjectPool {
@Test/* maxWaitMillis x2 + padding */
@Timeout(value = 1200, unit = TimeUnit.MILLISECONDS)
public void testBorrowObjectOverrideMaxWaitSmall() throws Exception {
- try (final GenericObjectPool<String, InterruptedException> pool = new
GenericObjectPool<>(createSlowObjectFactory(60_000))) {
+ try (final GenericObjectPool<String, InterruptedException> pool = new
GenericObjectPool<>(createSlowObjectFactory(Duration.ofSeconds(60)))) {
pool.setMaxTotal(1);
pool.setMaxWait(Duration.ofMillis(1)); // small
pool.setBlockWhenExhausted(false);
@@ -1178,7 +1178,7 @@ public class TestGenericObjectPool extends
TestBaseObjectPool {
/**
* On first borrow, first object fails validation, second object is OK.
* Subsequent borrows are OK. This was POOL-152.
- *
+ *
* @throws Exception
*/
@Test
@@ -2652,7 +2652,7 @@ public class TestGenericObjectPool extends
TestBaseObjectPool {
/**
* Verify that when a factory returns a null object, pool methods throw
NPE.
- *
+ *
* @throws InterruptedException
*/
@Test
@@ -2693,7 +2693,7 @@ public class TestGenericObjectPool extends
TestBaseObjectPool {
@Timeout(value = 1200, unit = TimeUnit.MILLISECONDS)
public void testReturnBorrowObjectWithingMaxWaitDuration() throws
Exception {
final Duration maxWaitDuration = Duration.ofMillis(500);
- try (final GenericObjectPool<String, InterruptedException>
createSlowObjectFactoryPool = new
GenericObjectPool<>(createSlowObjectFactory(60_000))) {
+ try (final GenericObjectPool<String, InterruptedException>
createSlowObjectFactoryPool = new
GenericObjectPool<>(createSlowObjectFactory(Duration.ofSeconds(60)))) {
createSlowObjectFactoryPool.setMaxTotal(1);
createSlowObjectFactoryPool.setMaxWait(maxWaitDuration);
// thread1 tries creating a slow object to make pool full.
@@ -2707,12 +2707,12 @@ public class TestGenericObjectPool extends
TestBaseObjectPool {
assertTrue(thread1.isAlive());
}
}
-
+
@Test /* maxWaitMillis x2 + padding */
@Timeout(value = 1200, unit = TimeUnit.MILLISECONDS)
public void testReturnBorrowObjectWithingMaxWaitMillis() throws Exception {
final long maxWaitMillis = 500;
- try (final GenericObjectPool<String, InterruptedException>
createSlowObjectFactoryPool = new
GenericObjectPool<>(createSlowObjectFactory(60000))) {
+ try (final GenericObjectPool<String, InterruptedException>
createSlowObjectFactoryPool = new
GenericObjectPool<>(createSlowObjectFactory(Duration.ofSeconds(60)))) {
createSlowObjectFactoryPool.setMaxTotal(1);
createSlowObjectFactoryPool.setMaxWait(Duration.ofMillis(maxWaitMillis));
// thread1 tries creating a slow object to make pool full.