Skip to content
Permalink
Browse files
Don't use reflection.
  • Loading branch information
Gary Gregory committed Sep 2, 2021
1 parent 50fb382 commit 71d5835288ed7a45a84bb4761a568dd92f66d6a4
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
@@ -153,6 +153,11 @@ static synchronized void cancel(final BaseGenericObjectPool<?>.Evictor evictor,
}
}

/** For testing only. */
static ScheduledThreadPoolExecutor getExecutor() {
return executor;
}

/**
* @return the number of eviction tasks under management.
*/
@@ -929,8 +929,7 @@ public void tearDown() throws Exception {
simpleFactory = null;

final MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
final Set<ObjectName> result = mbs.queryNames(new ObjectName(
"org.apache.commoms.pool2:type=GenericObjectPool,*"), null);
final Set<ObjectName> result = mbs.queryNames(new ObjectName("org.apache.commoms.pool2:type=GenericObjectPool,*"), null);
// There should be no registered pools at this point
final int registeredPoolCount = result.size();
final StringBuilder msg = new StringBuilder("Current pool is: ");
@@ -944,12 +943,14 @@ public void tearDown() throws Exception {
msg.append('\n');
mbs.unregisterMBean(name);
}
assertEquals( 0, registeredPoolCount,msg.toString());
assertEquals(0, registeredPoolCount, msg.toString());

// Make sure that EvictionTimer executor is shut down
final Field evictorExecutorField = EvictionTimer.class.getDeclaredField("executor");
evictorExecutorField.setAccessible(true);
assertNull(evictorExecutorField.get(null));
// Make sure that EvictionTimer executor is shut down.
Thread.yield();
if (EvictionTimer.getExecutor() != null) {
Thread.sleep(1000);
}
assertNull(EvictionTimer.getExecutor(), "EvictionTimer.getExecutor()");
}

/**

0 comments on commit 71d5835

Please sign in to comment.