jpountz commented on a change in pull request #1294: LUCENE-9074: Slice Allocation Control Plane For Concurrent Searches URL: https://github.com/apache/lucene-solr/pull/1294#discussion_r401584443
########## File path: lucene/core/src/test/org/apache/lucene/search/TestIndexSearcher.java ########## @@ -347,4 +354,89 @@ public void execute(final Runnable runnable) { throw new RejectedExecutionException(); } } + + public void testQueueSizeBasedSliceExecutor() throws Exception { + ThreadPoolExecutor service = new ThreadPoolExecutor(4, 4, 0L, TimeUnit.MILLISECONDS, + new LinkedBlockingQueue<Runnable>(), + new NamedThreadFactory("TestIndexSearcher")); + + runSliceExecutorTest(service, false); + + TestUtil.shutdownExecutorService(service); + } + + public void testRandomBlockingSliceExecutor() throws Exception { + ThreadPoolExecutor service = new ThreadPoolExecutor(4, 4, 0L, TimeUnit.MILLISECONDS, + new LinkedBlockingQueue<Runnable>(), + new NamedThreadFactory("TestIndexSearcher")); + + runSliceExecutorTest(service, true); + + TestUtil.shutdownExecutorService(service); + } + + private void runSliceExecutorTest(ThreadPoolExecutor service, boolean useRandomSliceExecutor) throws Exception { + SliceExecutor sliceExecutor = useRandomSliceExecutor == true ? new RandomBlockingSliceExecutor(service) : + new QueueSizeBasedExecutor(service); + + IndexSearcher searcher = new IndexSearcher(reader.getContext(), service, sliceExecutor); + + Query queries[] = new Query[] { + new MatchAllDocsQuery(), + new TermQuery(new Term("field", "1")) + }; + Sort sorts[] = new Sort[] { + null, + new Sort(new SortField("field2", SortField.Type.STRING)) + }; + ScoreDoc afters[] = new ScoreDoc[] { + null, + new FieldDoc(0, 0f, new Object[] { new BytesRef("boo!") }) + }; + + for (ScoreDoc after : afters) { + for (Query query : queries) { + for (Sort sort : sorts) { + searcher.search(query, Integer.MAX_VALUE); + searcher.searchAfter(after, query, Integer.MAX_VALUE); + if (sort != null) { + TopDocs topDocs = searcher.search(query, Integer.MAX_VALUE, sort); + assert topDocs.totalHits.value > 0; + + topDocs = searcher.search(query, Integer.MAX_VALUE, sort, true); + assert topDocs.totalHits.value > 0; + + topDocs = searcher.search(query, Integer.MAX_VALUE, sort, false); + assert topDocs.totalHits.value > 0; + + topDocs = searcher.searchAfter(after, query, Integer.MAX_VALUE, sort); + assert topDocs.totalHits.value > 0; + + topDocs = searcher.searchAfter(after, query, Integer.MAX_VALUE, sort, true); + assert topDocs.totalHits.value > 0; + + topDocs = searcher.searchAfter(after, query, Integer.MAX_VALUE, sort, false); + assert topDocs.totalHits.value > 0; Review comment: we should use assertTrue rather than assert in tests, since the latter only runs when assertions are enabled, and it can be useful to run tests with assertions disabled to make sure that the logic remains correct when assertions are off ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org With regards, Apache Git Services --------------------------------------------------------------------- To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org For additional commands, e-mail: issues-h...@lucene.apache.org