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;
}
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());
}
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);
}
Aggregations