use of org.apache.geode.cache.lucene.internal.InternalLuceneService in project geode by apache.
the class DumpDirectoryFilesJUnitTest method createMocks.
@Before
public void createMocks() throws BucketNotFoundException {
GemFireCacheImpl cache = Fakes.cache();
context = mock(RegionFunctionContext.class);
ResultSender sender = mock(ResultSender.class);
Region region = mock(Region.class);
InternalLuceneService service = mock(InternalLuceneService.class);
InternalLuceneIndex index = mock(InternalLuceneIndex.class);
RepositoryManager repoManager = mock(RepositoryManager.class);
IndexRepository repo = mock(IndexRepository.class);
IndexWriter writer = mock(IndexWriter.class);
RegionDirectory directory = mock(RegionDirectory.class);
fileSystem = mock(FileSystem.class);
Region bucket = mock(Region.class);
when(bucket.getFullPath()).thenReturn(bucketName);
when(context.getArguments()).thenReturn(new String[] { directoryName, indexName });
when(context.getResultSender()).thenReturn(sender);
when(context.getDataSet()).thenReturn(region);
when(region.getCache()).thenReturn(cache);
when(cache.getService(any())).thenReturn(service);
when(repoManager.getRepositories(eq(context))).thenReturn(Collections.singleton(repo));
when(index.getRepositoryManager()).thenReturn(repoManager);
when(index.getName()).thenReturn(indexName);
when(service.getIndex(eq(indexName), any())).thenReturn(index);
when(directory.getFileSystem()).thenReturn(fileSystem);
when(writer.getDirectory()).thenReturn(directory);
when(repo.getWriter()).thenReturn(writer);
when(repo.getRegion()).thenReturn(bucket);
}
use of org.apache.geode.cache.lucene.internal.InternalLuceneService in project geode by apache.
the class LuceneSearchIndexFunctionJUnitTest method testExecute.
@Test
@SuppressWarnings("unchecked")
public void testExecute() throws LuceneQueryException {
FunctionContext context = mock(FunctionContext.class);
ResultSender resultSender = mock(ResultSender.class);
GemFireCacheImpl cache = Fakes.cache();
LuceneQueryInfo queryInfo = createMockQueryInfo("index", "region", "field1:region1", "field1", 1);
InternalLuceneService service = getMockLuceneService("A", "Value", "1.2");
Region mockRegion = mock(Region.class);
LuceneSearchIndexFunction function = spy(LuceneSearchIndexFunction.class);
doReturn(queryInfo).when(context).getArguments();
doReturn(resultSender).when(context).getResultSender();
doReturn(cache).when(function).getCache();
when(cache.getService(eq(InternalLuceneService.class))).thenReturn(service);
when(cache.getRegion(queryInfo.getRegionPath())).thenReturn(mockRegion);
function.execute(context);
ArgumentCaptor<Set> resultCaptor = ArgumentCaptor.forClass(Set.class);
verify(resultSender).lastResult(resultCaptor.capture());
Set<LuceneSearchResults> result = resultCaptor.getValue();
assertEquals(1, result.size());
for (LuceneSearchResults searchResult : result) {
assertEquals("A", searchResult.getKey());
assertEquals("Value", searchResult.getValue());
assertEquals(1.2, searchResult.getScore(), .1);
}
}
use of org.apache.geode.cache.lucene.internal.InternalLuceneService in project geode by apache.
the class LuceneSearchIndexFunctionJUnitTest method getMockLuceneService.
private InternalLuceneService getMockLuceneService(String resultKey, String resultValue, String resultScore) throws LuceneQueryException {
InternalLuceneService service = mock(InternalLuceneService.class);
LuceneQueryFactory mockQueryFactory = spy(LuceneQueryFactory.class);
LuceneQuery mockQuery = mock(LuceneQuery.class);
PageableLuceneQueryResults pageableLuceneQueryResults = mock(PageableLuceneQueryResults.class);
LuceneResultStruct<String, String> resultStruct = new LuceneResultStructImpl(resultKey, resultValue, Float.valueOf(resultScore));
List<LuceneResultStruct<String, String>> queryResults = new ArrayList<>();
queryResults.add(resultStruct);
doReturn(mock(LuceneIndex.class)).when(service).getIndex(anyString(), anyString());
doReturn(mockQueryFactory).when(service).createLuceneQueryFactory();
doReturn(mockQueryFactory).when(mockQueryFactory).setLimit(anyInt());
doReturn(mockQuery).when(mockQueryFactory).create(any(), any(), any(), any());
when(mockQuery.findPages()).thenReturn(pageableLuceneQueryResults);
when(pageableLuceneQueryResults.hasNext()).thenReturn(true).thenReturn(false);
when(pageableLuceneQueryResults.next()).thenReturn(queryResults);
return service;
}
Aggregations