NRTIndexFactory implements Closeable { @Nullable public synchronized NRTIndex createIndex(LuceneIndexDefinition definition) { if (!(definition.isNRTIndexingEnabled() || definition.isSyncIndexingEnabled())){ return null; } String indexPath = definition.getIndexPath(); NRTIndex current = new NRTIndex(definition, indexCopier, getRefreshPolicy(definition), getPrevious(indexPath), statisticsProvider, directoryFactory, assertAllResourcesClosed); indexes.put(indexPath, current); closeLast(indexPath); return current; } NRTIndexFactory(IndexCopier indexCopier, StatisticsProvider statisticsProvider);  NRTIndexFactory(IndexCopier indexCopier, Clock clock, long refreshDeltaInSecs,
                           StatisticsProvider statisticsProvider); @Nullable synchronized NRTIndex createIndex(LuceneIndexDefinition definition); @Override void close(); void setDirectoryFactory(NRTDirectoryFactory directoryFactory); void setAssertAllResourcesClosed(boolean assertAllResourcesClosed);  }
@Test public void noIndexForAsync() throws Exception{ LuceneIndexDefinition idxDefn = new LuceneIndexDefinition(root, builder.getNodeState(), "/foo"); assertNull(indexFactory.createIndex(idxDefn)); }
@Test public void indexCreationAndCloserWithUpdate() throws Exception{ LuceneIndexDefinition idxDefn = getNRTIndexDefinition("/foo"); Document d = new Document(); d.add(newPathField("/a/b")); NRTIndex idx1 = indexFactory.createIndex(idxDefn); idx1.getWriter().updateDocument("/a/b", d); assertEquals(1, idx1.getReaders().size()); NRTIndex idx2 = indexFactory.createIndex(idxDefn); idx2.getWriter().updateDocument("/a/b", d); idx1.getWriter().updateDocument("/a/b", d); assertEquals(2, idx2.getReaders().size()); NRTIndex idx3 = indexFactory.createIndex(idxDefn); NRTIndex idx4 = indexFactory.createIndex(idxDefn); assertTrue(idx1.isClosed()); }