Search in sources :

Example 6 with OperandPolicy

use of org.scale7.cassandra.pelops.OperandPolicy 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 7 with OperandPolicy

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

the class MutatorIntegrationTest method testWriteColumnsWithDeleteIfNullFromConstructor.

@Test
public void testWriteColumnsWithDeleteIfNullFromConstructor() throws Exception {
    IThriftPool pool = new DebuggingPool(getCluster(), KEYSPACE, new OperandPolicy(3, true));
    Bytes rowKey = Bytes.fromLong(Long.MAX_VALUE);
    Bytes colName1 = Bytes.fromInt(1);
    Bytes colName2 = Bytes.fromInt(2);
    Mutator mutator = pool.createMutator();
    assertTrue("Mutator is not in a valid state for this test", mutator.deleteIfNull);
    List<Column> columns = mutator.newColumnList(mutator.newColumn(colName1, (Bytes) null), mutator.newColumn(colName2, Bytes.fromInt(1)));
    mutator.writeColumns(CF, rowKey, columns);
    // make sure there is at least one deletion
    boolean isOneDeletion = false;
    for (Mutation mutation : mutator.getMutationList(CF, rowKey)) {
        if (mutation.isSetDeletion()) {
            isOneDeletion = true;
            break;
        }
    }
    assertTrue("There should be one deletion", isOneDeletion);
    pool.shutdown();
}
Also used : Column(org.apache.cassandra.thrift.Column) IThriftPool(org.scale7.cassandra.pelops.pool.IThriftPool) Mutation(org.apache.cassandra.thrift.Mutation) DebuggingPool(org.scale7.cassandra.pelops.pool.DebuggingPool) Test(org.junit.Test) AbstractIntegrationTest(org.scale7.cassandra.pelops.support.AbstractIntegrationTest)

Example 8 with OperandPolicy

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

the class MutatorIntegrationTest method testConstructorDeleteIfNullFromPolicyState.

@Test
public void testConstructorDeleteIfNullFromPolicyState() {
    OperandPolicy policy = new OperandPolicy();
    policy.setDeleteIfNull(true);
    IThriftPool pool = Mockito.mock(IThriftPool.class);
    Mockito.when(pool.getOperandPolicy()).thenReturn(policy);
    Mutator mutator = new Mutator(pool);
    assertTrue("Mutator is not in the expected state", mutator.deleteIfNull);
}
Also used : IThriftPool(org.scale7.cassandra.pelops.pool.IThriftPool) Test(org.junit.Test) AbstractIntegrationTest(org.scale7.cassandra.pelops.support.AbstractIntegrationTest)

Aggregations

Test (org.junit.Test)6 AbstractIntegrationTest (org.scale7.cassandra.pelops.support.AbstractIntegrationTest)6 OperandPolicy (org.scale7.cassandra.pelops.OperandPolicy)4 IThriftPool (org.scale7.cassandra.pelops.pool.IThriftPool)3 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2 CommonsBackedPool (org.scale7.cassandra.pelops.pool.CommonsBackedPool)2 Column (org.apache.cassandra.thrift.Column)1 Mutation (org.apache.cassandra.thrift.Mutation)1 NotFoundException (org.apache.cassandra.thrift.NotFoundException)1 TimedOutException (org.apache.cassandra.thrift.TimedOutException)1 UnavailableException (org.apache.cassandra.thrift.UnavailableException)1 TTransportException (org.apache.thrift.transport.TTransportException)1 Cluster (org.scale7.cassandra.pelops.Cluster)1 IConnection (org.scale7.cassandra.pelops.IConnection)1 NoConnectionsAvailableException (org.scale7.cassandra.pelops.exceptions.NoConnectionsAvailableException)1 PelopsException (org.scale7.cassandra.pelops.exceptions.PelopsException)1 DebuggingPool (org.scale7.cassandra.pelops.pool.DebuggingPool)1 IPooledConnection (org.scale7.cassandra.pelops.pool.IThriftPool.IPooledConnection)1 LeastLoadedNodeSelectionStrategy (org.scale7.cassandra.pelops.pool.LeastLoadedNodeSelectionStrategy)1 NoOpConnectionValidator (org.scale7.cassandra.pelops.pool.NoOpConnectionValidator)1