Search in sources :

Example 6 with CommonsBackedPool

use of org.scale7.cassandra.pelops.pool.CommonsBackedPool in project scale7-pelops by s7.

the class CommonsBackedPoolFactoryBeanIntegrationTest method testAfterPropertiesSetSimpleUseCase.

/**
     * Tests the factory bean works as expected when no operand or pool policy are specified.
     * @throws Exception if an error occurs
     */
@Test
public void testAfterPropertiesSetSimpleUseCase() throws Exception {
    CommonsBackedPoolFactoryBean factoryBean = new CommonsBackedPoolFactoryBean();
    factoryBean.setCluster(AbstractIntegrationTest.cluster);
    factoryBean.setKeyspace(AbstractIntegrationTest.KEYSPACE);
    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);
        assertNotNull("The factory didn't initialize a default operand policy instance", pool.getOperandPolicy());
        assertNotNull("The factory didn't initialize a default pool config instance", pool.getPolicy());
        assertNotNull("The factory didn't initialize a default node selection policy instance", pool.getNodeSelectionStrategy());
        assertNotNull("The factory didn't initialize a default node suspension policy instance", pool.getNodeSuspensionStrategy());
        assertNotNull("The factory didn't initialize a default connection validator policy instance", pool.getConnectionValidator());
    } finally {
        factoryBean.destroy();
    }
}
Also used : CommonsBackedPool(org.scale7.cassandra.pelops.pool.CommonsBackedPool) Test(org.junit.Test) AbstractIntegrationTest(org.scale7.cassandra.pelops.support.AbstractIntegrationTest)

Example 7 with CommonsBackedPool

use of org.scale7.cassandra.pelops.pool.CommonsBackedPool in project scale7-pelops by s7.

the class Pelops method addPool.

/**
	 * Add a new Thrift connection pool for a specific cluster and keyspace. The name given to the pool is later used
	 * when creating operands such as <code>Mutator</code> and <code>Selector</code>.
	 * @param poolName				A name used to reference the pool e.g. "MainDatabase" or "LucandraIndexes"
	 * @param cluster				The Cassandra cluster that network connections will be made to
	 * @param keyspace				The keyspace in the Cassandra cluster against which pool operations will apply
	 */
public static void addPool(String poolName, Cluster cluster, String keyspace) {
    IThriftPool pool = new CommonsBackedPool(cluster, keyspace);
    addPool(poolName, pool);
}
Also used : IThriftPool(org.scale7.cassandra.pelops.pool.IThriftPool) CommonsBackedPool(org.scale7.cassandra.pelops.pool.CommonsBackedPool)

Example 8 with CommonsBackedPool

use of org.scale7.cassandra.pelops.pool.CommonsBackedPool in project scale7-pelops by s7.

the class Pelops method addPool.

/**
	 * Add a new Thrift connection pool for a specific cluster and keyspace. The name given to the pool is later used
	 * when creating operands such as <code>Mutator</code> and <code>Selector</code>.
	 * @param poolName				A name used to reference the pool e.g. "MainDatabase" or "LucandraIndexes"
     * @param cluster				The Cassandra cluster that network connections will be made to
     * @param keyspace				The keyspace in the Cassandra cluster against which pool operations will apply
     * @param policy                The configuration used by the pool
     * @param operandPolicy         The configuration used by the {@link org.scale7.cassandra.pelops.Operand}
     */
public static void addPool(String poolName, Cluster cluster, String keyspace, CommonsBackedPool.Policy policy, OperandPolicy operandPolicy) {
    IThriftPool pool = new CommonsBackedPool(cluster, keyspace, policy, operandPolicy);
    addPool(poolName, pool);
}
Also used : IThriftPool(org.scale7.cassandra.pelops.pool.IThriftPool) CommonsBackedPool(org.scale7.cassandra.pelops.pool.CommonsBackedPool)

Example 9 with CommonsBackedPool

use of org.scale7.cassandra.pelops.pool.CommonsBackedPool in project scale7-pelops by s7.

the class CommonsBackedPoolFactoryBean method afterPropertiesSet.

/**
     * Initializes the Pelops pool.
     * @throws Exception if an error occurs
     */
@Override
public void afterPropertiesSet() throws Exception {
    Assert.notNull(getCluster(), "The cluster property is required");
    Assert.notNull(getKeyspace(), "The keyspace property is required");
    logger.info("Initializing Pelops pool keyspace {} for nodes {}", getKeyspace(), Arrays.toString(getCluster().getNodes()));
    this.thriftPool = new CommonsBackedPool(getCluster(), getKeyspace(), getPolicy(), getOperandPolicy(), getNodeSelectionStrategy(), getNodeSuspensionStrategy(), getConnectionValidator());
}
Also used : CommonsBackedPool(org.scale7.cassandra.pelops.pool.CommonsBackedPool)

Aggregations

Test (org.junit.Test)6 AbstractIntegrationTest (org.scale7.cassandra.pelops.support.AbstractIntegrationTest)6 OperandPolicy (org.scale7.cassandra.pelops.OperandPolicy)5 CommonsBackedPool (org.scale7.cassandra.pelops.pool.CommonsBackedPool)5 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2 IThriftPool (org.scale7.cassandra.pelops.pool.IThriftPool)2 ExecutorService (java.util.concurrent.ExecutorService)1 Cluster (org.scale7.cassandra.pelops.Cluster)1 IConnection (org.scale7.cassandra.pelops.IConnection)1 Selector (org.scale7.cassandra.pelops.Selector)1 NoConnectionsAvailableException (org.scale7.cassandra.pelops.exceptions.NoConnectionsAvailableException)1 LeastLoadedNodeSelectionStrategy (org.scale7.cassandra.pelops.pool.LeastLoadedNodeSelectionStrategy)1 NoOpConnectionValidator (org.scale7.cassandra.pelops.pool.NoOpConnectionValidator)1 NoOpNodeSuspensionStrategy (org.scale7.cassandra.pelops.pool.NoOpNodeSuspensionStrategy)1