Repository: cassandra Updated Branches: refs/heads/trunk faa27d0fc -> 55d70173b
Add keyspace and table name in schema validation exception Patch by Jay Zhuang; Reviewed by Jaydeepkumar Chovatia for CASSANDRA-13845 Project: http://git-wip-us.apache.org/repos/asf/cassandra/repo Commit: http://git-wip-us.apache.org/repos/asf/cassandra/commit/55d70173 Tree: http://git-wip-us.apache.org/repos/asf/cassandra/tree/55d70173 Diff: http://git-wip-us.apache.org/repos/asf/cassandra/diff/55d70173 Branch: refs/heads/trunk Commit: 55d70173b8945987308e8c89166cfbcf6b2e3f06 Parents: faa27d0 Author: Jay Zhuang <jay.zhu...@yahoo.com> Authored: Wed Sep 6 15:12:46 2017 -0700 Committer: Jeff Jirsa <jji...@apple.com> Committed: Fri Sep 8 17:41:33 2017 -0700 ---------------------------------------------------------------------- CHANGES.txt | 1 + .../apache/cassandra/schema/TableMetadata.java | 2 +- .../cassandra/schema/MigrationManagerTest.java | 40 ++++++++++++++++++++ 3 files changed, 42 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cassandra/blob/55d70173/CHANGES.txt ---------------------------------------------------------------------- diff --git a/CHANGES.txt b/CHANGES.txt index 8311162..b63485e 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -1,4 +1,5 @@ 4.0 + * Add keyspace and table name in schema validation exception (CASSANDRA-13845) * Emit metrics whenever we hit tombstone failures and warn thresholds (CASSANDRA-13771) * Make netty EventLoopGroups daemon threads (CASSANDRA-13837) * Race condition when closing stream sessions (CASSANDRA-13852) http://git-wip-us.apache.org/repos/asf/cassandra/blob/55d70173/src/java/org/apache/cassandra/schema/TableMetadata.java ---------------------------------------------------------------------- diff --git a/src/java/org/apache/cassandra/schema/TableMetadata.java b/src/java/org/apache/cassandra/schema/TableMetadata.java index 86964cc..d50a9bb 100644 --- a/src/java/org/apache/cassandra/schema/TableMetadata.java +++ b/src/java/org/apache/cassandra/schema/TableMetadata.java @@ -507,7 +507,7 @@ public final class TableMetadata private void except(String format, Object... args) { - throw new ConfigurationException(format(format, args)); + throw new ConfigurationException(keyspace + "." + name + ": " +format(format, args)); } @Override http://git-wip-us.apache.org/repos/asf/cassandra/blob/55d70173/test/unit/org/apache/cassandra/schema/MigrationManagerTest.java ---------------------------------------------------------------------- diff --git a/test/unit/org/apache/cassandra/schema/MigrationManagerTest.java b/test/unit/org/apache/cassandra/schema/MigrationManagerTest.java index 07640c3..6247c02 100644 --- a/test/unit/org/apache/cassandra/schema/MigrationManagerTest.java +++ b/test/unit/org/apache/cassandra/schema/MigrationManagerTest.java @@ -26,7 +26,9 @@ import java.util.function.Supplier; import com.google.common.collect.ImmutableMap; import org.junit.BeforeClass; +import org.junit.Rule; import org.junit.Test; +import org.junit.rules.ExpectedException; import org.junit.runner.RunWith; import org.apache.cassandra.OrderedJUnit4ClassRunner; @@ -69,6 +71,9 @@ public class MigrationManagerTest private static final String TABLE2 = "standard2"; private static final String TABLE1i = "indexed1"; + @Rule + public ExpectedException thrown = ExpectedException.none(); + @BeforeClass public static void defineSchema() throws ConfigurationException { @@ -525,6 +530,41 @@ public class MigrationManagerTest assertFalse(new File(desc.filenameFor(Component.DATA)).exists()); } + @Test + public void testValidateNullKeyspace() throws Exception + { + TableMetadata.Builder builder = TableMetadata.builder(null, TABLE1).addPartitionKeyColumn("partitionKey", BytesType.instance); + + TableMetadata table1 = builder.build(); + thrown.expect(ConfigurationException.class); + thrown.expectMessage(null + "." + TABLE1 + ": Keyspace name must not be empty"); + table1.validate(); + } + + @Test + public void testValidateCompatibilityIDMismatch() throws Exception + { + TableMetadata.Builder builder = TableMetadata.builder(KEYSPACE1, TABLE1).addPartitionKeyColumn("partitionKey", BytesType.instance); + + TableMetadata table1 = builder.build(); + TableMetadata table2 = table1.unbuild().id(TableId.generate()).build(); + thrown.expect(ConfigurationException.class); + thrown.expectMessage(KEYSPACE1 + "." + TABLE1 + ": Table ID mismatch"); + table1.validateCompatibility(table2); + } + + @Test + public void testValidateCompatibilityNameMismatch() throws Exception + { + TableMetadata.Builder builder1 = TableMetadata.builder(KEYSPACE1, TABLE1).addPartitionKeyColumn("partitionKey", BytesType.instance); + TableMetadata.Builder builder2 = TableMetadata.builder(KEYSPACE1, TABLE2).addPartitionKeyColumn("partitionKey", BytesType.instance); + TableMetadata table1 = builder1.build(); + TableMetadata table2 = builder2.build(); + thrown.expect(ConfigurationException.class); + thrown.expectMessage(KEYSPACE1 + "." + TABLE1 + ": Table mismatch"); + table1.validateCompatibility(table2); + } + private TableMetadata addTestTable(String ks, String cf, String comment) { return --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@cassandra.apache.org For additional commands, e-mail: commits-h...@cassandra.apache.org