Search in sources :

Example 6 with BatchExecution

use of org.scassandra.http.client.BatchExecution in project java-driver by datastax.

the class ConsistencyTest method should_use_appropriate_cl_when_multiple_defined.

/**
 * Tests that order of precedence is followed when defining CLs.
 * Statement level CL should be honored above QueryOptions.
 * QueryOptions should be honored above default CL.
 *
 * @test_category consistency
 */
@Test(groups = "short")
public void should_use_appropriate_cl_when_multiple_defined() throws Throwable {
    ConsistencyLevel cl_one = ConsistencyLevel.ONE;
    // Build a cluster with no CL set in the query options.
    Cluster cluster = builder().withQueryOptions(new QueryOptions().setConsistencyLevel(cl_one)).build();
    try {
        Session session = cluster.connect();
        // Check order of precedence for simple statements
        // Construct unique query statement with no CL defined.
        String queryString = "opts_cl";
        Query clQuery = executeSimple(session, queryString, null, null);
        assertTrue(clQuery.getConsistency().equals(cl_one.toString()));
        // Construct unique query statement with a CL defined.
        ConsistencyLevel cl_all = ConsistencyLevel.ALL;
        queryString = "stm_cl";
        clQuery = executeSimple(session, queryString, cl_all, null);
        assertTrue(clQuery.getConsistency().equals(cl_all.toString()));
        // Check order of precedence for prepared statements
        // Construct unique prepared statement with no CL defined.
        String prepareString = "prep_opts_cl";
        PreparedStatementExecution pse = executePrepared(session, prepareString, null, null);
        assertTrue(pse.getConsistency().equals(cl_one.toString()));
        clearActivityLog();
        // Construct unique prepared statement with a CL defined.
        prepareString = "prep_stm_cl";
        pse = executePrepared(session, prepareString, cl_all, null);
        assertTrue(pse.getConsistency().equals(cl_all.toString()));
        // Check order of precedence for batch statements
        // Construct unique batch statement with no CL defined.
        String batchString = "batch_opts_cl";
        BatchExecution batch = executeBatch(session, batchString, null, null);
        assertTrue(batch.getConsistency().equals(cl_one.toString()));
        clearActivityLog();
        // Construct unique prepared statement with a CL defined.
        batchString = "prep_stm_cl";
        batch = executeBatch(session, batchString, cl_all, null);
        assertTrue(batch.getConsistency().equals(cl_all.toString()));
    } finally {
        cluster.close();
    }
}
Also used : Query(org.scassandra.http.client.Query) BatchExecution(org.scassandra.http.client.BatchExecution) PreparedStatementExecution(org.scassandra.http.client.PreparedStatementExecution) Test(org.testng.annotations.Test)

Aggregations

BatchExecution (org.scassandra.http.client.BatchExecution)6 PreparedStatementExecution (org.scassandra.http.client.PreparedStatementExecution)6 Query (org.scassandra.http.client.Query)6 Test (org.testng.annotations.Test)6