model1 = new IndexerModelImpl(zk1, "/test");
model1.registerListener(listener);
// Create an indexer -- verify INDEXER_ADDED event
IndexerDefinition indexer1 = new IndexerDefinitionBuilder()
.name("indexer1")
.configuration("my-conf".getBytes("UTF-8"))
.build();
model1.addIndexer(indexer1);
listener.waitForEvents(1);
listener.verifyEvents(new IndexerModelEvent(IndexerModelEventType.INDEXER_ADDED, "indexer1"));
// Verify that a fresh indexer model has the index
model2 = new IndexerModelImpl(zk2, "/test");
Collection<IndexerDefinition> indexers = model2.getIndexers();
assertEquals("Expected indexer1, got " + indexers, 1, indexers.size());
assertTrue(model2.hasIndexer("indexer1"));
// Update the indexer -- verify INDEXER_UPDATED event
indexer1 = new IndexerDefinitionBuilder()
.startFrom(indexer1)
.incrementalIndexingState(IncrementalIndexingState.SUBSCRIBE_DO_NOT_CONSUME)
.build();
String lock = model1.lockIndexer("indexer1");
model1.updateIndexer(indexer1, lock);
listener.waitForEvents(1);
listener.verifyEvents(new IndexerModelEvent(IndexerModelEventType.INDEXER_UPDATED, "indexer1"));
model1.unlockIndexer(lock);
// Delete the indexer -- verify INDEXER_DELETED event
model1.deleteIndexerInternal("indexer1");
listener.waitForEvents(1);
listener.verifyEvents(new IndexerModelEvent(IndexerModelEventType.INDEXER_DELETED, "indexer1"));
// Create some more indexes and verify we get the correct number of INDEXER_ADDED events
IndexerModelEvent[] expectedEvents = new IndexerModelEvent[9];
for (int i = 2; i <= 10; i++) {
String name = "indexer" + i;
IndexerDefinition indexer = new IndexerDefinitionBuilder()
.name(name)
.configuration("my-conf".getBytes("UTF-8"))
.build();
model1.addIndexer(indexer);
expectedEvents[i - 2] = new IndexerModelEvent(IndexerModelEventType.INDEXER_ADDED, name);
}
listener.waitForEvents(9);
listener.verifyEvents(expectedEvents);
// Terminate ZK connections: clients should automatically re-establish the connection and things
// should work as before
assertEquals(2, terminateZooKeeperConnections());
// Do another index update and check we get an event
IndexerDefinition indexer2 = new IndexerDefinitionBuilder()
.name("indexer2")
.incrementalIndexingState(IncrementalIndexingState.DO_NOT_SUBSCRIBE)
.configuration("my-conf".getBytes(Charsets.UTF_8))
.build();
lock = model1.lockIndexer("indexer2");