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);
});
}
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());
}
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;
}
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);
}
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());
}
Aggregations