@Test(groups = "unit") public void should_create_table_with_cdc_true() throws Exception { // When SchemaStatement statement = createTable("test") .addPartitionKey("id", DataType.bigint()) .addColumn("name", DataType.text()) .withOptions() .cdc(true); // Then assertThat(statement.getQueryString()) .isEqualTo( "\n\tCREATE TABLE test(\n\t\t" + "id bigint,\n\t\t" + "name text,\n\t\t" + "PRIMARY KEY(id))\n\t" + "WITH cdc = true"); }
@Test(groups = "unit", expectedExceptions = IllegalArgumentException.class) public void should_fail_when_read_repair_chance_out_of_bound() throws Exception { createTable("test") .addPartitionKey("id", DataType.bigint()) .addColumn("name", DataType.text()) .withOptions() .readRepairChance(1.3); }
@Test(groups = "unit") public void should_create_table_with_cdc_false() throws Exception { // When SchemaStatement statement = createTable("test") .addPartitionKey("id", DataType.bigint()) .addColumn("name", DataType.text()) .withOptions() .cdc(false); // Then assertThat(statement.getQueryString()) .isEqualTo( "\n\tCREATE TABLE test(\n\t\t" + "id bigint,\n\t\t" + "name text,\n\t\t" + "PRIMARY KEY(id))\n\t" + "WITH cdc = false"); }
@Test(groups = "unit", expectedExceptions = IllegalArgumentException.class) public void should_fail_when_read_repair_chance_negative() throws Exception { createTable("test") .addPartitionKey("id", DataType.bigint()) .addColumn("name", DataType.text()) .withOptions() .readRepairChance(-1.3); }
@Test(groups = "unit") public void should_create_table_with_speculative_retry_none() throws Exception { // When SchemaStatement statement = createTable("test") .addPartitionKey("id", DataType.bigint()) .addColumn("name", DataType.text()) .withOptions() .speculativeRetry(noSpeculativeRetry()); // Then assertThat(statement.getQueryString()) .isEqualTo( "\n\tCREATE TABLE test(\n\t\t" + "id bigint,\n\t\t" + "name text,\n\t\t" + "PRIMARY KEY(id))\n\t" + "WITH speculative_retry = 'NONE'"); }
@Test(groups = "unit") public void should_create_table_with_speculative_retry_in_percentile() throws Exception { // When SchemaStatement statement = createTable("test") .addPartitionKey("id", DataType.bigint()) .addColumn("name", DataType.text()) .withOptions() .speculativeRetry(percentile(95)); // Then assertThat(statement.getQueryString()) .isEqualTo( "\n\tCREATE TABLE test(\n\t\t" + "id bigint,\n\t\t" + "name text,\n\t\t" + "PRIMARY KEY(id))\n\t" + "WITH speculative_retry = '95percentile'"); }
@Test(groups = "unit") public void should_create_table_with_speculative_retry_in_milli_secs() throws Exception { // When SchemaStatement statement = createTable("test") .addPartitionKey("id", DataType.bigint()) .addColumn("name", DataType.text()) .withOptions() .speculativeRetry(millisecs(12)); // Then assertThat(statement.getQueryString()) .isEqualTo( "\n\tCREATE TABLE test(\n\t\t" + "id bigint,\n\t\t" + "name text,\n\t\t" + "PRIMARY KEY(id))\n\t" + "WITH speculative_retry = '12ms'"); }
@Test(groups = "unit") public void should_build_table_with_custom_option() throws Exception { // When SchemaStatement statement = createTable("test") .addPartitionKey("id", DataType.bigint()) .addColumn("name", DataType.text()) .withOptions() .freeformOption("key1", "value1") .freeformOption("key2", 1.0); // Then assertThat(statement.getQueryString()) .isEqualTo( "\n\tCREATE TABLE test(\n\t\t" + "id bigint,\n\t\t" + "name text,\n\t\tPRIMARY KEY(id))\n\t" + "WITH key1 = 'value1' " + "AND key2 = 1.0"); }
@Test(groups = "unit", expectedExceptions = IllegalArgumentException.class) public void should_fail_when_negative_rows_per_partition() throws Exception { createTable("test") .addPartitionKey("id", DataType.bigint()) .addColumn("name", DataType.text()) .withOptions() .caching(KeyCaching.ALL, rows(-3)); }
@Test(groups = "unit", expectedExceptions = IllegalStateException.class) public void should_fail_when_both_caching_versions() throws Exception { createTable("test") .addPartitionKey("id", DataType.bigint()) .addColumn("name", DataType.text()) .withOptions() .caching(Caching.KEYS_ONLY) .caching(KeyCaching.ALL, allRows()) .getQueryString(); }
.addPartitionKey("id", DataType.bigint()) .addColumn("name", DataType.text()) .withOptions() .caching(KeyCaching.ALL, rows(100)); .addPartitionKey("id", DataType.bigint()) .addColumn("name", DataType.text()) .withOptions() .caching(KeyCaching.ALL, allRows());
@Test(groups = "unit", expectedExceptions = IllegalArgumentException.class) public void should_fail_when_blank_clustering_order_column_provided() throws Exception { createTable("test") .addPartitionKey("id", DataType.bigint()) .addClusteringColumn("col1", DataType.uuid()) .addClusteringColumn("col2", DataType.uuid()) .addColumn("name", DataType.text()) .withOptions() .clusteringOrder("", Direction.DESC); }
@Test(groups = "unit", expectedExceptions = IllegalArgumentException.class) public void should_fail_when_clustering_order_column_does_not_match_declared_clustering_keys() throws Exception { createTable("test") .addPartitionKey("id", DataType.bigint()) .addClusteringColumn("col1", DataType.uuid()) .addClusteringColumn("col2", DataType.uuid()) .addColumn("name", DataType.text()) .withOptions() .clusteringOrder("col3", Direction.ASC); }
@Test(groups = "unit") public void should_create_table_with_compact_storage() throws Exception { // When SchemaStatement statement = createTable("test") .addPartitionKey("id", DataType.bigint()) .addClusteringColumn("col1", DataType.uuid()) .addClusteringColumn("col2", DataType.uuid()) .addColumn("name", DataType.text()) .withOptions() .compactStorage(); // Then assertThat(statement.getQueryString()) .isEqualTo( "\n\tCREATE TABLE test(\n\t\t" + "id bigint,\n\t\t" + "col1 uuid,\n\t\t" + "col2 uuid,\n\t\t" + "name text,\n\t\t" + "PRIMARY KEY(id, col1, col2))\n\t" + "WITH COMPACT STORAGE"); }
@Test( groups = "unit", expectedExceptions = IllegalStateException.class, expectedExceptionsMessageRegExp = "Cannot create table 'test' with compact storage and static columns '\\[stat\\]'") public void should_fail_creating_table_with_static_columns_and_compact_storage() throws Exception { createTable("test") .addPartitionKey("pk", DataType.bigint()) .addClusteringColumn("cluster", DataType.uuid()) .addStaticColumn("stat", DataType.text()) .withOptions() .compactStorage() .getQueryString(); } }
@Test(groups = "unit") public void should_create_table_with_clustering_order() throws Exception { // When SchemaStatement statement = createTable("test") .addPartitionKey("id", DataType.bigint()) .addClusteringColumn("col1", DataType.uuid()) .addClusteringColumn("col2", DataType.uuid()) .addColumn("name", DataType.text()) .withOptions() .clusteringOrder("col1", Direction.ASC) .clusteringOrder("col2", Direction.DESC); // Then assertThat(statement.getQueryString()) .isEqualTo( "\n\tCREATE TABLE test(\n\t\t" + "id bigint,\n\t\t" + "col1 uuid,\n\t\t" + "col2 uuid,\n\t\t" + "name text,\n\t\t" + "PRIMARY KEY(id, col1, col2))\n\t" + "WITH CLUSTERING ORDER BY(col1 ASC, col2 DESC)"); }
.addClusteringColumn("c", DataType.cint()) .addClusteringColumn("d", DataType.cint()) .withOptions() .compactStorage());
.addPartitionKey("zkey", DataType.text()) .addColumn("a", ks.getUserType("atype").copy(true)) .withOptions() .compactionOptions(SchemaBuilder.leveledStrategy().ssTableSizeInMB(95))); } else { .addPartitionKey("zkey", DataType.text()) .addColumn("a", DataType.cint()) .withOptions() .compactionOptions(SchemaBuilder.leveledStrategy().ssTableSizeInMB(95)));
.addClusteringColumn("col2", DataType.uuid()) .addColumn("name", DataType.text()) .withOptions() .clusteringOrder("col1", Direction.ASC) .clusteringOrder("col2", Direction.DESC)
.addClusteringColumn(TIMESTAMP, DataType.bigint()) .addColumn(VALUE, DataType.blob()) .withOptions() .bloomFilterFPChance(falsePositive(tableMetadata.hasNegativeLookups(), appendHeavyReadLight)) .caching(SchemaBuilder.Caching.KEYS_ONLY)