Search in sources :

Example 6 with LuceneIndexImpl

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

the class LuceneQueriesAccessorBase method waitForFlushBeforeExecuteTextSearch.

protected boolean waitForFlushBeforeExecuteTextSearch(VM vm, int ms) {
    return vm.invoke(() -> {
        Cache cache = getCache();
        LuceneService service = LuceneServiceProvider.get(cache);
        LuceneIndexImpl index = (LuceneIndexImpl) service.getIndex(INDEX_NAME, REGION_NAME);
        return service.waitUntilFlushed(INDEX_NAME, REGION_NAME, ms, TimeUnit.MILLISECONDS);
    });
}
Also used : LuceneIndexImpl(org.apache.geode.cache.lucene.internal.LuceneIndexImpl) Cache(org.apache.geode.cache.Cache)

Example 7 with LuceneIndexImpl

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

the class LuceneIndexMaintenanceIntegrationTest method entriesFlushedToIndexAfterWaitForFlushCalled.

@Test
public void entriesFlushedToIndexAfterWaitForFlushCalled() throws InterruptedException {
    luceneService.createIndexFactory().setFields("title", "description").create(INDEX_NAME, REGION_NAME);
    Region region = createRegion(REGION_NAME, RegionShortcut.PARTITION);
    LuceneTestUtilities.pauseSender(cache);
    region.put("object-1", new TestObject("title 1", "hello world"));
    region.put("object-2", new TestObject("title 2", "this will not match"));
    region.put("object-3", new TestObject("title 3", "hello world"));
    region.put("object-4", new TestObject("hello world", "hello world"));
    LuceneIndexImpl index = (LuceneIndexImpl) luceneService.getIndex(INDEX_NAME, REGION_NAME);
    assertFalse(luceneService.waitUntilFlushed(INDEX_NAME, REGION_NAME, 500, TimeUnit.MILLISECONDS));
    LuceneTestUtilities.resumeSender(cache);
    assertTrue(luceneService.waitUntilFlushed(INDEX_NAME, REGION_NAME, WAIT_FOR_FLUSH_TIME, TimeUnit.MILLISECONDS));
    assertEquals(4, index.getIndexStats().getCommits());
}
Also used : LuceneIndexForPartitionedRegion(org.apache.geode.cache.lucene.internal.LuceneIndexForPartitionedRegion) Region(org.apache.geode.cache.Region) LuceneIndexImpl(org.apache.geode.cache.lucene.internal.LuceneIndexImpl) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 8 with LuceneIndexImpl

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

the class LuceneListIndexFunctionJUnitTest method getMockLuceneIndex.

private LuceneIndexImpl getMockLuceneIndex(final String indexName) {
    String[] searchableFields = { "field1", "field2" };
    Map<String, Analyzer> fieldAnalyzers = new HashMap<>();
    fieldAnalyzers.put("field1", new StandardAnalyzer());
    fieldAnalyzers.put("field2", new KeywordAnalyzer());
    LuceneIndexImpl index = mock(LuceneIndexImpl.class);
    when(index.getName()).thenReturn(indexName);
    when(index.getRegionPath()).thenReturn("/region");
    when(index.getFieldNames()).thenReturn(searchableFields);
    when(index.getFieldAnalyzers()).thenReturn(fieldAnalyzers);
    return index;
}
Also used : KeywordAnalyzer(org.apache.lucene.analysis.core.KeywordAnalyzer) HashMap(java.util.HashMap) StandardAnalyzer(org.apache.lucene.analysis.standard.StandardAnalyzer) Analyzer(org.apache.lucene.analysis.Analyzer) KeywordAnalyzer(org.apache.lucene.analysis.core.KeywordAnalyzer) StandardAnalyzer(org.apache.lucene.analysis.standard.StandardAnalyzer) LuceneIndexImpl(org.apache.geode.cache.lucene.internal.LuceneIndexImpl)

Example 9 with LuceneIndexImpl

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

the class LuceneListIndexFunctionJUnitTest method testExecute.

@Test
@SuppressWarnings("unchecked")
public void testExecute() throws Throwable {
    GemFireCacheImpl cache = Fakes.cache();
    final String serverName = "mockServer";
    LuceneServiceImpl service = mock(LuceneServiceImpl.class);
    when(cache.getService(InternalLuceneService.class)).thenReturn(service);
    FunctionContext context = mock(FunctionContext.class);
    ResultSender resultSender = mock(ResultSender.class);
    when(context.getResultSender()).thenReturn(resultSender);
    LuceneIndexImpl index1 = getMockLuceneIndex("index1");
    LuceneIndexImpl index2 = getMockLuceneIndex("index2");
    TreeSet expectedResult = new TreeSet();
    expectedResult.add(new LuceneIndexDetails(index1, serverName));
    expectedResult.add(new LuceneIndexDetails(index2, serverName));
    ArrayList<LuceneIndex> allIndexes = new ArrayList();
    allIndexes.add(index1);
    allIndexes.add(index2);
    when(service.getAllIndexes()).thenReturn(allIndexes);
    LuceneListIndexFunction function = new LuceneListIndexFunction();
    function = spy(function);
    Mockito.doReturn(cache).when(function).getCache();
    function.execute(context);
    ArgumentCaptor<Set> resultCaptor = ArgumentCaptor.forClass(Set.class);
    verify(resultSender).lastResult(resultCaptor.capture());
    Set<String> result = resultCaptor.getValue();
    assertEquals(2, result.size());
    assertEquals(expectedResult, result);
}
Also used : Set(java.util.Set) TreeSet(java.util.TreeSet) ArrayList(java.util.ArrayList) FunctionContext(org.apache.geode.cache.execute.FunctionContext) ResultSender(org.apache.geode.cache.execute.ResultSender) LuceneIndex(org.apache.geode.cache.lucene.LuceneIndex) TreeSet(java.util.TreeSet) LuceneIndexDetails(org.apache.geode.cache.lucene.internal.cli.LuceneIndexDetails) GemFireCacheImpl(org.apache.geode.internal.cache.GemFireCacheImpl) LuceneServiceImpl(org.apache.geode.cache.lucene.internal.LuceneServiceImpl) LuceneIndexImpl(org.apache.geode.cache.lucene.internal.LuceneIndexImpl) Test(org.junit.Test) UnitTest(org.apache.geode.test.junit.categories.UnitTest)

Example 10 with LuceneIndexImpl

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

the class LuceneDescribeIndexFunctionJUnitTest method testExecute.

@Test
@SuppressWarnings("unchecked")
public void testExecute() throws Throwable {
    GemFireCacheImpl cache = Fakes.cache();
    final String serverName = "mockServer";
    LuceneServiceImpl service = mock(LuceneServiceImpl.class);
    when(cache.getService(InternalLuceneService.class)).thenReturn(service);
    FunctionContext context = mock(FunctionContext.class);
    ResultSender resultSender = mock(ResultSender.class);
    LuceneIndexInfo indexInfo = getMockLuceneInfo("index1");
    LuceneIndexImpl index1 = getMockLuceneIndex("index1");
    LuceneDescribeIndexFunction function = spy(LuceneDescribeIndexFunction.class);
    doReturn(indexInfo).when(context).getArguments();
    doReturn(resultSender).when(context).getResultSender();
    doReturn(cache).when(function).getCache();
    when(service.getIndex(indexInfo.getIndexName(), indexInfo.getRegionPath())).thenReturn(index1);
    function.execute(context);
    ArgumentCaptor<LuceneIndexDetails> resultCaptor = ArgumentCaptor.forClass(LuceneIndexDetails.class);
    verify(resultSender).lastResult(resultCaptor.capture());
    LuceneIndexDetails result = resultCaptor.getValue();
    LuceneIndexDetails expected = new LuceneIndexDetails(index1, "mockServer");
    assertEquals(expected.getIndexName(), result.getIndexName());
    assertEquals(expected.getRegionPath(), result.getRegionPath());
    assertEquals(expected.getIndexStats(), result.getIndexStats());
    assertEquals(expected.getFieldAnalyzersString(), result.getFieldAnalyzersString());
    assertEquals(expected.getSearchableFieldNamesString(), result.getSearchableFieldNamesString());
}
Also used : LuceneIndexInfo(org.apache.geode.cache.lucene.internal.cli.LuceneIndexInfo) LuceneIndexDetails(org.apache.geode.cache.lucene.internal.cli.LuceneIndexDetails) GemFireCacheImpl(org.apache.geode.internal.cache.GemFireCacheImpl) LuceneServiceImpl(org.apache.geode.cache.lucene.internal.LuceneServiceImpl) LuceneIndexImpl(org.apache.geode.cache.lucene.internal.LuceneIndexImpl) FunctionContext(org.apache.geode.cache.execute.FunctionContext) ResultSender(org.apache.geode.cache.execute.ResultSender) Test(org.junit.Test) UnitTest(org.apache.geode.test.junit.categories.UnitTest)

Aggregations

LuceneIndexImpl (org.apache.geode.cache.lucene.internal.LuceneIndexImpl)14 Cache (org.apache.geode.cache.Cache)5 LuceneServiceImpl (org.apache.geode.cache.lucene.internal.LuceneServiceImpl)5 Region (org.apache.geode.cache.Region)4 LuceneIndex (org.apache.geode.cache.lucene.LuceneIndex)4 LuceneIndexDetails (org.apache.geode.cache.lucene.internal.cli.LuceneIndexDetails)4 LuceneService (org.apache.geode.cache.lucene.LuceneService)3 Test (org.junit.Test)3 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 CacheClosedException (org.apache.geode.cache.CacheClosedException)2 FunctionContext (org.apache.geode.cache.execute.FunctionContext)2 RegionFunctionContext (org.apache.geode.cache.execute.RegionFunctionContext)2 ResultSender (org.apache.geode.cache.execute.ResultSender)2 LuceneIndexCreationProfile (org.apache.geode.cache.lucene.internal.LuceneIndexCreationProfile)2 LuceneIndexForPartitionedRegion (org.apache.geode.cache.lucene.internal.LuceneIndexForPartitionedRegion)2 LuceneIndexInfo (org.apache.geode.cache.lucene.internal.cli.LuceneIndexInfo)2 IndexRepository (org.apache.geode.cache.lucene.internal.repository.IndexRepository)2 GemFireCacheImpl (org.apache.geode.internal.cache.GemFireCacheImpl)2