use of com.datastax.driver.core.utils.CassandraVersion in project java-driver by datastax.
the class TestListener method scanAnnotatedElement.
private boolean scanAnnotatedElement(AnnotatedElement element) {
if (element.isAnnotationPresent(CassandraVersion.class)) {
CassandraVersion cassandraVersion = element.getAnnotation(CassandraVersion.class);
cassandraVersionCheck(cassandraVersion);
return true;
}
if (element.isAnnotationPresent(DseVersion.class)) {
DseVersion dseVersion = element.getAnnotation(DseVersion.class);
dseVersionCheck(dseVersion);
return true;
}
return false;
}
use of com.datastax.driver.core.utils.CassandraVersion in project java-driver by datastax.
the class SchemaBuilderIT method should_create_a_table_and_a_udt.
@Test(groups = "short")
@CassandraVersion("2.1.0")
public void should_create_a_table_and_a_udt() {
// Create a UDT and a table
session().execute(SchemaBuilder.createType("MyUDT").ifNotExists().addColumn("x", DataType.cint()));
UDTType myUDT = UDTType.frozen("MyUDT");
session().execute(SchemaBuilder.createTable("ks", "CreateTable").ifNotExists().addPartitionKey("a", DataType.cint()).addUDTPartitionKey("b", myUDT).addClusteringColumn("c", DataType.ascii()).addUDTClusteringColumn("d", myUDT).addUDTColumn("e", myUDT).addStaticColumn("f", DataType.bigint()).addUDTStaticColumn("g", myUDT).addUDTListColumn("h", myUDT).addUDTMapColumn("i", DataType.cboolean(), myUDT).addUDTMapColumn("j", myUDT, DataType.cboolean()).addUDTSetColumn("k", myUDT));
// Check columns a to k
ResultSet rows = session().execute("SELECT column_name, type, validator " + "FROM system.schema_columns " + "WHERE keyspace_name='ks' AND columnfamily_name='createtable'");
Iterator<Row> iterator = rows.iterator();
verifyNextColumnDefinition(iterator, "a", "partition_key", "org.apache.cassandra.db.marshal.Int32Type");
verifyNextColumnDefinition(iterator, "b", "partition_key", "org.apache.cassandra.db.marshal.UserType");
verifyNextColumnDefinition(iterator, "c", "clustering_key", "org.apache.cassandra.db.marshal.AsciiType");
verifyNextColumnDefinition(iterator, "d", "clustering_key", "org.apache.cassandra.db.marshal.UserType");
verifyNextColumnDefinition(iterator, "e", "regular", "org.apache.cassandra.db.marshal.UserType");
verifyNextColumnDefinition(iterator, "f", "static", "org.apache.cassandra.db.marshal.LongType");
verifyNextColumnDefinition(iterator, "g", "static", "org.apache.cassandra.db.marshal.UserType");
verifyNextColumnDefinition(iterator, "h", "regular", "org.apache.cassandra.db.marshal.ListType", "org.apache.cassandra.db.marshal.UserType");
verifyNextColumnDefinition(iterator, "i", "regular", "org.apache.cassandra.db.marshal.MapType", "org.apache.cassandra.db.marshal.BooleanType", "org.apache.cassandra.db.marshal.UserType");
verifyNextColumnDefinition(iterator, "j", "regular", "org.apache.cassandra.db.marshal.MapType", "org.apache.cassandra.db.marshal.UserType", "org.apache.cassandra.db.marshal.BooleanType");
verifyNextColumnDefinition(iterator, "k", "regular", "org.apache.cassandra.db.marshal.SetType", "org.apache.cassandra.db.marshal.UserType");
}
use of com.datastax.driver.core.utils.CassandraVersion in project java-driver by datastax.
the class SchemaBuilderIT method should_modify_table_metadata.
@Test(groups = "short")
@CassandraVersion("2.1.2")
public void should_modify_table_metadata() {
// Create a table
session().execute(SchemaBuilder.createTable("ks", "TableMetadata").addPartitionKey("a", DataType.cint()).addPartitionKey("b", DataType.cint()).addClusteringColumn("c", DataType.cint()).addClusteringColumn("d", DataType.cint()).withOptions().compactStorage());
// Modify the table metadata
session().execute(SchemaBuilder.alterTable("TableMetadata").withOptions().defaultTimeToLive(1337).bloomFilterFPChance(0.42).caching(SchemaBuilder.KeyCaching.ALL, rows(1)).gcGraceSeconds(1234567890).minIndexInterval(6).indexInterval(7).maxIndexInterval(8).comment("Useful comment").readRepairChance(0.123456).speculativeRetry(percentile(50)).dcLocalReadRepairChance(0.84).memtableFlushPeriodInMillis(1234567890).compactionOptions(dateTieredStrategy().baseTimeSeconds(1).minThreshold(2).maxThreshold(3).maxSSTableAgeDays(4).timestampResolution(TimeStampResolution.MILLISECONDS)).compressionOptions(snappy()));
// Retrieve the metadata from Cassandra
ResultSet rows = session().execute("SELECT " + "bloom_filter_fp_chance, " + "caching, " + "cf_id, " + "column_aliases, " + "comment, " + "compaction_strategy_class, " + "compaction_strategy_options, " + "comparator, " + "compression_parameters, " + "default_time_to_live, " + "default_validator, " + "dropped_columns, " + "gc_grace_seconds, " + "index_interval, " + "is_dense, " + "key_aliases, " + "key_validator, " + "local_read_repair_chance, " + "max_compaction_threshold, " + "max_index_interval, " + "memtable_flush_period_in_ms, " + "min_compaction_threshold, " + "min_index_interval, " + "read_repair_chance, " + "speculative_retry, " + "subcomparator, " + "type, " + "value_alias " + "FROM system.schema_columnfamilies " + "WHERE keyspace_name='ks' AND columnfamily_name='tablemetadata'");
for (Row row : rows) {
// There should be only one row
// Verify that every property we modified is correctly set
assertThat(row.getDouble("bloom_filter_fp_chance")).isEqualTo(0.42);
assertThat(row.getString("caching")).isEqualTo("{\"keys\":\"ALL\", \"rows_per_partition\":\"1\"}");
assertThat(row.getUUID("cf_id")).isNotNull();
assertThat(row.getString("column_aliases")).isEqualTo("[\"c\",\"d\"]");
assertThat(row.getString("comment")).isEqualTo("Useful comment");
assertThat(row.getString("compaction_strategy_class")).isEqualTo("org.apache.cassandra.db.compaction.DateTieredCompactionStrategy");
assertThat(row.getString("compaction_strategy_options")).isEqualTo("{\"base_time_seconds\":\"1\",\"timestamp_resolution\":\"MILLISECONDS\",\"max_sstable_age_days\":\"4\",\"min_threshold\":\"2\",\"max_threshold\":\"3\"}");
assertThat(row.getString("compression_parameters")).isEqualTo("{\"sstable_compression\":\"org.apache.cassandra.io.compress.SnappyCompressor\"}");
assertThat(row.getInt("default_time_to_live")).isEqualTo(1337);
assertThat(row.getInt("gc_grace_seconds")).isEqualTo(1234567890);
assertThat(row.getInt("min_index_interval")).isEqualTo(6);
assertThat(row.getInt("max_index_interval")).isEqualTo(8);
assertThat(row.getString("key_aliases")).isEqualTo("[\"a\",\"b\"]");
assertThat(row.getDouble("local_read_repair_chance")).isEqualTo(0.84);
assertThat(row.getInt("max_compaction_threshold")).isEqualTo(3);
assertThat(row.getInt("memtable_flush_period_in_ms")).isEqualTo(1234567890);
assertThat(row.getInt("min_compaction_threshold")).isEqualTo(2);
assertThat(row.getDouble("read_repair_chance")).isEqualTo(0.123456);
assertThat(row.getString("speculative_retry")).isEqualTo("50.0PERCENTILE");
}
}
use of com.datastax.driver.core.utils.CassandraVersion in project java-driver by datastax.
the class IndexMetadataTest method should_create_metadata_for_values_index_on_mixed_case_column.
@Test(groups = "short")
@CassandraVersion(value = "2.1", description = "index names with quoted identifiers and collection indexes not supported until 2.1")
public void should_create_metadata_for_values_index_on_mixed_case_column() {
// 3.0 assumes the 'values' keyword if index on a collection
String createValuesIndex = ccm().getCassandraVersion().getMajor() > 2 ? String.format("CREATE INDEX \"MixedCaseIndex\" ON %s.indexing (values(\"MixedCaseColumn\"));", keyspace) : String.format("CREATE INDEX \"MixedCaseIndex\" ON %s.indexing (\"MixedCaseColumn\");", keyspace);
session().execute(createValuesIndex);
ColumnMetadata column = getColumn("\"MixedCaseColumn\"");
IndexMetadata index = getIndex("\"MixedCaseIndex\"");
assertThat(index).hasName("MixedCaseIndex").hasParent((TableMetadata) column.getParent()).isNotCustomIndex().hasTarget(ccm().getCassandraVersion().getMajor() > 2 ? "values(\"MixedCaseColumn\")" : "\"MixedCaseColumn\"").hasKind(COMPOSITES).asCqlQuery(createValuesIndex);
assertThat((TableMetadata) column.getParent()).hasIndex(index);
}
use of com.datastax.driver.core.utils.CassandraVersion in project java-driver by datastax.
the class IndexMetadataTest method should_create_metadata_for_index_on_map_entries.
@Test(groups = "short")
@CassandraVersion("2.2.0")
public void should_create_metadata_for_index_on_map_entries() {
String createEntriesIndex = String.format("CREATE INDEX map_entries_index ON %s.indexing (entries(map_entries));", keyspace);
session().execute(createEntriesIndex);
ColumnMetadata column = getColumn("map_entries");
IndexMetadata index = getIndex("map_entries_index");
assertThat(index).hasName("map_entries_index").hasParent((TableMetadata) column.getParent()).isNotCustomIndex().hasTarget("entries(map_entries)").hasKind(COMPOSITES).asCqlQuery(createEntriesIndex);
assertThat((TableMetadata) column.getParent()).hasIndex(index);
}
Aggregations