Search in sources :

Example 1 with WrapperDataSource

use of org.jboss.jca.adapters.jdbc.WrapperDataSource in project wildfly by wildfly.

the class JcaTestsUtil method extractWrapperDatasource.

/**
     * Extract WrapperDataSource from WildflyDataSource by using reflection
     *
     * @param wfds
     * @return WrapperDataSource instance, <code>null</code> if not found
     */
public static WrapperDataSource extractWrapperDatasource(WildFlyDataSource wfds) {
    Class clazz = wfds.getClass();
    try {
        Field delegate = clazz.getDeclaredField("delegate");
        delegate.setAccessible(true);
        return (WrapperDataSource) delegate.get(wfds);
    } catch (Throwable t) {
    //
    }
    return null;
}
Also used : Field(java.lang.reflect.Field) WrapperDataSource(org.jboss.jca.adapters.jdbc.WrapperDataSource)

Example 2 with WrapperDataSource

use of org.jboss.jca.adapters.jdbc.WrapperDataSource in project wildfly by wildfly.

the class DatasourcePoolAttributesTestCase method testModifyNonReloadAttributes.

/**
     * Checks that attributes not requiring reload can be set.
     */
@Test
public void testModifyNonReloadAttributes() throws Exception {
    WrapperDataSource wrapperDataSource = JcaTestsUtil.extractWrapperDatasource((WildFlyDataSource) datasource);
    PoolConfiguration poolConfiguration = JcaTestsUtil.exctractPoolConfiguration(wrapperDataSource);
    // check initial values
    Assert.assertNotNull(poolConfiguration);
    Assert.assertEquals(0, poolConfiguration.getMinSize());
    Assert.assertEquals(20, poolConfiguration.getMaxSize());
    Assert.assertEquals(0, poolConfiguration.getInitialSize());
    Assert.assertEquals(30000, poolConfiguration.getBlockingTimeout());
    Assert.assertEquals(true, poolConfiguration.isFair());
    Assert.assertEquals(false, poolConfiguration.isStrictMin());
    // modify values
    writeAttribute(DS_ADDRESS, Constants.MIN_POOL_SIZE.getName(), "4");
    writeAttribute(DS_ADDRESS, Constants.MAX_POOL_SIZE.getName(), "10");
    writeAttribute(DS_ADDRESS, Constants.INITIAL_POOL_SIZE.getName(), "6");
    writeAttribute(DS_ADDRESS, Constants.BLOCKING_TIMEOUT_WAIT_MILLIS.getName(), "10000");
    writeAttribute(DS_ADDRESS, Constants.POOL_FAIR.getName(), "false");
    writeAttribute(DS_ADDRESS, Constants.POOL_USE_STRICT_MIN.getName(), "true");
    // check that server is not in reload-required state
    ModelNode serverState = readAttribute(new ModelNode(), "server-state");
    Assert.assertEquals("running", serverState.asString());
    // check that runtime was updated
    Assert.assertEquals(4, poolConfiguration.getMinSize());
    Assert.assertEquals(10, poolConfiguration.getMaxSize());
    Assert.assertEquals(6, poolConfiguration.getInitialSize());
    Assert.assertEquals(10000, poolConfiguration.getBlockingTimeout());
    Assert.assertEquals(false, poolConfiguration.isFair());
    Assert.assertEquals(true, poolConfiguration.isStrictMin());
}
Also used : PoolConfiguration(org.jboss.jca.core.api.connectionmanager.pool.PoolConfiguration) ModelNode(org.jboss.dmr.ModelNode) WrapperDataSource(org.jboss.jca.adapters.jdbc.WrapperDataSource) Test(org.junit.Test)

Example 3 with WrapperDataSource

use of org.jboss.jca.adapters.jdbc.WrapperDataSource 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

WrapperDataSource (org.jboss.jca.adapters.jdbc.WrapperDataSource)3 Test (org.junit.Test)2 Field (java.lang.reflect.Field)1 Connection (java.sql.Connection)1 ModelNode (org.jboss.dmr.ModelNode)1 PoolConfiguration (org.jboss.jca.core.api.connectionmanager.pool.PoolConfiguration)1 ManagedConnectionPool (org.jboss.jca.core.connectionmanager.pool.mcp.ManagedConnectionPool)1