Do not wait on task's future if it was rejected

This commit is contained in:
Atri Sharma 2019-09-27 17:27:44 +05:30 committed by Atri Sharma
parent 15db6bfa88
commit a9cf5f6abe
2 changed files with 9 additions and 9 deletions

View File

@ -668,14 +668,20 @@ public class IndexSearcher {
search(Arrays.asList(leaves), weight, collector);
return collector;
});
boolean executedOnCallerThread = false;
try {
executor.execute(task);
} catch (RejectedExecutionException e) {
// Execute on caller thread
search(Arrays.asList(leaves), weight, collector);
topDocsFutures.add(CompletableFuture.completedFuture(collector));
executedOnCallerThread = true;
}
topDocsFutures.add(task);
// Do not add the task's future if it was not used
if (executedOnCallerThread == false) {
topDocsFutures.add(task);
}
}
final LeafReaderContext[] leaves = leafSlices[leafSlices.length - 1].leaves;
final C collector = collectors.get(leafSlices.length - 1);

View File

@ -273,8 +273,6 @@ public class TestIndexSearcher extends LuceneTestCase {
}
public void testRejectedExecution() throws IOException {
List<LeafReaderContext> leaves = reader.leaves();
AtomicInteger numExecutions = new AtomicInteger(0);
ExecutorService service = new RejectingMockExecutor();
IndexSearcher searcher = new IndexSearcher(reader, service) {
@ -290,12 +288,8 @@ public class TestIndexSearcher extends LuceneTestCase {
// To ensure that failing ExecutorService still allows query to run
// successfully
searcher.search(new MatchAllDocsQuery(), 10);
if (leaves.size() <= 1) {
assertEquals(0, numExecutions.get());
} else {
assertEquals(leaves.size() - 1, numExecutions.get());
}
TopDocs topDocs = searcher.search(new MatchAllDocsQuery(), 10);
assert topDocs.scoreDocs.length == 10;
service.shutdown();
}