use of com.datastax.oss.driver.api.testinfra.CassandraRequirement in project java-driver by datastax.
the class BoundStatementCcmIT method should_compute_routing_key_when_indices_randomly_distributed.
// Test for JAVA-2066
@Test
@CassandraRequirement(min = "2.2")
public void should_compute_routing_key_when_indices_randomly_distributed() {
try (CqlSession session = SessionUtils.newSession(ccmRule, sessionRule.keyspace())) {
PreparedStatement ps = session.prepare("INSERT INTO test3 (v, pk2, pk1) VALUES (?,?,?)");
List<Integer> indices = ps.getPartitionKeyIndices();
assertThat(indices).containsExactly(2, 1);
BoundStatement bs = ps.bind(1, 2, 3);
ByteBuffer routingKey = bs.getRoutingKey();
assertThat(routingKey).isEqualTo(RoutingKey.compose(bs.getBytesUnsafe(2), bs.getBytesUnsafe(1)));
}
}
use of com.datastax.oss.driver.api.testinfra.CassandraRequirement in project java-driver by datastax.
the class ExecutionInfoWarningsIT method should_execute_query_and_not_log_server_side_warnings.
@Test
@CassandraRequirement(min = "3.0")
public void should_execute_query_and_not_log_server_side_warnings() {
final String query = "SELECT count(*) FROM test;";
Statement<?> st = SimpleStatement.builder(query).setExecutionProfileName("log-disabled").build();
ResultSet result = sessionRule.session().execute(st);
ExecutionInfo executionInfo = result.getExecutionInfo();
assertThat(executionInfo).isNotNull();
List<String> warnings = executionInfo.getWarnings();
assertThat(warnings).isNotEmpty();
String warning = warnings.get(0);
assertThat(warning).isEqualTo("Aggregation query used without partition key");
// verify the log was NOT generated
verify(appender, timeout(500).times(0)).doAppend(loggingEventCaptor.capture());
}
use of com.datastax.oss.driver.api.testinfra.CassandraRequirement in project java-driver by datastax.
the class ProtocolVersionInitialNegotiationIT method should_downgrade_to_v4_oss.
@CassandraRequirement(min = "2.2", max = "4.0-rc1", description = "Only C* in [2.2,4.0-rc1[ has V4 as its highest version")
@Test
public void should_downgrade_to_v4_oss() {
Assume.assumeFalse("This test is only for OSS C*", ccm.getDseVersion().isPresent());
try (CqlSession session = SessionUtils.newSession(ccm)) {
assertThat(session.getContext().getProtocolVersion().getCode()).isEqualTo(4);
session.execute("select * from system.local");
}
}
use of com.datastax.oss.driver.api.testinfra.CassandraRequirement in project java-driver by datastax.
the class BatchStatementIT method should_execute_batch_of_bound_statements_with_unset_values.
@Test
@CassandraRequirement(min = "2.2")
public void should_execute_batch_of_bound_statements_with_unset_values() {
// Build a batch of batchCount statements with bound statements, each with their own positional
// variables.
BatchStatementBuilder builder = BatchStatement.builder(DefaultBatchType.UNLOGGED);
SimpleStatement insert = SimpleStatement.builder(String.format("INSERT INTO test (k0, k1, v) values ('%s', ? , ?)", name.getMethodName())).build();
PreparedStatement preparedStatement = sessionRule.session().prepare(insert);
for (int i = 0; i < batchCount; i++) {
builder.addStatement(preparedStatement.bind(i, i + 1));
}
BatchStatement batchStatement = builder.build();
sessionRule.session().execute(batchStatement);
verifyBatchInsert();
BatchStatementBuilder builder2 = BatchStatement.builder(DefaultBatchType.UNLOGGED);
for (int i = 0; i < batchCount; i++) {
BoundStatement boundStatement = preparedStatement.bind(i, i + 2);
// unset v every 20 statements.
if (i % 20 == 0) {
boundStatement = boundStatement.unset(1);
}
builder.addStatement(boundStatement);
}
sessionRule.session().execute(builder2.build());
Statement<?> select = SimpleStatement.builder("SELECT * from test where k0 = ?").addPositionalValue(name.getMethodName()).build();
ResultSet result = sessionRule.session().execute(select);
List<Row> rows = result.all();
assertThat(rows).hasSize(100);
Iterator<Row> iterator = rows.iterator();
for (int i = 0; i < batchCount; i++) {
Row row = iterator.next();
assertThat(row.getString("k0")).isEqualTo(name.getMethodName());
assertThat(row.getInt("k1")).isEqualTo(i);
// value should be from first insert (i + 1) if at row divisble by 20, otherwise second.
int expectedValue = i % 20 == 0 ? i + 1 : i + 2;
if (i % 20 == 0) {
assertThat(row.getInt("v")).isEqualTo(expectedValue);
}
}
}
use of com.datastax.oss.driver.api.testinfra.CassandraRequirement in project java-driver by datastax.
the class PerRequestKeyspaceIT method should_prepare_statement_with_keyspace.
@Test
@CassandraRequirement(min = "4.0")
public void should_prepare_statement_with_keyspace() {
CqlSession session = sessionRule.session();
PreparedStatement prepared = session.prepare(SimpleStatement.newInstance("INSERT INTO foo (k, cc, v) VALUES (?, ?, ?)").setKeyspace(sessionRule.keyspace()));
session.execute(prepared.bind(nameRule.getMethodName(), 1, 1));
Row row = session.execute(SimpleStatement.newInstance("SELECT v FROM foo WHERE k = ? AND cc = 1", nameRule.getMethodName()).setKeyspace(sessionRule.keyspace())).one();
assertThat(row.getInt(0)).isEqualTo(1);
}
Aggregations