LuceneConfig luceneConfig = Mockito.mock(LuceneConfig.class);
Mockito.when(luceneConfig.commitInterval()).thenReturn(1L);
Mockito.when(luceneConfig.useNRTManagerReopenThread()).thenReturn(false);
final LuceneIndexLanguageTracker tracker = new LuceneIndexLanguageTracker(directoryFactory, luceneConfig);
final IndexAndTaxonomy acquire = addDocumentAndAssertCorrectlyAdded(tracker);
final boolean[] tryingToReset = new boolean[1];
final boolean[] done = new boolean[1];
final Exception[] error = new Exception[1];
startThread("Close open reader thread", new Runnable() {
@Override
public void run() {
try {
while (!tryingToReset[0]) {
Thread.sleep(100);
}
acquire.indexReader.releaseToNRTManager();
} catch (Exception e) {
error[0] = e;
}
done[0] = true;
}
});
tryingToReset[0] = true;
tracker.reset(500);
while(!done[0]) {
Thread.sleep(100);
}
if (error[0] != null) {
throw error[0];
}
final IndexAndTaxonomy acquire2 = tracker.acquire(LANG, -1);
assertEquals(0, acquire2.indexReader.numDocs());
}