Search in sources :

Example 26 with FunctionInvocationTargetException

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;
        }
    });
}
Also used : ArrayList(java.util.ArrayList) Host(org.apache.geode.test.dunit.Host) DistributedSystem(org.apache.geode.distributed.DistributedSystem) InternalDistributedSystem(org.apache.geode.distributed.internal.InternalDistributedSystem) FunctionInvocationTargetException(org.apache.geode.cache.execute.FunctionInvocationTargetException) FunctionException(org.apache.geode.cache.execute.FunctionException) CacheClosedException(org.apache.geode.cache.CacheClosedException) IgnoredException(org.apache.geode.test.dunit.IgnoredException) Execution(org.apache.geode.cache.execute.Execution) VM(org.apache.geode.test.dunit.VM) SerializableCallable(org.apache.geode.test.dunit.SerializableCallable) FunctionInvocationTargetException(org.apache.geode.cache.execute.FunctionInvocationTargetException) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Example 27 with FunctionInvocationTargetException

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);
    }
}
Also used : ArrayList(java.util.ArrayList) RegionFunctionContext(org.apache.geode.cache.execute.RegionFunctionContext) FunctionContext(org.apache.geode.cache.execute.FunctionContext) RegionFunctionContext(org.apache.geode.cache.execute.RegionFunctionContext) Execution(org.apache.geode.cache.execute.Execution) Iterator(java.util.Iterator) FunctionInvocationTargetException(org.apache.geode.cache.execute.FunctionInvocationTargetException) Region(org.apache.geode.cache.Region) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) FunctionAdapter(org.apache.geode.cache.execute.FunctionAdapter) ArrayList(java.util.ArrayList) List(java.util.List) ResultCollector(org.apache.geode.cache.execute.ResultCollector) HashSet(java.util.HashSet)

Example 28 with FunctionInvocationTargetException

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);
    }
}
Also used : ArrayList(java.util.ArrayList) RegionFunctionContext(org.apache.geode.cache.execute.RegionFunctionContext) FunctionContext(org.apache.geode.cache.execute.FunctionContext) RegionFunctionContext(org.apache.geode.cache.execute.RegionFunctionContext) Execution(org.apache.geode.cache.execute.Execution) Iterator(java.util.Iterator) FunctionInvocationTargetException(org.apache.geode.cache.execute.FunctionInvocationTargetException) Region(org.apache.geode.cache.Region) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) FunctionAdapter(org.apache.geode.cache.execute.FunctionAdapter) ArrayList(java.util.ArrayList) List(java.util.List) ResultCollector(org.apache.geode.cache.execute.ResultCollector) HashSet(java.util.HashSet)

Example 29 with FunctionInvocationTargetException

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);
    }
}
Also used : ArrayList(java.util.ArrayList) RegionFunctionContext(org.apache.geode.cache.execute.RegionFunctionContext) FunctionContext(org.apache.geode.cache.execute.FunctionContext) RegionFunctionContext(org.apache.geode.cache.execute.RegionFunctionContext) Execution(org.apache.geode.cache.execute.Execution) Iterator(java.util.Iterator) FunctionInvocationTargetException(org.apache.geode.cache.execute.FunctionInvocationTargetException) Region(org.apache.geode.cache.Region) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) FunctionAdapter(org.apache.geode.cache.execute.FunctionAdapter) ArrayList(java.util.ArrayList) List(java.util.List) ResultCollector(org.apache.geode.cache.execute.ResultCollector) HashSet(java.util.HashSet)

Example 30 with FunctionInvocationTargetException

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;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) RegionInformation(org.apache.geode.management.internal.cli.domain.RegionInformation) TabularResultData(org.apache.geode.management.internal.cli.result.TabularResultData) ArrayList(java.util.ArrayList) FunctionInvocationTargetException(org.apache.geode.cache.execute.FunctionInvocationTargetException) CommandResultException(org.apache.geode.management.internal.cli.result.CommandResultException) Result(org.apache.geode.management.cli.Result) TreeSet(java.util.TreeSet) DistributedMember(org.apache.geode.distributed.DistributedMember) FunctionInvocationTargetException(org.apache.geode.cache.execute.FunctionInvocationTargetException) CliCommand(org.springframework.shell.core.annotation.CliCommand) CliMetaData(org.apache.geode.management.cli.CliMetaData) ResourceOperation(org.apache.geode.management.internal.security.ResourceOperation)

Aggregations

FunctionInvocationTargetException (org.apache.geode.cache.execute.FunctionInvocationTargetException)36 ArrayList (java.util.ArrayList)20 FunctionException (org.apache.geode.cache.execute.FunctionException)19 CacheClosedException (org.apache.geode.cache.CacheClosedException)16 ResultCollector (org.apache.geode.cache.execute.ResultCollector)13 Execution (org.apache.geode.cache.execute.Execution)11 Region (org.apache.geode.cache.Region)10 List (java.util.List)9 PartitionedRegion (org.apache.geode.internal.cache.PartitionedRegion)9 InternalFunctionInvocationTargetException (org.apache.geode.internal.cache.execute.InternalFunctionInvocationTargetException)9 IOException (java.io.IOException)8 HashSet (java.util.HashSet)8 DistributedMember (org.apache.geode.distributed.DistributedMember)8 CliMetaData (org.apache.geode.management.cli.CliMetaData)8 Result (org.apache.geode.management.cli.Result)7 IgnoredException (org.apache.geode.test.dunit.IgnoredException)7 AbstractExecution (org.apache.geode.internal.cache.execute.AbstractExecution)6 SerializableCallable (org.apache.geode.test.dunit.SerializableCallable)6 Test (org.junit.Test)6 CliCommand (org.springframework.shell.core.annotation.CliCommand)6