Use result size for built index test

Patch by Jorge Bay Gondra; reviewed by Sam Tunnicliffe for CASSANDRA-15565
This commit is contained in:
Jorge Bay Gondra 2020-03-11 10:19:28 +00:00 committed by Sam Tunnicliffe
parent af097240bc
commit c81d7dcc09
1 changed files with 19 additions and 4 deletions

View File

@ -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