use of org.jboss.jca.core.connectionmanager.pool.mcp.ManagedConnectionPool in project wildfly by wildfly.
the class JcaTestsUtil method extractManagedConnectionPool.
/**
* Extract ManagedConnectionPool from ConnectionFactory by using reflection
*
* @param connectionFactory
* @return ManagedConnectionPool instance. <code>null</code> if not found
*/
public static ManagedConnectionPool extractManagedConnectionPool(Object connectionFactory) {
ConnectionManager cm = extractConnectionManager(connectionFactory);
// org.jboss.jca.core.connectionmanager.pool.strategy.OnePool
Object onePool = cm.getPool();
Class<?> clz = onePool.getClass();
// org.jboss.jca.core.connectionmanager.pool.AbstractPrefillPool
clz = clz.getSuperclass();
// org.jboss.jca.core.connectionmanager.pool.AbstractPool
clz = clz.getSuperclass();
try {
Method getManagedConnectionPools = clz.getDeclaredMethod("getManagedConnectionPools");
getManagedConnectionPools.setAccessible(true);
ConcurrentMap<Object, ManagedConnectionPool> mcps = (ConcurrentMap<Object, ManagedConnectionPool>) getManagedConnectionPools.invoke(onePool);
return mcps.values().iterator().next();
} catch (Throwable t) {
fail(t.getMessage());
}
return null;
}
use of org.jboss.jca.core.connectionmanager.pool.mcp.ManagedConnectionPool in project wildfly by wildfly.
the class ResourceAdapterCapacityPoliciesTestCase method testNonDefaultDecrementerAndIncrementer.
/**
* Test pool with
* org.jboss.jca.core.connectionmanager.pool.capacity.MinPoolSizeDecrementer
* org.jboss.jca.core.connectionmanager.pool.capacity.MaxPoolSizeIncrementer"
*
* @throws Exception
*/
@Test
public void testNonDefaultDecrementerAndIncrementer() throws Exception {
checkStatistics(5, 0, 0, 0);
LazyConnection[] connections = new LazyConnection[4];
connections[0] = lcf.getConnection();
// sometimes InUseCount is 2 and AvailableCount is 3 when statistics are checked right after
// ds.getConnection, hence this sleep. I guess it's caused by CapacityFiller
Thread.sleep(50);
checkStatistics(4, 1, 5, 0);
connections[1] = lcf.getConnection();
checkStatistics(3, 2, 5, 0);
connections[2] = lcf.getConnection();
checkStatistics(2, 3, 5, 0);
connections[3] = lcf.getConnection();
checkStatistics(1, 4, 5, 0);
for (int i = 0; i < 4; i++) {
LazyConnection c = connections[i];
c.close();
}
ManagedConnectionPool mcp = JcaTestsUtil.extractManagedConnectionPool(lcf);
JcaTestsUtil.callRemoveIdleConnections(mcp);
checkStatistics(5, 0, 2, 3);
}
use of org.jboss.jca.core.connectionmanager.pool.mcp.ManagedConnectionPool in project wildfly by wildfly.
the class AbstractDatasourceCapacityPoliciesTestCase method testNonDefaultDecrementerAndIncrementer.
/**
* Test pool with
* org.jboss.jca.core.connectionmanager.pool.capacity.MinPoolSizeDecrementer
* org.jboss.jca.core.connectionmanager.pool.capacity.MaxPoolSizeIncrementer"
*
* @throws Exception
*/
@Test
public void testNonDefaultDecrementerAndIncrementer() throws Exception {
checkStatistics(5, 0, 0, 0);
Connection[] connections = new Connection[4];
connections[0] = ds.getConnection();
// sometimes InUseCount is 2 and AvailableCount is 3 when statistics are checked right after
// ds.getConnection, hence this sleep. I guess it's caused by CapacityFiller
Thread.sleep(500);
checkStatistics(4, 1, 5, 0);
connections[1] = ds.getConnection();
checkStatistics(3, 2, 5, 0);
connections[2] = ds.getConnection();
checkStatistics(2, 3, 5, 0);
connections[3] = ds.getConnection();
checkStatistics(1, 4, 5, 0);
for (int i = 0; i < 4; i++) {
Connection c = connections[i];
c.close();
}
WrapperDataSource wsds = JcaTestsUtil.extractWrapperDatasource((WildFlyDataSource) ds);
ManagedConnectionPool mcp = JcaTestsUtil.extractManagedConnectionPool(wsds);
JcaTestsUtil.callRemoveIdleConnections(mcp);
checkStatistics(5, 0, 2, 3);
}
Aggregations