public TableMetadataAssert isCompactStorage() { assertThat(actual.getOptions().isCompactStorage()).isTrue(); return this; }
public TableMetadataAssert hasComment(String comment) { assertThat(actual.getOptions().getComment()).isEqualTo(comment); return this; }
public TableMetadataAssert isNotCompactStorage() { assertThat(actual.getOptions().isCompactStorage()).isFalse(); return this; }
public TableMetadataAssert doesNotHaveComment(String comment) { assertThat(actual.getOptions().getComment()).isNotEqualTo(comment); return this; }
/** * Ensures that if a table is configured with change data capture enabled that {@link * TableOptionsMetadata#isCDC()} returns true for that table. * * @test_category metadata * @jira_ticket JAVA-1287 * @jira_ticket CASSANDRA-12041 */ @Test(groups = "short") public void should_parse_cdc_from_table_options() { // given // create a simple table with cdc as true. String cql = String.format( "CREATE TABLE %s.cdc_table (\n" + " k text,\n" + " c int,\n" + " v timeuuid,\n" + " PRIMARY KEY (k, c)\n" + ") WITH cdc=true;", keyspace); session().execute(cql); // when retrieving the table's metadata. TableMetadata table = cluster().getMetadata().getKeyspace(keyspace).getTable("cdc_table"); // then the table's options should have cdc as true. assertThat(table.getOptions().isCDC()).isEqualTo(true); assertThat(table.asCQLQuery(true)).contains("cdc = true"); } }
@Test(groups = "short") public void should_escape_single_quote_table_comment() { // given String cql = String.format( "CREATE TABLE %s.single_quote (\n" + " c1 int PRIMARY KEY\n" + ") WITH comment = 'comment with single quote '' should work'", keyspace); // when session().execute(cql); TableMetadata table = cluster().getMetadata().getKeyspace(keyspace).getTable("single_quote"); // then assertThat(table.getOptions().getComment()) .isEqualTo("comment with single quote ' should work"); assertThat(table.asCQLQuery()).contains("comment = 'comment with single quote '' should work'"); }
cluster().getMetadata().getKeyspace(keyspace).getTable("table_with_extensions"); assertThat(table.getOptions().getExtensions()).isEqualTo(extensions);
assertThat(tm.getClusteringOrder().size()).isEqualTo(1); assertThat(tm.getId()).isEqualTo(new UUID(0L, 0L)); assertThat(tm.getOptions()).isNull(); assertThat(tm.getKeyspace()).isEqualTo(km); assertThat(tm.asCQLQuery())
assertThat(table.getOptions().getReadRepairChance()).isEqualTo(0.5); assertThat(table.getOptions().getLocalReadRepairChance()).isEqualTo(0.6); assertThat(table.getOptions().getGcGraceInSeconds()).isEqualTo(42); assertThat(table.getOptions().getBloomFilterFalsePositiveChance()).isEqualTo(0.01); assertThat(table.getOptions().getComment()).isEqualTo("My awesome table"); assertThat(table.getOptions().getCaching()).contains(entry("keys", "ALL")); assertThat(table.getOptions().getCaching()).contains(entry("rows_per_partition", "10")); assertThat(table.getOptions().getCompaction()) .contains(entry("class", "org.apache.cassandra.db.compaction.LeveledCompactionStrategy")); assertThat(table.getOptions().getCompaction()).contains(entry("sstable_size_in_mb", "15")); assertThat(table.getOptions().getCompression()) .contains( entry( assertThat(table.getOptions().getCompression()) .contains(entry("chunk_length_in_kb", "128")); // note the "in" prefix assertThat(table.getOptions().getDefaultTimeToLive()).isEqualTo(0); assertThat(table.getOptions().getSpeculativeRetry()).isEqualTo("99.9PERCENTILE"); assertThat(table.getOptions().getIndexInterval()).isNull(); assertThat(table.getOptions().getMinIndexInterval()).isEqualTo(128); assertThat(table.getOptions().getMaxIndexInterval()).isEqualTo(2048); assertThat(table.getOptions().getReplicateOnWrite()).isTrue(); // default assertThat(table.getOptions().getCrcCheckChance()).isEqualTo(0.5); assertThat(table.getOptions().getExtensions()).isEmpty(); // default assertThat(table.getOptions().getMemtableFlushPeriodInMs()).isEqualTo(1000); assertThat(table.asCQLQuery()) .contains("read_repair_chance = 0.5") assertThat(table.getOptions().getReadRepairChance()).isEqualTo(0.5);
assertThat(table.getOptions().getCompression()) .contains(entry("class", "org.apache.cassandra.io.compress.DeflateCompressor")) .contains(entry("chunk_length_in_kb", "128"));
static boolean hasUpgrade1_defaultTtl(KeyspaceMetadata keyspaceMetadata) { // TODO: we need some approach to forward-check compatibility as well. // backward: this code knows the current schema is too old. // forward: this code knows the current schema is too new. return keyspaceMetadata.getTable("traces").getOptions().getDefaultTimeToLive() > 0; }
static Map<String, String> readMetadata(String keyspace, Cluster cluster) { Map<String, String> metadata = new LinkedHashMap<>(); try (Session ignored = cluster.connect()) { KeyspaceMetadata keyspaceMetadata = getKeyspaceMetadata(keyspace, cluster); Map<String, String> replication = keyspaceMetadata.getReplication(); if ("SimpleStrategy".equals(replication.get("class")) && "1".equals(replication.get("replication_factor"))) { LOG.warn("running with RF=1, this is not suitable for production. Optimal is 3+"); } Map<String, String> tracesCompaction = keyspaceMetadata.getTable("traces").getOptions().getCompaction(); metadata.put("traces.compaction.class", tracesCompaction.get("class")); } return metadata; }
static boolean hasUpgrade1_defaultTtl(KeyspaceMetadata keyspaceMetadata) { // TODO: we need some approach to forward-check compatibility as well. // backward: this code knows the current schema is too old. // forward: this code knows the current schema is too new. return keyspaceMetadata.getTable("traces").getOptions().getDefaultTimeToLive() > 0; }
static Metadata readMetadata(Session session) { KeyspaceMetadata keyspaceMetadata = getKeyspaceMetadata(session); Map<String, String> replication = keyspaceMetadata.getReplication(); if ("SimpleStrategy".equals(replication.get("class")) && "1".equals(replication.get("replication_factor"))) { LOG.warn("running with RF=1, this is not suitable for production. Optimal is 3+"); } String compactionClass = keyspaceMetadata.getTable("traces").getOptions().getCompaction().get("class"); boolean hasDefaultTtl = hasUpgrade1_defaultTtl(keyspaceMetadata); if (!hasDefaultTtl) { LOG.warn( "schema lacks default ttls: apply {}, or set CassandraStorage.ensureSchema=true", UPGRADE_1); } return new Metadata(compactionClass, hasDefaultTtl); }
public TableMetadataAssert hasComment(String comment) { assertThat(actual.getOptions().getComment()).isEqualTo(comment); return this; }
public TableMetadataAssert isCompactStorage() { assertThat(actual.getOptions().isCompactStorage()).isTrue(); return this; }
public TableMetadataAssert isNotCompactStorage() { assertThat(actual.getOptions().isCompactStorage()).isFalse(); return this; }
public TableMetadataAssert doesNotHaveComment(String comment) { assertThat(actual.getOptions().getComment()).isNotEqualTo(comment); return this; }
/** * Get the comment associated with a {@code tablename} of a {@code keyspace}. * * @param keyspace The target keyspace. * @param tablename The target table. * @return The comment or null if the table does not exist in the keyspace, or the client is not * connected to Cassandra. */ public String getTableComment(String keyspace, String tablename) { String result = null; if (clusterMetadata != null && clusterMetadata.getKeyspace(keyspace) != null) { result = clusterMetadata.getKeyspace(keyspace).getTable(tablename).getOptions().getComment(); } return result; }
Map<String, String> getCompressionOptions(final String name) throws BackendException { final KeyspaceMetadata keyspaceMetadata = Option.of(this.cluster.getMetadata().getKeyspace(this.keyspace)) .getOrElseThrow(() -> new PermanentBackendException(String.format("Unknown keyspace '%s'", this.keyspace))); return Option.of(keyspaceMetadata.getTable(name)) .map(tableMetadata -> tableMetadata.getOptions().getCompression()) .getOrElseThrow(() -> new PermanentBackendException(String.format("Unknown table '%s'", name))); }