public void testIndexerIncrementalIndexingStates() throws Exception {
createTable("table1", "family1");
// First create an index in the default incremental indexing state (SUBSCRIBE_AND_CONSUME)
markEventCounts();
WriteableIndexerModel indexerModel = main.getIndexerModel();
IndexerDefinition indexerDef = new IndexerDefinitionBuilder()
.name("indexer1")
.configuration(Bytes.toBytes("<indexer table='table1'>" +
"<field name='field1_s' value='family1:qualifier1'/>" +
"</indexer>"))
.connectionType("solr")
.connectionParams(ImmutableMap.of("solr.zk", solrTestingUtility.getZkConnectString(),
"solr.collection", "collection1"))
.build();
indexerModel.addIndexer(indexerDef);
// wait for 2 events because: first the indexer is added (= first event), then IndexerMaster
// updates it to assign subscription (= second event), and only then IndexerSupervisor will start the indexer
waitOnEventsProcessed(2);
// Make sure the SEP and indexer processes were started
assertEquals(1, main.getIndexerSupervisor().getRunningIndexers().size());
SepTestUtil.waitOnReplicationPeerReady(peerId("indexer1"));
// Now change to DO_NOT_SUBSCRIBE_STATE
markEventCounts();
String lock = indexerModel.lockIndexer("indexer1");
indexerDef = new IndexerDefinitionBuilder()
.startFrom(indexerModel.getFreshIndexer("indexer1"))
.incrementalIndexingState(IncrementalIndexingState.DO_NOT_SUBSCRIBE)
.build();
indexerModel.updateIndexer(indexerDef, lock);
indexerModel.unlockIndexer(lock);
waitOnEventsProcessed(1);
// Verify master removed the SEP subscription and unassigned the subscription ID
SepTestUtil.waitOnReplicationPeerStopped(peerId("indexer1"));
assertNull(indexerModel.getFreshIndexer("indexer1").getSubscriptionId());
// Verify supervisor stopped the indexer
assertEquals(0, main.getIndexerSupervisor().getRunningIndexers().size());
// Change to SUBSCRIBE_DO_NOT_CONSUME
markEventCounts();
lock = indexerModel.lockIndexer("indexer1");
indexerDef = new IndexerDefinitionBuilder()
.startFrom(indexerModel.getFreshIndexer("indexer1"))
.incrementalIndexingState(IncrementalIndexingState.SUBSCRIBE_DO_NOT_CONSUME)
.build();
indexerModel.updateIndexer(indexerDef, lock);
indexerModel.unlockIndexer(lock);
waitOnEventsProcessed(1);
// Verify master registered the SEP subscription and assigned the subscription ID
SepTestUtil.waitOnReplicationPeerReady(peerId("indexer1"));
assertNotNull(indexerModel.getFreshIndexer("indexer1").getSubscriptionId());
// Verify supervisor didn't start the indexer (because in state "do no consume")
assertEquals(0, main.getIndexerSupervisor().getRunningIndexers().size());
// Change again to default SUBSCRIBE_AND_CONSUME
markEventCounts();
lock = indexerModel.lockIndexer("indexer1");
indexerDef = new IndexerDefinitionBuilder()
.startFrom(indexerModel.getFreshIndexer("indexer1"))
.incrementalIndexingState(IncrementalIndexingState.SUBSCRIBE_AND_CONSUME)
.build();
indexerModel.updateIndexer(indexerDef, lock);
indexerModel.unlockIndexer(lock);
waitOnEventsProcessed(1);
// Verify supervisor started the indexer
assertEquals(1, main.getIndexerSupervisor().getRunningIndexers().size());
}