Skip to content

Commit f996e74

Browse files
authored
Allow AlreadyClosedException to be a possible outcome of injecting fake exceptions in TestIndexFileDeleter (#15545)
* Allow AlreadyClosedException to be a possible outcome of injecting fake exceptions in TestIndexFileDeleter * Fix duplicate branches.
1 parent c7c507f commit f996e74

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

lucene/core/src/test/org/apache/lucene/index/TestIndexFileDeleter.java

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import org.apache.lucene.document.Document;
3131
import org.apache.lucene.document.Field;
3232
import org.apache.lucene.index.IndexWriterConfig.OpenMode;
33+
import org.apache.lucene.store.AlreadyClosedException;
3334
import org.apache.lucene.store.Directory;
3435
import org.apache.lucene.store.IOContext;
3536
import org.apache.lucene.store.IndexInput;
@@ -41,11 +42,6 @@
4142
import org.apache.lucene.tests.util.TestUtil;
4243
import org.apache.lucene.util.InfoStream;
4344

44-
/*
45-
Verify we can read the pre-2.1 file format, do searches
46-
against it, and add documents to it.
47-
*/
48-
4945
public class TestIndexFileDeleter extends LuceneTestCase {
5046

5147
public void testDeleteLeftoverFiles() throws IOException {
@@ -440,7 +436,6 @@ public void eval(MockDirectoryWrapper dir) throws IOException {
440436
});
441437

442438
IndexWriterConfig iwc = newIndexWriterConfig(new MockAnalyzer(random()));
443-
// iwc.setMergeScheduler(new SerialMergeScheduler());
444439
MergeScheduler ms = iwc.getMergeScheduler();
445440
if (ms instanceof ConcurrentMergeScheduler) {
446441
final ConcurrentMergeScheduler suppressFakeFail =
@@ -486,8 +481,12 @@ protected void handleMergeException(Throwable exc) {
486481
}
487482
} catch (Throwable t) {
488483
if (t.toString().contains("fake fail")
489-
|| (t.getCause() != null && t.getCause().toString().contains("fake fail"))) {
490-
// ok
484+
|| (t.getCause() != null && t.getCause().toString().contains("fake fail"))
485+
|| t instanceof AlreadyClosedException) {
486+
// All these conditions are fine.
487+
// AlreadyClosedException can happen if the injected exception (RuntimeException("fake
488+
// fail")) happened inside the concurrent merges and this closed the index writer's
489+
// reader pool.
491490
} else {
492491
throw t;
493492
}

0 commit comments

Comments
 (0)