Search in sources :

Example 1 with LuceneIndexDetails

use of org.apache.geode.cache.lucene.internal.cli.LuceneIndexDetails 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 LuceneIndexDetails

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

the class LuceneListIndexFunction method execute.

public void execute(final FunctionContext context) {
    final Set<LuceneIndexDetails> indexDetailsSet = new HashSet<>();
    final Cache cache = getCache();
    final String serverName = cache.getDistributedSystem().getDistributedMember().getName();
    LuceneServiceImpl service = (LuceneServiceImpl) LuceneServiceProvider.get(cache);
    for (LuceneIndex index : service.getAllIndexes()) {
        indexDetailsSet.add(new LuceneIndexDetails((LuceneIndexImpl) index, serverName));
    }
    for (LuceneIndexCreationProfile profile : service.getAllDefinedIndexes()) {
        indexDetailsSet.add(new LuceneIndexDetails(profile, serverName));
    }
    context.getResultSender().lastResult(indexDetailsSet);
}
Also used : LuceneIndex(org.apache.geode.cache.lucene.LuceneIndex) LuceneIndexDetails(org.apache.geode.cache.lucene.internal.cli.LuceneIndexDetails) LuceneServiceImpl(org.apache.geode.cache.lucene.internal.LuceneServiceImpl) LuceneIndexImpl(org.apache.geode.cache.lucene.internal.LuceneIndexImpl) LuceneIndexCreationProfile(org.apache.geode.cache.lucene.internal.LuceneIndexCreationProfile) HashSet(java.util.HashSet) Cache(org.apache.geode.cache.Cache)

Example 3 with LuceneIndexDetails

use of org.apache.geode.cache.lucene.internal.cli.LuceneIndexDetails 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 4 with LuceneIndexDetails

use of org.apache.geode.cache.lucene.internal.cli.LuceneIndexDetails 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)4 LuceneServiceImpl (org.apache.geode.cache.lucene.internal.LuceneServiceImpl)4 LuceneIndexDetails (org.apache.geode.cache.lucene.internal.cli.LuceneIndexDetails)4 LuceneIndex (org.apache.geode.cache.lucene.LuceneIndex)3 Cache (org.apache.geode.cache.Cache)2 FunctionContext (org.apache.geode.cache.execute.FunctionContext)2 ResultSender (org.apache.geode.cache.execute.ResultSender)2 LuceneIndexCreationProfile (org.apache.geode.cache.lucene.internal.LuceneIndexCreationProfile)2 LuceneIndexInfo (org.apache.geode.cache.lucene.internal.cli.LuceneIndexInfo)2 GemFireCacheImpl (org.apache.geode.internal.cache.GemFireCacheImpl)2 UnitTest (org.apache.geode.test.junit.categories.UnitTest)2 Test (org.junit.Test)2 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 Set (java.util.Set)1 TreeSet (java.util.TreeSet)1