Search in sources :

Example 11 with CassandraRequirement

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)));
    }
}
Also used : PreparedStatement(com.datastax.oss.driver.api.core.cql.PreparedStatement) CqlSession(com.datastax.oss.driver.api.core.CqlSession) BoundStatement(com.datastax.oss.driver.api.core.cql.BoundStatement) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test) CassandraRequirement(com.datastax.oss.driver.api.testinfra.CassandraRequirement)

Example 12 with CassandraRequirement

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());
}
Also used : ResultSet(com.datastax.oss.driver.api.core.cql.ResultSet) ExecutionInfo(com.datastax.oss.driver.api.core.cql.ExecutionInfo) Test(org.junit.Test) CassandraRequirement(com.datastax.oss.driver.api.testinfra.CassandraRequirement)

Example 13 with CassandraRequirement

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");
    }
}
Also used : CqlSession(com.datastax.oss.driver.api.core.CqlSession) Test(org.junit.Test) CassandraRequirement(com.datastax.oss.driver.api.testinfra.CassandraRequirement)

Example 14 with CassandraRequirement

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);
        }
    }
}
Also used : SimpleStatement(com.datastax.oss.driver.api.core.cql.SimpleStatement) BatchStatement(com.datastax.oss.driver.api.core.cql.BatchStatement) BatchStatementBuilder(com.datastax.oss.driver.api.core.cql.BatchStatementBuilder) ResultSet(com.datastax.oss.driver.api.core.cql.ResultSet) PreparedStatement(com.datastax.oss.driver.api.core.cql.PreparedStatement) Row(com.datastax.oss.driver.api.core.cql.Row) BoundStatement(com.datastax.oss.driver.api.core.cql.BoundStatement) Test(org.junit.Test) CassandraRequirement(com.datastax.oss.driver.api.testinfra.CassandraRequirement)

Example 15 with CassandraRequirement

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);
}
Also used : PreparedStatement(com.datastax.oss.driver.api.core.cql.PreparedStatement) Row(com.datastax.oss.driver.api.core.cql.Row) CqlSession(com.datastax.oss.driver.api.core.CqlSession) Test(org.junit.Test) CassandraRequirement(com.datastax.oss.driver.api.testinfra.CassandraRequirement)

Aggregations

CassandraRequirement (com.datastax.oss.driver.api.testinfra.CassandraRequirement)29 Test (org.junit.Test)27 CqlSession (com.datastax.oss.driver.api.core.CqlSession)21 PreparedStatement (com.datastax.oss.driver.api.core.cql.PreparedStatement)8 DriverConfigLoader (com.datastax.oss.driver.api.core.config.DriverConfigLoader)7 ResultSet (com.datastax.oss.driver.api.core.cql.ResultSet)6 Row (com.datastax.oss.driver.api.core.cql.Row)6 ByteBuffer (java.nio.ByteBuffer)5 AsyncResultSet (com.datastax.oss.driver.api.core.cql.AsyncResultSet)3 BoundStatement (com.datastax.oss.driver.api.core.cql.BoundStatement)3 ExecutionInfo (com.datastax.oss.driver.api.core.cql.ExecutionInfo)3 SimpleStatement (com.datastax.oss.driver.api.core.cql.SimpleStatement)3 AllNodesFailedException (com.datastax.oss.driver.api.core.AllNodesFailedException)2 UnsupportedProtocolVersionException (com.datastax.oss.driver.api.core.UnsupportedProtocolVersionException)2 Version (com.datastax.oss.driver.api.core.Version)2 Metadata (com.datastax.oss.driver.api.core.metadata.Metadata)2 ColumnMetadata (com.datastax.oss.driver.api.core.metadata.schema.ColumnMetadata)2 KeyspaceMetadata (com.datastax.oss.driver.api.core.metadata.schema.KeyspaceMetadata)2 TableMetadata (com.datastax.oss.driver.api.core.metadata.schema.TableMetadata)2 DseRequirement (com.datastax.oss.driver.api.testinfra.DseRequirement)2