Search in sources :

Example 51 with Execution

use of org.apache.geode.cache.execute.Execution in project geode by apache.

the class PRClientServerRegionFunctionExecutionDUnitTest method serverMultiKeyExecutionNoResult.

public static void serverMultiKeyExecutionNoResult(Boolean isByName) throws Exception {
    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);
    Function function = new TestFunction(false, TEST_FUNCTION7);
    FunctionService.registerFunction(function);
    Execution dataSet = FunctionService.onRegion(region);
    try {
        String msg = "<ExpectedException action=add>" + "FunctionException" + "</ExpectedException>";
        cache.getLogger().info(msg);
        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 = execute(dataSet, testKeysSet, Boolean.TRUE, function, isByName);
        rc1.getResult();
        Thread.sleep(20000);
        fail("Test failed after the put operation");
    } catch (FunctionException expected) {
        assertTrue(expected.getMessage().startsWith((LocalizedStrings.ExecuteFunction_CANNOT_0_RESULTS_HASRESULT_FALSE.toLocalizedString("return any"))));
    } finally {
        cache.getLogger().info("<ExpectedException action=remove>" + "FunctionException" + "</ExpectedException>");
    }
}
Also used : Function(org.apache.geode.cache.execute.Function) TestFunction(org.apache.geode.internal.cache.functions.TestFunction) Execution(org.apache.geode.cache.execute.Execution) TestFunction(org.apache.geode.internal.cache.functions.TestFunction) Iterator(java.util.Iterator) FunctionException(org.apache.geode.cache.execute.FunctionException) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) Region(org.apache.geode.cache.Region) ResultCollector(org.apache.geode.cache.execute.ResultCollector) HashSet(java.util.HashSet)

Example 52 with Execution

use of org.apache.geode.cache.execute.Execution in project geode by apache.

the class PRClientServerRegionFunctionExecutionDUnitTest method serverSingleKeyExecution_NoLastResult.

public static void serverSingleKeyExecution_NoLastResult(Boolean isByName, Boolean toRegister) throws Exception {
    Region region = cache.getRegion(PartitionedRegionName);
    assertNotNull(region);
    final String testKey = "execKey";
    final Set testKeysSet = new HashSet();
    testKeysSet.add(testKey);
    DistributedSystem.setThreadsSocketPolicy(false);
    Function function = new TestFunction(true, TestFunction.TEST_FUNCTION_NO_LASTRESULT);
    if (toRegister.booleanValue()) {
        FunctionService.registerFunction(function);
    } else {
        FunctionService.unregisterFunction(function.getId());
        assertNull(FunctionService.getFunction(function.getId()));
    }
    Execution dataSet = FunctionService.onRegion(region);
    region.put(testKey, new Integer(1));
    try {
        ResultCollector rs = execute(dataSet, testKeysSet, Boolean.TRUE, function, isByName);
        assertEquals(Boolean.TRUE, ((List) rs.getResult()).get(0));
        fail("Expected FunctionException : Function did not send last result");
    } catch (Exception ex) {
        if (!ex.getMessage().contains("did not send last result")) {
            throw ex;
        }
    }
}
Also used : Function(org.apache.geode.cache.execute.Function) TestFunction(org.apache.geode.internal.cache.functions.TestFunction) Set(java.util.Set) HashSet(java.util.HashSet) Execution(org.apache.geode.cache.execute.Execution) TestFunction(org.apache.geode.internal.cache.functions.TestFunction) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) Region(org.apache.geode.cache.Region) ResultCollector(org.apache.geode.cache.execute.ResultCollector) ServerException(java.rmi.ServerException) IgnoredException(org.apache.geode.test.dunit.IgnoredException) FunctionInvocationTargetException(org.apache.geode.cache.execute.FunctionInvocationTargetException) FunctionException(org.apache.geode.cache.execute.FunctionException) CacheClosedException(org.apache.geode.cache.CacheClosedException) ServerConnectivityException(org.apache.geode.cache.client.ServerConnectivityException) ServerOperationException(org.apache.geode.cache.client.ServerOperationException) IOException(java.io.IOException) HashSet(java.util.HashSet)

Example 53 with Execution

use of org.apache.geode.cache.execute.Execution in project geode by apache.

the class PRClientServerRegionFunctionExecutionDUnitTest method serverMultiKeyExecution_SendException.

public static void serverMultiKeyExecution_SendException(Boolean isByName) {
    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);
    Function function = new TestFunction(true, TestFunction.TEST_FUNCTION_SEND_EXCEPTION);
    FunctionService.registerFunction(function);
    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);
    }
    try {
        List l = null;
        ResultCollector rc1 = execute(dataSet, testKeysSet, Boolean.TRUE, function, isByName);
        l = ((List) rc1.getResult());
        LogWriterUtils.getLogWriter().info("Result size : " + l.size());
        assertEquals(3, l.size());
        for (Iterator i = l.iterator(); i.hasNext(); ) {
            assertTrue(i.next() instanceof MyFunctionExecutionException);
        }
    } catch (Exception ex) {
        ex.printStackTrace();
        fail("No Exception Expected");
    }
    try {
        List l = null;
        ResultCollector rc1 = execute(dataSet, testKeysSet, testKeysSet, function, isByName);
        List resultList = (List) rc1.getResult();
        assertEquals(((testKeysSet.size() * 3) + 3), resultList.size());
        Iterator resultIterator = resultList.iterator();
        int exceptionCount = 0;
        while (resultIterator.hasNext()) {
            Object o = resultIterator.next();
            if (o instanceof MyFunctionExecutionException) {
                exceptionCount++;
            }
        }
        assertEquals(3, exceptionCount);
    } catch (Exception ex) {
        ex.printStackTrace();
        fail("No Exception Expected");
    }
}
Also used : TestFunction(org.apache.geode.internal.cache.functions.TestFunction) ServerException(java.rmi.ServerException) IgnoredException(org.apache.geode.test.dunit.IgnoredException) FunctionInvocationTargetException(org.apache.geode.cache.execute.FunctionInvocationTargetException) FunctionException(org.apache.geode.cache.execute.FunctionException) CacheClosedException(org.apache.geode.cache.CacheClosedException) ServerConnectivityException(org.apache.geode.cache.client.ServerConnectivityException) ServerOperationException(org.apache.geode.cache.client.ServerOperationException) IOException(java.io.IOException) Function(org.apache.geode.cache.execute.Function) TestFunction(org.apache.geode.internal.cache.functions.TestFunction) Execution(org.apache.geode.cache.execute.Execution) Iterator(java.util.Iterator) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) Region(org.apache.geode.cache.Region) List(java.util.List) ArrayList(java.util.ArrayList) ResultCollector(org.apache.geode.cache.execute.ResultCollector) HashSet(java.util.HashSet)

Example 54 with Execution

use of org.apache.geode.cache.execute.Execution in project geode by apache.

the class OnGroupsFunctionExecutionDUnitTest method testP2PMemberFailure.

@Test
public void testP2PMemberFailure() {
    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");
            e1 = e1.setArguments(args);
            try {
                e1.execute(new OnGroupsExceptionFunction()).getResult();
                fail("expected exception not thrown");
            } catch (FunctionException ex) {
                assertTrue(ex.getCause() instanceof FunctionInvocationTargetException);
            }
            return null;
        }
    });
}
Also used : ArrayList(java.util.ArrayList) FunctionException(org.apache.geode.cache.execute.FunctionException) 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 55 with Execution

use of org.apache.geode.cache.execute.Execution in project geode by apache.

the class OnGroupsFunctionExecutionDUnitTest method testP2PException.

@Test
public void testP2PException() {
    Host host = Host.getHost(0);
    VM vm0 = host.getVM(0);
    VM vm1 = host.getVM(1);
    VM vm2 = host.getVM(2);
    final String regionName = getName();
    // The test function deliberately throws a null pointer exception.
    // which is logged.
    IgnoredException.addIgnoredException(NullPointerException.class.getSimpleName());
    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 e = FunctionService.onMembers("mg");
            ArrayList<String> args = new ArrayList<String>();
            args.add("runtime");
            e = e.setArguments(args);
            try {
                e.execute(new OnGroupsExceptionFunction()).getResult();
                fail("expected exception not thrown");
            } catch (FunctionException ex) {
                assertTrue(ex.getCause() instanceof NullPointerException);
            }
            Execution e1 = FunctionService.onMembers("g1");
            e1 = e1.setArguments(args);
            try {
                e1.execute(new OnGroupsExceptionFunction()).getResult();
                fail("expected exception not thrown");
            } catch (FunctionException ex) {
                assertTrue(ex.getCause() instanceof NullPointerException);
            }
            // fail on only one member
            Execution e2 = FunctionService.onMembers("g1");
            args.add("g2");
            e2 = e2.setArguments(args);
            try {
                e2.execute(new OnGroupsExceptionFunction()).getResult();
                fail("expected exception not thrown");
            } catch (FunctionException ex) {
                assertTrue(ex.getCause() instanceof NullPointerException);
            }
            return null;
        }
    });
}
Also used : ArrayList(java.util.ArrayList) FunctionException(org.apache.geode.cache.execute.FunctionException) 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) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Aggregations

Execution (org.apache.geode.cache.execute.Execution)217 ResultCollector (org.apache.geode.cache.execute.ResultCollector)163 HashSet (java.util.HashSet)144 ArrayList (java.util.ArrayList)139 FunctionException (org.apache.geode.cache.execute.FunctionException)131 PartitionedRegion (org.apache.geode.internal.cache.PartitionedRegion)127 Function (org.apache.geode.cache.execute.Function)121 TestFunction (org.apache.geode.internal.cache.functions.TestFunction)108 IgnoredException (org.apache.geode.test.dunit.IgnoredException)108 List (java.util.List)106 Test (org.junit.Test)85 Iterator (java.util.Iterator)79 Region (org.apache.geode.cache.Region)79 SerializableCallable (org.apache.geode.test.dunit.SerializableCallable)74 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)74 VM (org.apache.geode.test.dunit.VM)70 FunctionInvocationTargetException (org.apache.geode.cache.execute.FunctionInvocationTargetException)69 Host (org.apache.geode.test.dunit.Host)69 Set (java.util.Set)65 CacheClosedException (org.apache.geode.cache.CacheClosedException)59