Search in sources :

Example 6 with LuceneDestroyIndexInfo

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

the class LuceneDestroyIndexFunctionJUnitTest method testDestroyDefinedIndex.

@Test
public void testDestroyDefinedIndex() throws Throwable {
    String indexName = "index1";
    String regionPath = "/region1";
    LuceneDestroyIndexInfo indexInfo = new LuceneDestroyIndexInfo(indexName, regionPath, true);
    when(this.context.getArguments()).thenReturn(indexInfo);
    LuceneDestroyIndexFunction function = new LuceneDestroyIndexFunction();
    function = spy(function);
    doReturn(this.cache).when(function).getCache();
    function.execute(this.context);
    verify(this.service).destroyDefinedIndex(eq(indexName), eq(regionPath));
    verify(this.service, never()).destroyIndex(eq(indexName), eq(regionPath));
    verify(this.service, never()).destroyIndexes(eq(regionPath));
    verify(function, never()).getXmlEntity(eq(indexName), eq(regionPath));
    verifyFunctionResult(true);
}
Also used : LuceneDestroyIndexInfo(org.apache.geode.cache.lucene.internal.cli.LuceneDestroyIndexInfo) Test(org.junit.Test) UnitTest(org.apache.geode.test.junit.categories.UnitTest)

Example 7 with LuceneDestroyIndexInfo

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

the class LuceneDestroyIndexFunctionJUnitTest method testDestroyIndexesFailure.

@Test
@SuppressWarnings("unchecked")
public void testDestroyIndexesFailure() throws Throwable {
    String regionPath = "/region1";
    LuceneDestroyIndexInfo indexInfo = new LuceneDestroyIndexInfo(null, regionPath, false);
    when(this.context.getArguments()).thenReturn(indexInfo);
    LuceneDestroyIndexFunction function = new LuceneDestroyIndexFunction();
    function = spy(function);
    doReturn(this.cache).when(function).getCache();
    doThrow(new IllegalStateException()).when(this.service).destroyIndexes(eq(regionPath));
    function.execute(this.context);
    verifyFunctionResult(false);
}
Also used : LuceneDestroyIndexInfo(org.apache.geode.cache.lucene.internal.cli.LuceneDestroyIndexInfo) Test(org.junit.Test) UnitTest(org.apache.geode.test.junit.categories.UnitTest)

Example 8 with LuceneDestroyIndexInfo

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

the class LuceneDestroyIndexFunctionJUnitTest method testDestroyIndex.

@Test
@SuppressWarnings("unchecked")
public void testDestroyIndex() throws Throwable {
    String indexName = "index1";
    String regionPath = "/region1";
    LuceneDestroyIndexInfo indexInfo = new LuceneDestroyIndexInfo(indexName, regionPath, false);
    when(this.context.getArguments()).thenReturn(indexInfo);
    LuceneDestroyIndexFunction function = new LuceneDestroyIndexFunction();
    function = spy(function);
    doReturn(this.cache).when(function).getCache();
    function.execute(this.context);
    verify(this.service).destroyIndex(eq(indexName), eq(regionPath));
    verify(function).getXmlEntity(eq(indexName), eq(regionPath));
    verify(this.service, never()).destroyDefinedIndex(eq(indexName), eq(regionPath));
    verify(this.service, never()).destroyIndexes(eq(regionPath));
    verifyFunctionResult(true);
}
Also used : LuceneDestroyIndexInfo(org.apache.geode.cache.lucene.internal.cli.LuceneDestroyIndexInfo) Test(org.junit.Test) UnitTest(org.apache.geode.test.junit.categories.UnitTest)

Example 9 with LuceneDestroyIndexInfo

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

the class LuceneDestroyIndexFunction method execute.

public void execute(final FunctionContext context) {
    CliFunctionResult result = null;
    String memberId = getCache().getDistributedSystem().getDistributedMember().getId();
    try {
        LuceneDestroyIndexInfo indexInfo = (LuceneDestroyIndexInfo) context.getArguments();
        String indexName = indexInfo.getIndexName();
        String regionPath = indexInfo.getRegionPath();
        LuceneService service = LuceneServiceProvider.get(getCache());
        if (indexName == null) {
            if (indexInfo.isDefinedDestroyOnly()) {
                ((LuceneServiceImpl) service).destroyDefinedIndexes(regionPath);
                result = new CliFunctionResult(memberId);
            } else {
                service.destroyIndexes(regionPath);
                result = new CliFunctionResult(memberId, getXmlEntity(indexName, regionPath));
            }
        } else {
            if (indexInfo.isDefinedDestroyOnly()) {
                ((LuceneServiceImpl) service).destroyDefinedIndex(indexName, regionPath);
                result = new CliFunctionResult(memberId);
            } else {
                service.destroyIndex(indexName, regionPath);
                result = new CliFunctionResult(memberId, getXmlEntity(indexName, regionPath));
            }
        }
    } catch (Exception e) {
        result = new CliFunctionResult(memberId, e, e.getMessage());
    }
    context.getResultSender().lastResult(result);
}
Also used : CliFunctionResult(org.apache.geode.management.internal.cli.functions.CliFunctionResult) LuceneServiceImpl(org.apache.geode.cache.lucene.internal.LuceneServiceImpl) LuceneDestroyIndexInfo(org.apache.geode.cache.lucene.internal.cli.LuceneDestroyIndexInfo) LuceneService(org.apache.geode.cache.lucene.LuceneService)

Aggregations

LuceneDestroyIndexInfo (org.apache.geode.cache.lucene.internal.cli.LuceneDestroyIndexInfo)9 UnitTest (org.apache.geode.test.junit.categories.UnitTest)8 Test (org.junit.Test)8 LuceneService (org.apache.geode.cache.lucene.LuceneService)1 LuceneServiceImpl (org.apache.geode.cache.lucene.internal.LuceneServiceImpl)1 CliFunctionResult (org.apache.geode.management.internal.cli.functions.CliFunctionResult)1