Search in sources :

Example 1 with ManagedConnectionPool

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;
}
Also used : ConnectionManager(org.jboss.jca.core.connectionmanager.ConnectionManager) ConcurrentMap(java.util.concurrent.ConcurrentMap) Method(java.lang.reflect.Method) ManagedConnectionPool(org.jboss.jca.core.connectionmanager.pool.mcp.ManagedConnectionPool)

Example 2 with ManagedConnectionPool

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);
}
Also used : LazyConnection(org.jboss.as.test.integration.jca.lazyconnectionmanager.rar.LazyConnection) ManagedConnectionPool(org.jboss.jca.core.connectionmanager.pool.mcp.ManagedConnectionPool) Test(org.junit.Test)

Example 3 with ManagedConnectionPool

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);
}
Also used : Connection(java.sql.Connection) ManagedConnectionPool(org.jboss.jca.core.connectionmanager.pool.mcp.ManagedConnectionPool) WrapperDataSource(org.jboss.jca.adapters.jdbc.WrapperDataSource) Test(org.junit.Test)

Aggregations

ManagedConnectionPool (org.jboss.jca.core.connectionmanager.pool.mcp.ManagedConnectionPool)3 Test (org.junit.Test)2 Method (java.lang.reflect.Method)1 Connection (java.sql.Connection)1 ConcurrentMap (java.util.concurrent.ConcurrentMap)1 LazyConnection (org.jboss.as.test.integration.jca.lazyconnectionmanager.rar.LazyConnection)1 WrapperDataSource (org.jboss.jca.adapters.jdbc.WrapperDataSource)1 ConnectionManager (org.jboss.jca.core.connectionmanager.ConnectionManager)1