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);
}
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();
}
}
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");
}
}
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);
}
}
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);
}
Aggregations