Do not wait on task's future if it was rejected
This commit is contained in:
Родитель
15db6bfa88
Коммит
a9cf5f6abe
|
@ -668,14 +668,20 @@ public class IndexSearcher {
|
||||||
search(Arrays.asList(leaves), weight, collector);
|
search(Arrays.asList(leaves), weight, collector);
|
||||||
return collector;
|
return collector;
|
||||||
});
|
});
|
||||||
|
boolean executedOnCallerThread = false;
|
||||||
try {
|
try {
|
||||||
executor.execute(task);
|
executor.execute(task);
|
||||||
} catch (RejectedExecutionException e) {
|
} catch (RejectedExecutionException e) {
|
||||||
// Execute on caller thread
|
// Execute on caller thread
|
||||||
search(Arrays.asList(leaves), weight, collector);
|
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 LeafReaderContext[] leaves = leafSlices[leafSlices.length - 1].leaves;
|
||||||
final C collector = collectors.get(leafSlices.length - 1);
|
final C collector = collectors.get(leafSlices.length - 1);
|
||||||
|
|
|
@ -273,8 +273,6 @@ public class TestIndexSearcher extends LuceneTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testRejectedExecution() throws IOException {
|
public void testRejectedExecution() throws IOException {
|
||||||
List<LeafReaderContext> leaves = reader.leaves();
|
|
||||||
AtomicInteger numExecutions = new AtomicInteger(0);
|
|
||||||
ExecutorService service = new RejectingMockExecutor();
|
ExecutorService service = new RejectingMockExecutor();
|
||||||
|
|
||||||
IndexSearcher searcher = new IndexSearcher(reader, service) {
|
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
|
// To ensure that failing ExecutorService still allows query to run
|
||||||
// successfully
|
// successfully
|
||||||
searcher.search(new MatchAllDocsQuery(), 10);
|
TopDocs topDocs = searcher.search(new MatchAllDocsQuery(), 10);
|
||||||
if (leaves.size() <= 1) {
|
assert topDocs.scoreDocs.length == 10;
|
||||||
assertEquals(0, numExecutions.get());
|
|
||||||
} else {
|
|
||||||
assertEquals(leaves.size() - 1, numExecutions.get());
|
|
||||||
}
|
|
||||||
|
|
||||||
service.shutdown();
|
service.shutdown();
|
||||||
}
|
}
|
||||||
|
|
Загрузка…
Ссылка в новой задаче