Search in sources :

Example 1 with LuceneIndexInfo

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);
}
Also used : LuceneIndexInfo(org.apache.geode.cache.lucene.internal.cli.LuceneIndexInfo) LuceneIndex(org.apache.geode.cache.lucene.LuceneIndex) LuceneIndexDetails(org.apache.geode.cache.lucene.internal.cli.LuceneIndexDetails) LuceneServiceImpl(org.apache.geode.cache.lucene.internal.LuceneServiceImpl) LuceneIndexCreationProfile(org.apache.geode.cache.lucene.internal.LuceneIndexCreationProfile) LuceneIndexImpl(org.apache.geode.cache.lucene.internal.LuceneIndexImpl) Cache(org.apache.geode.cache.Cache)

Example 2 with LuceneIndexInfo

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);
}
Also used : CliFunctionResult(org.apache.geode.management.internal.cli.functions.CliFunctionResult) LuceneIndexInfo(org.apache.geode.cache.lucene.internal.cli.LuceneIndexInfo) Set(java.util.Set) Test(org.junit.Test) UnitTest(org.apache.geode.test.junit.categories.UnitTest)

Example 3 with LuceneIndexInfo

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);
}
Also used : KeywordAnalyzer(org.apache.lucene.analysis.core.KeywordAnalyzer) Set(java.util.Set) ArrayList(java.util.ArrayList) CliFunctionResult(org.apache.geode.management.internal.cli.functions.CliFunctionResult) LuceneIndexInfo(org.apache.geode.cache.lucene.internal.cli.LuceneIndexInfo) StandardAnalyzer(org.apache.lucene.analysis.standard.StandardAnalyzer) Map(java.util.Map) Test(org.junit.Test) UnitTest(org.apache.geode.test.junit.categories.UnitTest)

Example 4 with LuceneIndexInfo

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;
}
Also used : LuceneIndexInfo(org.apache.geode.cache.lucene.internal.cli.LuceneIndexInfo)

Example 5 with LuceneIndexInfo

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

LuceneIndexInfo (org.apache.geode.cache.lucene.internal.cli.LuceneIndexInfo)6 CliFunctionResult (org.apache.geode.management.internal.cli.functions.CliFunctionResult)3 UnitTest (org.apache.geode.test.junit.categories.UnitTest)3 Test (org.junit.Test)3 Set (java.util.Set)2 Cache (org.apache.geode.cache.Cache)2 LuceneIndexImpl (org.apache.geode.cache.lucene.internal.LuceneIndexImpl)2 LuceneServiceImpl (org.apache.geode.cache.lucene.internal.LuceneServiceImpl)2 LuceneIndexDetails (org.apache.geode.cache.lucene.internal.cli.LuceneIndexDetails)2 StandardAnalyzer (org.apache.lucene.analysis.standard.StandardAnalyzer)2 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1 FunctionContext (org.apache.geode.cache.execute.FunctionContext)1 ResultSender (org.apache.geode.cache.execute.ResultSender)1 LuceneIndex (org.apache.geode.cache.lucene.LuceneIndex)1 LuceneIndexFactory (org.apache.geode.cache.lucene.LuceneIndexFactory)1 LuceneService (org.apache.geode.cache.lucene.LuceneService)1 LuceneIndexCreationProfile (org.apache.geode.cache.lucene.internal.LuceneIndexCreationProfile)1 GemFireCacheImpl (org.apache.geode.internal.cache.GemFireCacheImpl)1 XmlEntity (org.apache.geode.management.internal.configuration.domain.XmlEntity)1