From c81d7dcc09fa1c35f190f0baad764fbe8a024679 Mon Sep 17 00:00:00 2001 From: Jorge Bay Gondra Date: Wed, 11 Mar 2020 10:19:28 +0000 Subject: [PATCH] Use result size for built index test Patch by Jorge Bay Gondra; reviewed by Sam Tunnicliffe for CASSANDRA-15565 --- .../index/internal/CassandraIndexTest.java | 23 +++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/test/unit/org/apache/cassandra/index/internal/CassandraIndexTest.java b/test/unit/org/apache/cassandra/index/internal/CassandraIndexTest.java index 286c418664..7cea9dab81 100644 --- a/test/unit/org/apache/cassandra/index/internal/CassandraIndexTest.java +++ b/test/unit/org/apache/cassandra/index/internal/CassandraIndexTest.java @@ -488,21 +488,36 @@ public class CassandraIndexTest extends CQLTester @Test public void indexCorrectlyMarkedAsBuildAndRemoved() throws Throwable { + String selectBuiltIndexesQuery = String.format("SELECT * FROM %s.\"%s\"", + SystemKeyspace.NAME, + SystemKeyspace.BUILT_INDEXES); + UntypedResultSet rs = execute(selectBuiltIndexesQuery); + int initialSize = rs.size(); + String indexName = "build_remove_test_idx"; String tableName = createTable("CREATE TABLE %s (a int, b int, c int, PRIMARY KEY (a, b))"); createIndex(String.format("CREATE INDEX %s ON %%s(c)", indexName)); waitForIndex(KEYSPACE, tableName, indexName); // check that there are no other rows in the built indexes table - assertRows(execute(String.format("SELECT * FROM %s.\"%s\"", SystemKeyspace.NAME, SystemKeyspace.BUILT_INDEXES)), - row(KEYSPACE, indexName)); + rs = execute(selectBuiltIndexesQuery); + int sizeAfterBuild = rs.size(); + assertRowsIgnoringOrderAndExtra(rs, row(KEYSPACE, indexName)); // rebuild the index and verify the built status table getCurrentColumnFamilyStore().rebuildSecondaryIndex(indexName); waitForIndex(KEYSPACE, tableName, indexName); // check that there are no other rows in the built indexes table - assertRows(execute(String.format("SELECT * FROM %s.\"%s\"", SystemKeyspace.NAME, SystemKeyspace.BUILT_INDEXES)), - row(KEYSPACE, indexName)); + rs = execute(selectBuiltIndexesQuery); + assertEquals(sizeAfterBuild, rs.size()); + assertRowsIgnoringOrderAndExtra(rs, row(KEYSPACE, indexName)); + + // check that dropping the index removes it from the built indexes table + dropIndex("DROP INDEX %s." + indexName); + rs = execute(selectBuiltIndexesQuery); + assertEquals(initialSize, rs.size()); + rs.forEach(row -> assertFalse(row.getString("table_name").equals(KEYSPACE) // table_name is actually keyspace + && row.getString("index_name").equals(indexName))); } // this is slightly annoying, but we cannot read rows from the methods in Util as