Search in sources :

Example 1 with InternalLuceneService

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);
}
Also used : IndexRepository(org.apache.geode.cache.lucene.internal.repository.IndexRepository) IndexWriter(org.apache.lucene.index.IndexWriter) InternalLuceneIndex(org.apache.geode.cache.lucene.internal.InternalLuceneIndex) FileSystem(org.apache.geode.cache.lucene.internal.filesystem.FileSystem) GemFireCacheImpl(org.apache.geode.internal.cache.GemFireCacheImpl) Region(org.apache.geode.cache.Region) RegionFunctionContext(org.apache.geode.cache.execute.RegionFunctionContext) RepositoryManager(org.apache.geode.cache.lucene.internal.repository.RepositoryManager) InternalLuceneService(org.apache.geode.cache.lucene.internal.InternalLuceneService) ResultSender(org.apache.geode.cache.execute.ResultSender) Before(org.junit.Before)

Example 2 with InternalLuceneService

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);
    }
}
Also used : Set(java.util.Set) LuceneSearchResults(org.apache.geode.cache.lucene.internal.cli.LuceneSearchResults) GemFireCacheImpl(org.apache.geode.internal.cache.GemFireCacheImpl) Region(org.apache.geode.cache.Region) InternalLuceneService(org.apache.geode.cache.lucene.internal.InternalLuceneService) FunctionContext(org.apache.geode.cache.execute.FunctionContext) ResultSender(org.apache.geode.cache.execute.ResultSender) LuceneQueryInfo(org.apache.geode.cache.lucene.internal.cli.LuceneQueryInfo) Test(org.junit.Test) UnitTest(org.apache.geode.test.junit.categories.UnitTest)

Example 3 with InternalLuceneService

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;
}
Also used : LuceneQuery(org.apache.geode.cache.lucene.LuceneQuery) LuceneResultStructImpl(org.apache.geode.cache.lucene.internal.LuceneResultStructImpl) PageableLuceneQueryResults(org.apache.geode.cache.lucene.PageableLuceneQueryResults) LuceneIndex(org.apache.geode.cache.lucene.LuceneIndex) ArrayList(java.util.ArrayList) InternalLuceneService(org.apache.geode.cache.lucene.internal.InternalLuceneService) LuceneQueryFactory(org.apache.geode.cache.lucene.LuceneQueryFactory) LuceneResultStruct(org.apache.geode.cache.lucene.LuceneResultStruct)

Aggregations

InternalLuceneService (org.apache.geode.cache.lucene.internal.InternalLuceneService)3 Region (org.apache.geode.cache.Region)2 ResultSender (org.apache.geode.cache.execute.ResultSender)2 GemFireCacheImpl (org.apache.geode.internal.cache.GemFireCacheImpl)2 ArrayList (java.util.ArrayList)1 Set (java.util.Set)1 FunctionContext (org.apache.geode.cache.execute.FunctionContext)1 RegionFunctionContext (org.apache.geode.cache.execute.RegionFunctionContext)1 LuceneIndex (org.apache.geode.cache.lucene.LuceneIndex)1 LuceneQuery (org.apache.geode.cache.lucene.LuceneQuery)1 LuceneQueryFactory (org.apache.geode.cache.lucene.LuceneQueryFactory)1 LuceneResultStruct (org.apache.geode.cache.lucene.LuceneResultStruct)1 PageableLuceneQueryResults (org.apache.geode.cache.lucene.PageableLuceneQueryResults)1 InternalLuceneIndex (org.apache.geode.cache.lucene.internal.InternalLuceneIndex)1 LuceneResultStructImpl (org.apache.geode.cache.lucene.internal.LuceneResultStructImpl)1 LuceneQueryInfo (org.apache.geode.cache.lucene.internal.cli.LuceneQueryInfo)1 LuceneSearchResults (org.apache.geode.cache.lucene.internal.cli.LuceneSearchResults)1 FileSystem (org.apache.geode.cache.lucene.internal.filesystem.FileSystem)1 IndexRepository (org.apache.geode.cache.lucene.internal.repository.IndexRepository)1 RepositoryManager (org.apache.geode.cache.lucene.internal.repository.RepositoryManager)1