Source:
<code>public void testWriteOnlyIndex() throws Throwable { LoadTypeConstrainedIndex index = null; try { LoadTypeConstrainedIndex.setSupportedLoad(LoadType.WRITE); String tableName = createTable("CREATE TABLE %s (pk int, ck int, value int, PRIMARY KEY (pk, ck))"); String indexName = createIndex("CREATE CUSTOM INDEX ON %s (value) USING '" + LoadTypeConstrainedIndex.class.getName() + "'"); assertTrue(waitForIndex(keyspace(), tableName, indexName)); execute("INSERT INTO %s (pk, ck, value) VALUES (?, ?, ?)", 1, 1, 1); index = (LoadTypeConstrainedIndex) getCurrentColumnFamilyStore().indexManager.getIndexByName(indexName); assertEquals(1, index.rowsInserted.size()); <START> try { execute("SELECT value FROM %s WHERE value = 1"); fail(); } catch (IndexNotAvailableException e) { assertTrue(true); } <END> index.reset(); getCurrentColumnFamilyStore().indexManager.rebuildIndexesBlocking(ImmutableSet.of(indexName)); execute("INSERT INTO %s (pk, ck, value) VALUES (?, ?, ?)", 2, 1, 1); assertEquals(1, index.rowsInserted.size()); execute("SELECT value FROM %s WHERE value = 1"); execute("DROP index " + KEYSPACE + "." + indexName); index.reset(); LoadTypeConstrainedIndex.setSupportedLoad(LoadType.WRITE); index.failInit = true; indexName = createIndex("CREATE CUSTOM INDEX ON %s (value) USING '" + LoadTypeConstrainedIndex.class.getName() + "'"); assertTrue(waitForIndexBuilds(keyspace(), indexName)); execute("INSERT INTO %s (pk, ck, value) VALUES (?, ?, ?)", 1, 1, 1); assertEquals(0, index.rowsInserted.size()); try { execute("SELECT value FROM %s WHERE value = 1"); fail(); } catch (IndexNotAvailableException e) { assertTrue(true); } execute("DROP index " + KEYSPACE + "." + indexName); } finally { if (index != null) index.reset(); } }</code><technical_language>Nit: provided assertInvalidThrow: suggestion assertInvalidThrow(IndexNotAvailableException.class, "SELECT %s = 1");</technical_language>

Target:
public void testWriteOnlyIndex() throws Throwable { String tableName = createTable("CREATE TABLE %s (pk int, ck int, value int, PRIMARY KEY (pk, ck))"); String indexName = createIndex("CREATE CUSTOM INDEX ON %s (value) USING '" + WriteOnlyOnFailureIndex.class.getName() + "'"); assertTrue(waitForIndex(keyspace(), tableName, indexName)); execute("SELECT value FROM %s WHERE value = 1"); execute("INSERT INTO %s (pk, ck, value) VALUES (?, ?, ?)", 1, 1, 1); WriteOnlyOnFailureIndex index = (WriteOnlyOnFailureIndex) getCurrentColumnFamilyStore().indexManager.getIndexByName(indexName); assertEquals(1, index.rowsInserted.size()); getCurrentColumnFamilyStore().indexManager.rebuildIndexesBlocking(ImmutableSet.of(indexName)); assertEquals(1, index.rowsInserted.size()); execute("SELECT value FROM %s WHERE value = 1"); execute("INSERT INTO %s (pk, ck, value) VALUES (?, ?, ?)", 2, 1, 1); assertEquals(2, index.rowsInserted.size()); dropIndex(format("DROP INDEX %s.%s", KEYSPACE, indexName)); WriteOnlyOnFailureIndex.failInit = true; indexName = createIndex("CREATE CUSTOM INDEX ON %s (value) USING '" + WriteOnlyOnFailureIndex.class.getName() + "'"); index = (WriteOnlyOnFailureIndex) getCurrentColumnFamilyStore().indexManager.getIndexByName(indexName); assertTrue(waitForIndexBuilds(keyspace(), indexName)); execute("INSERT INTO %s (pk, ck, value) VALUES (?, ?, ?)", 1, 1, 1); assertEquals(1, index.rowsInserted.size()); assertInvalidThrow(IndexNotAvailableException.class, "SELECT value FROM %s WHERE value = 1"); index.reset(); getCurrentColumnFamilyStore().indexManager.rebuildIndexesBlocking(ImmutableSet.of(indexName)); assertEquals(2, index.rowsInserted.size()); execute("SELECT value FROM %s WHERE value = 1"); execute("INSERT INTO %s (pk, ck, value) VALUES (?, ?, ?)", 2, 1, 1); assertEquals(3, index.rowsInserted.size()); dropIndex(format("DROP INDEX %s.%s", KEYSPACE, indexName)); }