use of org.scale7.cassandra.pelops.pool.NoOpConnectionValidator in project scale7-pelops by s7.
the class CommonsBackedPoolIntegrationTest method testsScheduledTaskNodeSuspension.
/**
* Test that when a node is suspended all it's connections are terminated and that when it comes good it starts
* returning connections again.
*/
@Test
public void testsScheduledTaskNodeSuspension() throws Exception {
CommonsBackedPool.Policy config = new CommonsBackedPool.Policy();
// disable the background thread
config.setTimeBetweenScheduledMaintenanceTaskRunsMillis(-1);
config.setMaxActivePerNode(1);
final AtomicBoolean suspended = new AtomicBoolean(true);
CommonsBackedPool pool = new CommonsBackedPool(AbstractIntegrationTest.cluster, AbstractIntegrationTest.KEYSPACE, config, new OperandPolicy(), new LeastLoadedNodeSelectionStrategy(), new CommonsBackedPool.INodeSuspensionStrategy() {
@Override
public boolean evaluate(CommonsBackedPool pool, PooledNode node) {
if (suspended.get()) {
// first run through we want to suspend the node
suspended.set(false);
node.setSuspensionState(new CommonsBackedPool.INodeSuspensionState() {
@Override
public boolean isSuspended() {
return true;
}
});
return true;
} else {
// second run through we want the node active
node.setSuspensionState(new CommonsBackedPool.INodeSuspensionState() {
@Override
public boolean isSuspended() {
return false;
}
});
return false;
}
}
}, new NoOpConnectionValidator());
try {
// node not yet suspended
IThriftPool.IPooledConnection connection = pool.getConnection();
connection.release();
// suspend the node
pool.runMaintenanceTasks();
try {
pool.getConnection();
fail("No nodes should be available");
} catch (NoConnectionsAvailableException e) {
// expected
}
// activate the node
pool.runMaintenanceTasks();
// node is now active
connection = pool.getConnection();
connection.release();
} finally {
pool.shutdown();
}
}
use of org.scale7.cassandra.pelops.pool.NoOpConnectionValidator in project scale7-pelops by s7.
the class CommonsBackedPoolFactoryBeanIntegrationTest method testAfterProperties.
/**
* Tests the factory bean works as expected when operand or pool policy instances are provided.
* @throws Exception if an error occurs
*/
@Test
public void testAfterProperties() throws Exception {
OperandPolicy operandPolicy = new OperandPolicy();
CommonsBackedPool.Policy policy = new CommonsBackedPool.Policy();
LeastLoadedNodeSelectionStrategy nodeSelectionStrategy = new LeastLoadedNodeSelectionStrategy();
NoOpNodeSuspensionStrategy nodeSuspensionStrategy = new NoOpNodeSuspensionStrategy();
NoOpConnectionValidator connectionValidator = new NoOpConnectionValidator();
CommonsBackedPoolFactoryBean factoryBean = new CommonsBackedPoolFactoryBean();
factoryBean.setCluster(AbstractIntegrationTest.cluster);
factoryBean.setKeyspace(AbstractIntegrationTest.KEYSPACE);
factoryBean.setPolicy(policy);
factoryBean.setOperandPolicy(operandPolicy);
factoryBean.setNodeSelectionStrategy(nodeSelectionStrategy);
factoryBean.setNodeSuspensionStrategy(nodeSuspensionStrategy);
factoryBean.setConnectionValidator(connectionValidator);
assertNull("The factory should not have created the pool at this point", factoryBean.getObject());
try {
factoryBean.afterPropertiesSet();
CommonsBackedPool pool = (CommonsBackedPool) factoryBean.getObject();
assertNotNull("The factory didn't initialize the pool", pool);
assertTrue("The factory didn't use the provided operand policy instance", operandPolicy == pool.getOperandPolicy());
assertTrue("The factory didn't use the provided config instance", policy == pool.getPolicy());
assertTrue("The factory didn't use the provided config instance", cluster == pool.getCluster());
assertTrue("The factory didn't use the provided node selection instance", nodeSelectionStrategy == pool.getNodeSelectionStrategy());
assertTrue("The factory didn't use the provided node suspension instance", nodeSuspensionStrategy == pool.getNodeSuspensionStrategy());
assertTrue("The factory didn't use the provided connection validator instance", connectionValidator == pool.getConnectionValidator());
} finally {
factoryBean.destroy();
}
}
Aggregations