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