Search in sources :

Example 1 with StringQueryProvider

use of org.apache.geode.cache.lucene.internal.StringQueryProvider in project geode by apache.

the class LuceneQueryFunctionJUnitTest method createMocksAndCommonObjects.

@Before
public void createMocksAndCommonObjects() throws Exception {
    mockContext = mock(InternalRegionFunctionContext.class);
    mockResultSender = mock(ResultSender.class);
    mockRegion = mock(Region.class);
    mockRepoManager = mock(RepositoryManager.class);
    mockRepository1 = mock(IndexRepository.class, "repo1");
    mockRepository2 = mock(IndexRepository.class, "repo2");
    mockCollector = mock(IndexResultCollector.class);
    mockStats = mock(LuceneIndexStats.class);
    repos = new ArrayList<IndexRepository>();
    repos.add(mockRepository1);
    repos.add(mockRepository2);
    mockIndex = mock(LuceneIndexImpl.class);
    mockService = mock(InternalLuceneService.class);
    mockCache = mock(InternalCache.class);
    Analyzer analyzer = new StandardAnalyzer();
    Mockito.doReturn(analyzer).when(mockIndex).getAnalyzer();
    queryProvider = new StringQueryProvider("gemfire:lucene", DEFAULT_FIELD);
    searchArgs = new LuceneFunctionContext<IndexResultCollector>(queryProvider, "indexName");
    when(mockRegion.getCache()).thenReturn(mockCache);
    when(mockRegion.getFullPath()).thenReturn(regionPath);
    when(mockCache.getService(any())).thenReturn(mockService);
    when(mockService.getIndex(eq("indexName"), eq(regionPath))).thenReturn(mockIndex);
    when(mockIndex.getRepositoryManager()).thenReturn(mockRepoManager);
    when(mockIndex.getFieldNames()).thenReturn(new String[] { "gemfire" });
    when(mockIndex.getIndexStats()).thenReturn(mockStats);
    query = queryProvider.getQuery(mockIndex);
}
Also used : LuceneIndexStats(org.apache.geode.cache.lucene.internal.LuceneIndexStats) StringQueryProvider(org.apache.geode.cache.lucene.internal.StringQueryProvider) InternalCache(org.apache.geode.internal.cache.InternalCache) Analyzer(org.apache.lucene.analysis.Analyzer) StandardAnalyzer(org.apache.lucene.analysis.standard.StandardAnalyzer) ResultSender(org.apache.geode.cache.execute.ResultSender) IndexRepository(org.apache.geode.cache.lucene.internal.repository.IndexRepository) IndexResultCollector(org.apache.geode.cache.lucene.internal.repository.IndexResultCollector) StandardAnalyzer(org.apache.lucene.analysis.standard.StandardAnalyzer) InternalRegionFunctionContext(org.apache.geode.internal.cache.execute.InternalRegionFunctionContext) Region(org.apache.geode.cache.Region) RepositoryManager(org.apache.geode.cache.lucene.internal.repository.RepositoryManager) InternalLuceneService(org.apache.geode.cache.lucene.internal.InternalLuceneService) LuceneIndexImpl(org.apache.geode.cache.lucene.internal.LuceneIndexImpl) Before(org.junit.Before)

Example 2 with StringQueryProvider

use of org.apache.geode.cache.lucene.internal.StringQueryProvider in project geode by apache.

the class LuceneQueryFunctionContextJUnitTest method testSerialization.

@Test
public void testSerialization() {
    LuceneServiceImpl.registerDataSerializables();
    LuceneQueryProvider provider = new StringQueryProvider("text", DEFAULT_FIELD);
    CollectorManager<TopEntriesCollector> manager = new TopEntriesCollectorManager("test");
    LuceneFunctionContext<TopEntriesCollector> context = new LuceneFunctionContext<>(provider, "testIndex", manager, 123);
    LuceneFunctionContext<TopEntriesCollector> copy = CopyHelper.deepCopy(context);
    assertEquals(123, copy.getLimit());
    assertNotNull(copy.getQueryProvider());
    assertEquals("text", ((StringQueryProvider) copy.getQueryProvider()).getQueryString());
    assertEquals(TopEntriesCollectorManager.class, copy.getCollectorManager().getClass());
    assertEquals("test", ((TopEntriesCollectorManager) copy.getCollectorManager()).getId());
    assertEquals("testIndex", copy.getIndexName());
}
Also used : LuceneQueryProvider(org.apache.geode.cache.lucene.LuceneQueryProvider) StringQueryProvider(org.apache.geode.cache.lucene.internal.StringQueryProvider) UnitTest(org.apache.geode.test.junit.categories.UnitTest) Test(org.junit.Test)

Aggregations

StringQueryProvider (org.apache.geode.cache.lucene.internal.StringQueryProvider)2 Region (org.apache.geode.cache.Region)1 ResultSender (org.apache.geode.cache.execute.ResultSender)1 LuceneQueryProvider (org.apache.geode.cache.lucene.LuceneQueryProvider)1 InternalLuceneService (org.apache.geode.cache.lucene.internal.InternalLuceneService)1 LuceneIndexImpl (org.apache.geode.cache.lucene.internal.LuceneIndexImpl)1 LuceneIndexStats (org.apache.geode.cache.lucene.internal.LuceneIndexStats)1 IndexRepository (org.apache.geode.cache.lucene.internal.repository.IndexRepository)1 IndexResultCollector (org.apache.geode.cache.lucene.internal.repository.IndexResultCollector)1 RepositoryManager (org.apache.geode.cache.lucene.internal.repository.RepositoryManager)1 InternalCache (org.apache.geode.internal.cache.InternalCache)1 InternalRegionFunctionContext (org.apache.geode.internal.cache.execute.InternalRegionFunctionContext)1 UnitTest (org.apache.geode.test.junit.categories.UnitTest)1 Analyzer (org.apache.lucene.analysis.Analyzer)1 StandardAnalyzer (org.apache.lucene.analysis.standard.StandardAnalyzer)1 Before (org.junit.Before)1 Test (org.junit.Test)1