use of org.apache.geode.cache.lucene.internal.repository.IndexResultCollector in project geode by apache.
the class LuceneQueryFunctionJUnitTest method testResultLimitClause.
@Test
public void testResultLimitClause() throws Exception {
searchArgs = new LuceneFunctionContext<IndexResultCollector>(queryProvider, "indexName", null, 3);
when(mockContext.getDataSet()).thenReturn(mockRegion);
when(mockContext.getArguments()).thenReturn(searchArgs);
when(mockContext.<TopEntriesCollector>getResultSender()).thenReturn(mockResultSender);
when(mockRepoManager.getRepositories(eq(mockContext))).thenReturn(repos);
doAnswer(invocation -> {
IndexResultCollector collector = invocation.getArgumentAt(2, IndexResultCollector.class);
collector.collect(r1_1.getKey(), r1_1.getScore());
collector.collect(r1_2.getKey(), r1_2.getScore());
collector.collect(r1_3.getKey(), r1_3.getScore());
return null;
}).when(mockRepository1).query(eq(query), eq(3), any(IndexResultCollector.class));
doAnswer(invocation -> {
IndexResultCollector collector = invocation.getArgumentAt(2, IndexResultCollector.class);
collector.collect(r2_1.getKey(), r2_1.getScore());
collector.collect(r2_2.getKey(), r2_2.getScore());
return null;
}).when(mockRepository2).query(eq(query), eq(3), any(IndexResultCollector.class));
LuceneQueryFunction function = new LuceneQueryFunction();
function.execute(mockContext);
ArgumentCaptor<TopEntriesCollector> resultCaptor = ArgumentCaptor.forClass(TopEntriesCollector.class);
verify(mockResultSender).lastResult(resultCaptor.capture());
TopEntriesCollector result = resultCaptor.getValue();
List<EntryScore> hits = result.getEntries().getHits();
assertEquals(3, hits.size());
LuceneTestUtilities.verifyResultOrder(result.getEntries().getHits(), r1_1, r2_1, r1_2);
}
Aggregations