use of org.apache.geode.cache.execute.FunctionInvocationTargetException in project geode by apache.
the class OnGroupsFunctionExecutionDUnitTest method testP2PIgnoreMemberFailure.
@Test
public void testP2PIgnoreMemberFailure() {
Host host = Host.getHost(0);
VM vm0 = host.getVM(0);
VM vm1 = host.getVM(1);
VM vm2 = host.getVM(2);
final String regionName = getName();
initVM(vm0, "g0,mg", regionName, false);
initVM(vm1, "g1", regionName, false);
initVM(vm2, "g0,g1,g2", regionName, false);
vm0.invoke(new SerializableCallable() {
@Override
public Object call() throws Exception {
DistributedSystem ds = getSystem();
Execution e1 = FunctionService.onMembers("g1");
ArrayList<String> args = new ArrayList<String>();
args.add("shutdown");
args.add("g2");
e1 = e1.setArguments(args);
((AbstractExecution) e1).setIgnoreDepartedMembers(true);
ArrayList l = (ArrayList) e1.execute(new OnGroupsExceptionFunction()).getResult();
assertEquals(2, l.size());
if (l.get(0) instanceof FunctionInvocationTargetException) {
assertTrue((Boolean) l.get(1));
} else if (l.get(0) instanceof Boolean) {
assertTrue(l.get(1) instanceof FunctionInvocationTargetException);
} else {
fail("expected to find a Boolean or throwable at index 0");
}
return null;
}
});
}
use of org.apache.geode.cache.execute.FunctionInvocationTargetException in project geode by apache.
the class PRClientServerRegionFunctionExecutionNoSingleHopDUnitTest method serverMultiKeyExecution_FunctionInvocationTargetException.
public static void serverMultiKeyExecution_FunctionInvocationTargetException() {
Region region = cache.getRegion(PartitionedRegionName);
assertNotNull(region);
final HashSet testKeysSet = new HashSet();
for (int i = (totalNumBuckets.intValue() * 2); i > 0; i--) {
testKeysSet.add("execKey-" + i);
}
DistributedSystem.setThreadsSocketPolicy(false);
Execution dataSet = FunctionService.onRegion(region);
int j = 0;
HashSet origVals = new HashSet();
for (Iterator i = testKeysSet.iterator(); i.hasNext(); ) {
Integer val = new Integer(j++);
origVals.add(val);
region.put(i.next(), val);
}
ResultCollector rc1 = null;
try {
rc1 = dataSet.withFilter(testKeysSet).setArguments(Boolean.TRUE).execute(new FunctionAdapter() {
public void execute(FunctionContext context) {
if (((RegionFunctionContext) context).isPossibleDuplicate()) {
context.getResultSender().lastResult(new Integer(retryCount));
return;
}
if (context.getArguments() instanceof Boolean) {
throw new FunctionInvocationTargetException("I have been thrown from TestFunction");
}
}
public String getId() {
return getClass().getName();
}
public boolean hasResult() {
return true;
}
});
List list = (ArrayList) rc1.getResult();
assertEquals(list.get(0), 0);
} catch (Throwable e) {
e.printStackTrace();
Assert.fail("This is not expected Exception", e);
}
}
use of org.apache.geode.cache.execute.FunctionInvocationTargetException in project geode by apache.
the class PRClientServerRegionFunctionExecutionSelectorNoSingleHopDUnitTest method serverMultiKeyExecution_FunctionInvocationTargetException.
public static void serverMultiKeyExecution_FunctionInvocationTargetException() {
Region region = cache.getRegion(PartitionedRegionName);
assertNotNull(region);
final HashSet testKeysSet = new HashSet();
for (int i = (totalNumBuckets.intValue() * 2); i > 0; i--) {
testKeysSet.add("execKey-" + i);
}
DistributedSystem.setThreadsSocketPolicy(false);
Execution dataSet = FunctionService.onRegion(region);
int j = 0;
HashSet origVals = new HashSet();
for (Iterator i = testKeysSet.iterator(); i.hasNext(); ) {
Integer val = new Integer(j++);
origVals.add(val);
region.put(i.next(), val);
}
ResultCollector rc1 = null;
try {
rc1 = dataSet.withFilter(testKeysSet).setArguments(Boolean.TRUE).execute(new FunctionAdapter() {
public void execute(FunctionContext context) {
if (((RegionFunctionContext) context).isPossibleDuplicate()) {
context.getResultSender().lastResult(new Integer(retryCount));
return;
}
if (context.getArguments() instanceof Boolean) {
throw new FunctionInvocationTargetException("I have been thrown from TestFunction");
}
}
public String getId() {
return getClass().getName();
}
public boolean hasResult() {
return true;
}
});
List list = (ArrayList) rc1.getResult();
assertEquals(list.get(0), 0);
} catch (Throwable e) {
e.printStackTrace();
Assert.fail("This is not expected Exception", e);
}
}
use of org.apache.geode.cache.execute.FunctionInvocationTargetException in project geode by apache.
the class PRClientServerRegionFunctionExecutionSingleHopDUnitTest method serverMultiKeyExecution_FunctionInvocationTargetException.
public static void serverMultiKeyExecution_FunctionInvocationTargetException() {
Region region = cache.getRegion(PartitionedRegionName);
assertNotNull(region);
final HashSet testKeysSet = new HashSet();
for (int i = (totalNumBuckets.intValue() * 2); i > 0; i--) {
testKeysSet.add("execKey-" + i);
}
DistributedSystem.setThreadsSocketPolicy(false);
Execution dataSet = FunctionService.onRegion(region);
int j = 0;
HashSet origVals = new HashSet();
for (Iterator i = testKeysSet.iterator(); i.hasNext(); ) {
Integer val = new Integer(j++);
origVals.add(val);
region.put(i.next(), val);
}
ResultCollector rc1 = null;
try {
rc1 = dataSet.withFilter(testKeysSet).setArguments(Boolean.TRUE).execute(new FunctionAdapter() {
@Override
public void execute(FunctionContext context) {
if (((RegionFunctionContext) context).isPossibleDuplicate()) {
context.getResultSender().lastResult(new Integer(retryCount));
return;
}
if (context.getArguments() instanceof Boolean) {
throw new FunctionInvocationTargetException("I have been thrown from TestFunction");
}
}
@Override
public String getId() {
return getClass().getName();
}
@Override
public boolean hasResult() {
return true;
}
});
List list = (ArrayList) rc1.getResult();
assertEquals(list.get(0), 0);
} catch (Throwable e) {
e.printStackTrace();
Assert.fail("This is not expected Exception", e);
}
}
use of org.apache.geode.cache.execute.FunctionInvocationTargetException in project geode by apache.
the class RegionCommands method listRegion.
@CliCommand(value = { CliStrings.LIST_REGION }, help = CliStrings.LIST_REGION__HELP)
@CliMetaData(shellOnly = false, relatedTopic = CliStrings.TOPIC_GEODE_REGION)
@ResourceOperation(resource = Resource.DATA, operation = Operation.READ)
public Result listRegion(@CliOption(key = { CliStrings.LIST_REGION__GROUP }, optionContext = ConverterHint.MEMBERGROUP, help = CliStrings.LIST_REGION__GROUP__HELP) String[] group, @CliOption(key = { CliStrings.LIST_REGION__MEMBER }, optionContext = ConverterHint.MEMBERIDNAME, help = CliStrings.LIST_REGION__MEMBER__HELP) String[] memberNameOrId) {
Result result = null;
try {
Set<RegionInformation> regionInfoSet = new LinkedHashSet<RegionInformation>();
ResultCollector<?, ?> rc = null;
Set<DistributedMember> targetMembers = CliUtil.findMembers(group, memberNameOrId);
if (targetMembers.isEmpty()) {
return ResultBuilder.createUserErrorResult(CliStrings.NO_MEMBERS_FOUND_MESSAGE);
}
TabularResultData resultData = ResultBuilder.createTabularResultData();
rc = CliUtil.executeFunction(getRegionsFunction, null, targetMembers);
ArrayList<?> resultList = (ArrayList<?>) rc.getResult();
if (resultList != null) {
Iterator<?> iters = resultList.iterator();
while (iters.hasNext()) {
Object resultObj = iters.next();
if (resultObj != null) {
if (resultObj instanceof Object[]) {
Object[] resultObjectArray = (Object[]) resultObj;
for (Object regionInfo : resultObjectArray) {
if (regionInfo instanceof RegionInformation) {
regionInfoSet.add((RegionInformation) regionInfo);
}
}
}
}
}
Set<String> regionNames = new TreeSet<String>();
for (RegionInformation regionInfo : regionInfoSet) {
regionNames.add(regionInfo.getName());
Set<String> subRegionNames = regionInfo.getSubRegionNames();
for (String subRegionName : subRegionNames) {
regionNames.add(subRegionName);
}
}
for (String regionName : regionNames) {
resultData.accumulate("List of regions", regionName);
}
if (!regionNames.isEmpty()) {
result = ResultBuilder.buildResult(resultData);
} else {
result = ResultBuilder.createInfoResult(CliStrings.LIST_REGION__MSG__NOT_FOUND);
}
}
} catch (FunctionInvocationTargetException e) {
result = ResultBuilder.createGemFireErrorResult(CliStrings.format(CliStrings.COULD_NOT_EXECUTE_COMMAND_TRY_AGAIN, CliStrings.LIST_REGION));
} catch (Exception e) {
result = ResultBuilder.createGemFireErrorResult(CliStrings.LIST_REGION__MSG__ERROR + " : " + e.getMessage());
}
return result;
}
Aggregations