LuceneIndexLanguageTracker { public void reset(long timeoutInMillis) throws Exception { lock.lock(); try { lazyInit(); final ConfigurableApplicationContext context = ApplicationContextHolder.get(); DirectoryFactory directoryFactory = context.getBean(DirectoryFactory.class); waitForReadersToClose(timeoutInMillis); taxonomyIndexTracker.reset(); close(0, false); directoryFactory.resetIndex(); init(); } finally { lock.unlock(); } } LuceneIndexLanguageTracker(); IndexAndTaxonomy acquire(final String preferredLang, final long versionToken); void maybeRefreshBlocking(); void commit(); void addDocument(IndexInformation info); void open(String language); void reset(long timeoutInMillis); @PreDestroy synchronized void destroy(); void close(long timeoutInMillis, boolean closeTaxonomy, boolean lazyInitRequired); void close(long timeoutInMillis, boolean closeTaxonomy); void optimize(); void deleteDocuments(final Term term);  }
@Test(expected = TimeoutException.class) public void testResetThrowsExceptionWhenReadersAreNotClosed() throws Exception { GeonetworkDataDirectory datadir = Mockito.mock(GeonetworkDataDirectory.class); Mockito.when(datadir.getLuceneDir()).thenReturn(folder.getRoot().toPath()); FSDirectoryFactory directoryFactory = new FSDirectoryFactory(); LuceneConfig luceneConfig = Mockito.mock(LuceneConfig.class); Mockito.when(luceneConfig.commitInterval()).thenReturn(1L); Mockito.when(luceneConfig.useNRTManagerReopenThread()).thenReturn(false); Mockito.when(luceneConfig.getTaxonomyConfiguration()).thenReturn(new FacetsConfig()); final ConfigurableApplicationContext applicationContext = Mockito.mock(ConfigurableApplicationContext.class); ApplicationContextHolder.set(applicationContext); Mockito.when(applicationContext.getBean(GeonetworkDataDirectory.class)).thenReturn(datadir); Mockito.when(applicationContext.getBean(DirectoryFactory.class)).thenReturn(directoryFactory); Mockito.when(applicationContext.getBean(LuceneConfig.class)).thenReturn(luceneConfig); final LuceneIndexLanguageTracker tracker = new LuceneIndexLanguageTracker(); addDocumentAndAssertCorrectlyAdded(tracker); tracker.reset(500); }