use of com.datastax.oss.driver.api.testinfra.CassandraRequirement in project java-driver by datastax.
the class SchemaIT method should_exclude_virtual_keyspaces_from_token_map.
@CassandraRequirement(min = "4.0", description = "virtual tables introduced in 4.0")
@Test
public void should_exclude_virtual_keyspaces_from_token_map() {
skipIfDse60();
DriverConfigLoader loader = SessionUtils.configLoaderBuilder().withStringList(DefaultDriverOption.METADATA_SCHEMA_REFRESHED_KEYSPACES, Arrays.asList("system_views", "system_virtual_schema", sessionRule.keyspace().asInternal())).build();
try (CqlSession session = SessionUtils.newSession(ccmRule, loader)) {
Metadata metadata = session.getMetadata();
Map<CqlIdentifier, KeyspaceMetadata> keyspaces = metadata.getKeyspaces();
assertThat(keyspaces).containsKey(CqlIdentifier.fromCql("system_views")).containsKey(CqlIdentifier.fromCql("system_virtual_schema"));
TokenMap tokenMap = metadata.getTokenMap().orElseThrow(AssertionError::new);
// value does not matter
ByteBuffer partitionKey = Bytes.fromHexString("0x00");
assertThat(tokenMap.getReplicas("system_views", partitionKey)).isEmpty();
assertThat(tokenMap.getReplicas("system_virtual_schema", partitionKey)).isEmpty();
// Check that a non-virtual keyspace is present
assertThat(tokenMap.getReplicas(sessionRule.keyspace(), partitionKey)).isNotEmpty();
}
}
use of com.datastax.oss.driver.api.testinfra.CassandraRequirement in project java-driver by datastax.
the class PreparedStatementIT method should_update_metadata_when_schema_changed_across_executions.
@Test
@CassandraRequirement(min = "4.0")
public void should_update_metadata_when_schema_changed_across_executions() {
// Given
CqlSession session = sessionRule.session();
PreparedStatement ps = session.prepare("SELECT * FROM prepared_statement_test WHERE a = ?");
ByteBuffer idBefore = ps.getResultMetadataId();
// When
session.execute(SimpleStatement.builder("ALTER TABLE prepared_statement_test ADD d int").setExecutionProfile(sessionRule.slowProfile()).build());
BoundStatement bs = ps.bind(1);
ResultSet rows = session.execute(bs);
// Then
ByteBuffer idAfter = ps.getResultMetadataId();
assertThat(Bytes.toHexString(idAfter)).isNotEqualTo(Bytes.toHexString(idBefore));
for (ColumnDefinitions columnDefinitions : ImmutableList.of(ps.getResultSetDefinitions(), bs.getPreparedStatement().getResultSetDefinitions(), rows.getColumnDefinitions())) {
assertThat(columnDefinitions).hasSize(4);
assertThat(columnDefinitions.get("d").getType()).isEqualTo(DataTypes.INT);
}
}
use of com.datastax.oss.driver.api.testinfra.CassandraRequirement in project java-driver by datastax.
the class PreparedStatementIT method should_fail_to_reprepare_if_query_becomes_invalid.
@Test
@CassandraRequirement(min = "4.0")
public void should_fail_to_reprepare_if_query_becomes_invalid() {
// Given
CqlSession session = sessionRule.session();
session.execute("ALTER TABLE prepared_statement_test ADD d int");
PreparedStatement ps = session.prepare("SELECT a, b, c, d FROM prepared_statement_test WHERE a = ?");
session.execute("ALTER TABLE prepared_statement_test DROP d");
// When
Throwable t = catchThrowable(() -> session.execute(ps.bind()));
// Then
assertThat(t).isInstanceOf(InvalidQueryException.class).hasMessageContaining("Undefined column name d");
}
use of com.datastax.oss.driver.api.testinfra.CassandraRequirement in project java-driver by datastax.
the class BaseCcmRule method apply.
@Override
public Statement apply(Statement base, Description description) {
// If test is annotated with CassandraRequirement or DseRequirement, ensure configured CCM
// cluster meets those requirements.
CassandraRequirement cassandraRequirement = description.getAnnotation(CassandraRequirement.class);
if (cassandraRequirement != null) {
// if the configured cassandra cassandraRequirement exceeds the one being used skip this test.
if (!cassandraRequirement.min().isEmpty()) {
Version minVersion = Version.parse(cassandraRequirement.min());
if (minVersion.compareTo(ccmBridge.getCassandraVersion()) > 0) {
return buildErrorStatement(minVersion, cassandraRequirement.description(), false, false);
}
}
if (!cassandraRequirement.max().isEmpty()) {
// if the test version exceeds the maximum configured one, fail out.
Version maxVersion = Version.parse(cassandraRequirement.max());
if (maxVersion.compareTo(ccmBridge.getCassandraVersion()) <= 0) {
return buildErrorStatement(maxVersion, cassandraRequirement.description(), true, false);
}
}
}
DseRequirement dseRequirement = description.getAnnotation(DseRequirement.class);
if (dseRequirement != null) {
Optional<Version> dseVersionOption = ccmBridge.getDseVersion();
if (!dseVersionOption.isPresent()) {
return new Statement() {
@Override
public void evaluate() {
throw new AssumptionViolatedException("Test Requires DSE but C* is configured.");
}
};
} else {
Version dseVersion = dseVersionOption.get();
if (!dseRequirement.min().isEmpty()) {
Version minVersion = Version.parse(dseRequirement.min());
if (minVersion.compareTo(dseVersion) > 0) {
return buildErrorStatement(minVersion, dseRequirement.description(), false, true);
}
}
if (!dseRequirement.max().isEmpty()) {
Version maxVersion = Version.parse(dseRequirement.max());
if (maxVersion.compareTo(dseVersion) <= 0) {
return buildErrorStatement(maxVersion, dseRequirement.description(), true, true);
}
}
}
}
return super.apply(base, description);
}
Aggregations