Search in sources :

Example 6 with CassandraRequirement

use of com.datastax.oss.driver.api.testinfra.CassandraRequirement in project java-driver by datastax.

the class PerRequestKeyspaceIT method should_execute_batch_with_explicit_keyspace.

@Test
@CassandraRequirement(min = "4.0")
public void should_execute_batch_with_explicit_keyspace() {
    CqlSession session = sessionRule.session();
    session.execute(BatchStatement.builder(DefaultBatchType.LOGGED).setKeyspace(sessionRule.keyspace()).addStatements(SimpleStatement.newInstance("INSERT INTO foo (k, cc, v) VALUES (?, ?, ?)", nameRule.getMethodName(), 1, 1), SimpleStatement.newInstance("INSERT INTO foo (k, cc, v) VALUES (?, ?, ?)", nameRule.getMethodName(), 2, 2)).build());
    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 : 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)

Example 7 with CassandraRequirement

use of com.datastax.oss.driver.api.testinfra.CassandraRequirement in project java-driver by datastax.

the class PerRequestKeyspaceIT method should_reprepare_statement_with_keyspace_on_the_fly.

@Test
@CassandraRequirement(min = "4.0")
public void should_reprepare_statement_with_keyspace_on_the_fly() {
    // Create a separate session because we don't want it to have a default keyspace
    try (CqlSession session = SessionUtils.newSession(ccmRule)) {
        executeDdl(session, String.format("CREATE TABLE IF NOT EXISTS %s.bar (k int primary key)", sessionRule.keyspace()));
        PreparedStatement pst = session.prepare(SimpleStatement.newInstance("SELECT * FROM bar WHERE k=?").setKeyspace(sessionRule.keyspace()));
        // Drop and re-create the table to invalidate the prepared statement server side
        executeDdl(session, String.format("DROP TABLE %s.bar", sessionRule.keyspace()));
        executeDdl(session, String.format("CREATE TABLE %s.bar (k int primary key)", sessionRule.keyspace()));
        assertThat(preparedStatementExistsOnServer(session, pst.getId())).isFalse();
        // This will re-prepare on the fly
        session.execute(pst.bind(0));
        assertThat(preparedStatementExistsOnServer(session, pst.getId())).isTrue();
    }
}
Also used : PreparedStatement(com.datastax.oss.driver.api.core.cql.PreparedStatement) CqlSession(com.datastax.oss.driver.api.core.CqlSession) Test(org.junit.Test) CassandraRequirement(com.datastax.oss.driver.api.testinfra.CassandraRequirement)

Example 8 with CassandraRequirement

use of com.datastax.oss.driver.api.testinfra.CassandraRequirement in project java-driver by datastax.

the class ProtocolVersionInitialNegotiationIT method should_use_explicitly_provided_v5_oss.

@CassandraRequirement(min = "4.0", description = "Only C* in [4.0,*[ has V5 supported")
@Test
public void should_use_explicitly_provided_v5_oss() {
    Assume.assumeFalse("This test is only for OSS C*", ccm.getDseVersion().isPresent());
    DriverConfigLoader loader = SessionUtils.configLoaderBuilder().withString(DefaultDriverOption.PROTOCOL_VERSION, "V5").build();
    try (CqlSession session = SessionUtils.newSession(ccm, loader)) {
        assertThat(session.getContext().getProtocolVersion().getCode()).isEqualTo(5);
        session.execute("select * from system.local");
    }
}
Also used : DriverConfigLoader(com.datastax.oss.driver.api.core.config.DriverConfigLoader) CqlSession(com.datastax.oss.driver.api.core.CqlSession) Test(org.junit.Test) CassandraRequirement(com.datastax.oss.driver.api.testinfra.CassandraRequirement)

Example 9 with CassandraRequirement

use of com.datastax.oss.driver.api.testinfra.CassandraRequirement in project java-driver by datastax.

the class ProtocolVersionInitialNegotiationIT method should_fail_if_provided_v4_is_not_supported_oss.

@CassandraRequirement(max = "2.2", description = "Only C* in [*,2.2[ has V4 unsupported")
@Test
public void should_fail_if_provided_v4_is_not_supported_oss() {
    Assume.assumeFalse("This test is only for OSS C*", ccm.getDseVersion().isPresent());
    DriverConfigLoader loader = SessionUtils.configLoaderBuilder().withString(DefaultDriverOption.PROTOCOL_VERSION, "V4").build();
    try (CqlSession ignored = SessionUtils.newSession(ccm, loader)) {
        fail("Expected an AllNodesFailedException");
    } catch (AllNodesFailedException anfe) {
        Throwable cause = anfe.getAllErrors().values().iterator().next().get(0);
        assertThat(cause).isInstanceOf(UnsupportedProtocolVersionException.class);
        UnsupportedProtocolVersionException unsupportedException = (UnsupportedProtocolVersionException) cause;
        assertThat(unsupportedException.getAttemptedVersions()).containsOnly(DefaultProtocolVersion.V4);
    }
}
Also used : AllNodesFailedException(com.datastax.oss.driver.api.core.AllNodesFailedException) DriverConfigLoader(com.datastax.oss.driver.api.core.config.DriverConfigLoader) UnsupportedProtocolVersionException(com.datastax.oss.driver.api.core.UnsupportedProtocolVersionException) CqlSession(com.datastax.oss.driver.api.core.CqlSession) Test(org.junit.Test) CassandraRequirement(com.datastax.oss.driver.api.testinfra.CassandraRequirement)

Example 10 with CassandraRequirement

use of com.datastax.oss.driver.api.testinfra.CassandraRequirement in project java-driver by datastax.

the class CcmPaxExam method run.

@Override
public void run(RunNotifier notifier) {
    Description description = getDescription();
    CassandraRequirement cassandraRequirement = description.getAnnotation(CassandraRequirement.class);
    if (cassandraRequirement != null) {
        if (!cassandraRequirement.min().isEmpty()) {
            Version minVersion = Objects.requireNonNull(Version.parse(cassandraRequirement.min()));
            if (minVersion.compareTo(CCM_BRIDGE.getCassandraVersion()) > 0) {
                fireRequirementsNotMet(notifier, description, cassandraRequirement.min(), false, false);
                return;
            }
        }
        if (!cassandraRequirement.max().isEmpty()) {
            Version maxVersion = Objects.requireNonNull(Version.parse(cassandraRequirement.max()));
            if (maxVersion.compareTo(CCM_BRIDGE.getCassandraVersion()) <= 0) {
                fireRequirementsNotMet(notifier, description, cassandraRequirement.max(), true, false);
                return;
            }
        }
    }
    DseRequirement dseRequirement = description.getAnnotation(DseRequirement.class);
    if (dseRequirement != null) {
        Optional<Version> dseVersionOption = CCM_BRIDGE.getDseVersion();
        if (!dseVersionOption.isPresent()) {
            notifier.fireTestAssumptionFailed(new Failure(description, new AssumptionViolatedException("Test Requires DSE but C* is configured.")));
            return;
        } else {
            Version dseVersion = dseVersionOption.get();
            if (!dseRequirement.min().isEmpty()) {
                Version minVersion = Objects.requireNonNull(Version.parse(dseRequirement.min()));
                if (minVersion.compareTo(dseVersion) > 0) {
                    fireRequirementsNotMet(notifier, description, dseRequirement.min(), false, true);
                    return;
                }
            }
            if (!dseRequirement.max().isEmpty()) {
                Version maxVersion = Objects.requireNonNull(Version.parse(dseRequirement.max()));
                if (maxVersion.compareTo(dseVersion) <= 0) {
                    fireRequirementsNotMet(notifier, description, dseRequirement.min(), true, true);
                    return;
                }
            }
        }
    }
    super.run(notifier);
}
Also used : Description(org.junit.runner.Description) DseRequirement(com.datastax.oss.driver.api.testinfra.DseRequirement) Version(com.datastax.oss.driver.api.core.Version) AssumptionViolatedException(org.junit.AssumptionViolatedException) CassandraRequirement(com.datastax.oss.driver.api.testinfra.CassandraRequirement) Failure(org.junit.runner.notification.Failure)

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