use of org.apache.geode.cache.lucene.internal.cli.LuceneIndexInfo in project geode by apache.
the class LuceneDescribeIndexFunction method execute.
public void execute(final FunctionContext context) {
LuceneIndexDetails result = null;
final Cache cache = getCache();
final String serverName = cache.getDistributedSystem().getDistributedMember().getName();
final LuceneIndexInfo indexInfo = (LuceneIndexInfo) context.getArguments();
LuceneServiceImpl service = (LuceneServiceImpl) LuceneServiceProvider.get(cache);
LuceneIndex index = service.getIndex(indexInfo.getIndexName(), indexInfo.getRegionPath());
LuceneIndexCreationProfile profile = service.getDefinedIndex(indexInfo.getIndexName(), indexInfo.getRegionPath());
if (index != null) {
result = new LuceneIndexDetails((LuceneIndexImpl) index, serverName);
} else if (profile != null) {
result = new LuceneIndexDetails(profile, serverName);
}
context.getResultSender().lastResult(result);
}
use of org.apache.geode.cache.lucene.internal.cli.LuceneIndexInfo in project geode by apache.
the class LuceneCreateIndexFunctionJUnitTest method testExecuteWithoutAnalyzer.
@Test
@SuppressWarnings("unchecked")
public void testExecuteWithoutAnalyzer() throws Throwable {
String[] fields = new String[] { "field1", "field2", "field3" };
LuceneIndexInfo indexInfo = new LuceneIndexInfo("index1", "/region1", fields, null);
when(context.getArguments()).thenReturn(indexInfo);
LuceneCreateIndexFunction function = new LuceneCreateIndexFunction();
function = spy(function);
doReturn(cache).when(function).getCache();
function.execute(context);
verify(factory).addField(eq("field1"));
verify(factory).addField(eq("field2"));
verify(factory).addField(eq("field3"));
verify(factory).create(eq("index1"), eq("/region1"));
ArgumentCaptor<Set> resultCaptor = ArgumentCaptor.forClass(Set.class);
verify(resultSender).lastResult(resultCaptor.capture());
CliFunctionResult result = (CliFunctionResult) resultCaptor.getValue();
assertEquals(expectedResult, result);
}
use of org.apache.geode.cache.lucene.internal.cli.LuceneIndexInfo in project geode by apache.
the class LuceneCreateIndexFunctionJUnitTest method testExecuteWithAnalyzer.
@Test
@SuppressWarnings("unchecked")
public void testExecuteWithAnalyzer() throws Throwable {
List<String> analyzerNames = new ArrayList<>();
analyzerNames.add(StandardAnalyzer.class.getCanonicalName());
analyzerNames.add(KeywordAnalyzer.class.getCanonicalName());
analyzerNames.add(StandardAnalyzer.class.getCanonicalName());
String[] analyzers = new String[3];
analyzerNames.toArray(analyzers);
LuceneIndexInfo indexInfo = new LuceneIndexInfo("index1", "/region1", new String[] { "field1", "field2", "field3" }, analyzers);
when(context.getArguments()).thenReturn(indexInfo);
LuceneCreateIndexFunction function = new LuceneCreateIndexFunction();
function = spy(function);
doReturn(cache).when(function).getCache();
function.execute(context);
ArgumentCaptor<Map> analyzersCaptor = ArgumentCaptor.forClass(Map.class);
verify(service).createIndexFactory();
verify(factory).addField(eq("field1"), isA(StandardAnalyzer.class));
verify(factory).addField(eq("field2"), isA(KeywordAnalyzer.class));
verify(factory).addField(eq("field3"), isA(StandardAnalyzer.class));
verify(factory).create(eq("index1"), eq("/region1"));
ArgumentCaptor<Set> resultCaptor = ArgumentCaptor.forClass(Set.class);
verify(resultSender).lastResult(resultCaptor.capture());
CliFunctionResult result = (CliFunctionResult) resultCaptor.getValue();
assertEquals(expectedResult, result);
}
use of org.apache.geode.cache.lucene.internal.cli.LuceneIndexInfo in project geode by apache.
the class LuceneDescribeIndexFunctionJUnitTest method getMockLuceneInfo.
private LuceneIndexInfo getMockLuceneInfo(final String index1) {
LuceneIndexInfo mockInfo = mock(LuceneIndexInfo.class);
doReturn(index1).when(mockInfo).getIndexName();
doReturn("/region").when(mockInfo).getRegionPath();
return mockInfo;
}
use of org.apache.geode.cache.lucene.internal.cli.LuceneIndexInfo 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