use of org.scassandra.http.client.Query in project java-driver by datastax.
the class ConsistencyTest method should_use_query_option_serial_cl.
/**
* Exhaustively tests all serial consistency levels when they are set via QueryOptions.
*
* @test_category consistency
*/
@Test(groups = "short", dataProvider = "serialConsistencyLevels", dataProviderClass = DataProviders.class)
public void should_use_query_option_serial_cl(ConsistencyLevel cl) throws Throwable {
// Build a cluster with a CL level set in the query options.
Cluster cluster = builder().withQueryOptions(new QueryOptions().setSerialConsistencyLevel(cl)).build();
try {
Session session = cluster.connect();
// Construct unique query, with no CL defined.
String queryString = "serial_query_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, null);
checkSerialCLMatch(cl, pse.getSerialConsistency());
// Check batch statement CL
String batchStateString = "batch_statement_serial_cl";
BatchExecution batch = executeBatch(session, batchStateString, null, null);
checkSerialCLMatch(cl, batch.getSerialConsistency());
} finally {
cluster.close();
}
}
use of org.scassandra.http.client.Query in project java-driver by datastax.
the class ConsistencyTest method should_use_global_default_cl_when_none_specified.
/**
* When no consistency level is defined the default of LOCAL_ONE should be used.
*
* @test_category consistency
*/
@Test(groups = "short")
public void should_use_global_default_cl_when_none_specified() throws Throwable {
// Build a cluster with no CL level set in the query options.
Cluster cluster = builder().build();
try {
Session session = cluster.connect();
// Construct unique simple statement query, with no CL defined.
// Check to ensure
String queryString = "default_cl";
Query clQuery = executeSimple(session, queryString, null, null);
assertTrue(clQuery.getConsistency().equals(ConsistencyLevel.LOCAL_ONE.toString()));
// Check prepared statement default CL
String prepareString = "prepared_default_cl";
PreparedStatementExecution pse = executePrepared(session, prepareString, null, null);
assertTrue(pse.getConsistency().equals(ConsistencyLevel.LOCAL_ONE.toString()));
// Check batch statement default CL
String batchStateString = "batch_default_cl";
BatchExecution batch = executeBatch(session, batchStateString, null, null);
assertTrue(batch.getConsistency().equals(ConsistencyLevel.LOCAL_ONE.toString()));
} finally {
cluster.close();
}
}
use of org.scassandra.http.client.Query in project java-driver by datastax.
the class ConsistencyTest method should_use_statement_cl.
/**
* Exhaustively tests all consistency levels when they are set at the statement level.
*
* @test_category consistency
*/
@Test(groups = "short", dataProvider = "consistencyLevels", dataProviderClass = DataProviders.class)
public void should_use_statement_cl(ConsistencyLevel cl) throws Throwable {
// Build a cluster with no CL set in the query options.
// Note: nonQuietClusterCloseOptions is used to speed up tests
Cluster cluster = builder().build();
try {
Session session = cluster.connect();
// Construct unique query statement with a CL defined.
String queryString = "statement_cl";
Query clQuery = executeSimple(session, queryString, cl, null);
assertTrue(clQuery.getConsistency().equals(cl.toString()));
// Check prepared statement CL
String prepareString = "preapred_statement_cl";
PreparedStatementExecution pse = executePrepared(session, prepareString, cl, null);
assertTrue(pse.getConsistency().equals(cl.toString()));
// Check batch statement CL
String batchStateString = "batch_statement_cl";
BatchExecution batch = executeBatch(session, batchStateString, cl, null);
assertTrue(batch.getConsistency().equals(cl.toString()));
} finally {
cluster.close();
}
}
use of org.scassandra.http.client.Query 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();
}
}
use of org.scassandra.http.client.Query in project java-driver by datastax.
the class ConsistencyTest method executeSimple.
public Query executeSimple(Session session, String statement, ConsistencyLevel level, ConsistencyLevel serialLevel) {
SimpleStatement simpleStatement = new SimpleStatement(statement);
if (level != null) {
simpleStatement.setConsistencyLevel(level);
}
if (serialLevel != null) {
simpleStatement.setSerialConsistencyLevel(serialLevel);
}
session.execute(simpleStatement);
// Find the unique query in the activity log.
List<Query> queries = sCluster.node(1).activityClient().retrieveQueries();
for (Query query : queries) {
if (query.getQuery().equals(statement))
return query;
}
return null;
}
Aggregations