Search in sources :

Example 6 with PreparedStatementExecution

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

the class ConsistencyTest method should_use_query_option_cl.

/**
 * Exhaustively tests all consistency levels when they are set via QueryOptions.
 *
 * @test_category consistency
 */
@Test(groups = "short", dataProvider = "consistencyLevels", dataProviderClass = DataProviders.class)
public void should_use_query_option_cl(ConsistencyLevel cl) throws Throwable {
    // Build a cluster with a CL level set in the query options.
    Cluster cluster = builder().withQueryOptions(new QueryOptions().setConsistencyLevel(cl)).build();
    try {
        Session session = cluster.connect();
        // Construct unique query, with no CL defined.
        String queryString = "query_cl";
        Query clQuery = executeSimple(session, queryString, null, null);
        assertTrue(clQuery.getConsistency().equals(cl.toString()));
        // Check prepared statement CL
        String prepareString = "preapred_query_cl";
        PreparedStatementExecution pse = executePrepared(session, prepareString, null, null);
        assertTrue(pse.getConsistency().equals(cl.toString()));
        // Check batch statement CL
        String batchStateString = "batch_query_cl";
        BatchExecution batch = executeBatch(session, batchStateString, null, null);
        assertTrue(batch.getConsistency().equals(cl.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)

Example 7 with PreparedStatementExecution

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

the class ConsistencyTest method should_use_statement_serial_cl.

/**
 * Exhaustively tests all serial consistency levels when they are set at the statement level.
 *
 * @test_category consistency
 */
@Test(groups = "short", dataProvider = "serialConsistencyLevels", dataProviderClass = DataProviders.class)
public void should_use_statement_serial_cl(ConsistencyLevel cl) throws Throwable {
    // Build a cluster with no CL set in the query options.
    Cluster cluster = builder().build();
    try {
        Session session = cluster.connect();
        // Construct unique query statement with a CL defined.
        String queryString = "statement_serial_cl";
        Query clQuery = executeSimple(session, queryString, null, cl);
        checkSerialCLMatch(cl, clQuery.getSerialConsistency());
        // Check prepared statement CL
        String prepareString = "preapred_statement_serial_cl";
        PreparedStatementExecution pse = executePrepared(session, prepareString, null, cl);
        checkSerialCLMatch(cl, pse.getSerialConsistency());
        // Check batch statement CL
        String batchStateString = "batch_statement_serial_cl";
        BatchExecution batch = executeBatch(session, batchStateString, null, cl);
        checkSerialCLMatch(cl, batch.getSerialConsistency());
    } 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)

Example 8 with PreparedStatementExecution

use of org.scassandra.http.client.PreparedStatementExecution 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

PreparedStatementExecution (org.scassandra.http.client.PreparedStatementExecution)8 BatchExecution (org.scassandra.http.client.BatchExecution)6 Query (org.scassandra.http.client.Query)6 Test (org.testng.annotations.Test)6 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 Map (java.util.Map)1 PortabilityJob (org.dataportabilityproject.spi.cloud.types.PortabilityJob)1 Ignore (org.junit.Ignore)1 Test (org.junit.Test)1 PrimingRequest (org.scassandra.http.client.PrimingRequest)1