Search in sources :

Example 21 with ResultCollector

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

the class ClientServerFunctionExecutionDUnitTest method serverFunctionExecution_FunctionInvocationTargetException.

@SuppressWarnings("rawtypes")
public static void serverFunctionExecution_FunctionInvocationTargetException(Boolean isByName, Function function, Boolean toRegister) {
    DistributedSystem.setThreadsSocketPolicy(false);
    if (toRegister.booleanValue()) {
        FunctionService.registerFunction(function);
    }
    Execution member = FunctionService.onServer(pool);
    try {
        ResultCollector rs = execute(member, Boolean.TRUE, function, isByName);
        ArrayList list = (ArrayList) rs.getResult();
        assertTrue("Value of send result of the executed function : " + list.get(0) + "does not match the expected value : " + 1, ((Integer) list.get(0)) == 1);
        assertTrue("Value of last result of the executed function : " + list.get(0) + "is not equal or more than expected value : " + 5, ((Integer) list.get(1)) >= 5);
    } catch (Exception ex) {
        ex.printStackTrace();
        Assert.fail("This is not expected Exception", ex);
    }
}
Also used : Execution(org.apache.geode.cache.execute.Execution) ArrayList(java.util.ArrayList) ResultCollector(org.apache.geode.cache.execute.ResultCollector) ServerConnectivityException(org.apache.geode.cache.client.ServerConnectivityException) ServerOperationException(org.apache.geode.cache.client.ServerOperationException) IgnoredException(org.apache.geode.test.dunit.IgnoredException)

Example 22 with ResultCollector

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

the class ClientServerFunctionExecutionDUnitTest method FunctionExecution_Inline_Bug40714.

public static void FunctionExecution_Inline_Bug40714() {
    DistributedSystem.setThreadsSocketPolicy(false);
    Execution member = FunctionService.onServers(pool);
    try {
        ResultCollector rs = member.setArguments(Boolean.TRUE).execute(new FunctionAdapter() {

            public void execute(FunctionContext context) {
                if (context.getArguments() instanceof String) {
                    context.getResultSender().lastResult("Success");
                } else if (context.getArguments() instanceof Boolean) {
                    context.getResultSender().lastResult(Boolean.TRUE);
                }
            }

            public String getId() {
                return "Function";
            }

            public boolean hasResult() {
                return true;
            }
        });
        List resultList = (List) rs.getResult();
        assertEquals(3, resultList.size());
        assertEquals(Boolean.TRUE, resultList.get(0));
        assertEquals(Boolean.TRUE, resultList.get(1));
        assertEquals(Boolean.TRUE, resultList.get(2));
    } catch (Exception ex) {
        ex.printStackTrace();
        LogWriterUtils.getLogWriter().info("Exception : ", ex);
        fail("Test failed after the execute operation.");
    }
}
Also used : Execution(org.apache.geode.cache.execute.Execution) FunctionAdapter(org.apache.geode.cache.execute.FunctionAdapter) ArrayList(java.util.ArrayList) List(java.util.List) ResultCollector(org.apache.geode.cache.execute.ResultCollector) FunctionContext(org.apache.geode.cache.execute.FunctionContext) ServerConnectivityException(org.apache.geode.cache.client.ServerConnectivityException) ServerOperationException(org.apache.geode.cache.client.ServerOperationException) IgnoredException(org.apache.geode.test.dunit.IgnoredException)

Example 23 with ResultCollector

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

the class ClientServerFunctionExecutionDUnitTest method serverExecutionHAOneServerDown.

public static Object serverExecutionHAOneServerDown(Boolean isByName, Function function, Boolean toRegister) {
    DistributedSystem.setThreadsSocketPolicy(false);
    if (toRegister.booleanValue()) {
        FunctionService.registerFunction(function);
    }
    Execution member = FunctionService.onServer(pool);
    ResultCollector rs = null;
    try {
        ArrayList<String> args = new ArrayList<String>();
        args.add(retryRegionName);
        args.add("serverExecutionHAOneServerDown");
        rs = execute(member, args, function, isByName);
        assertEquals(retryRegionName, ((List) rs.getResult()).get(0));
    } catch (Exception ex) {
        ex.printStackTrace();
        LogWriterUtils.getLogWriter().info("Exception : ", ex);
        fail("Test failed after the execute operation");
    }
    return rs.getResult();
}
Also used : Execution(org.apache.geode.cache.execute.Execution) ArrayList(java.util.ArrayList) ResultCollector(org.apache.geode.cache.execute.ResultCollector) ServerConnectivityException(org.apache.geode.cache.client.ServerConnectivityException) ServerOperationException(org.apache.geode.cache.client.ServerOperationException) IgnoredException(org.apache.geode.test.dunit.IgnoredException)

Example 24 with ResultCollector

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

the class ClientServerFunctionExecutionDUnitTest method serverExecution.

public static void serverExecution(Boolean isByName, Function function, Boolean toRegister) {
    DistributedSystem.setThreadsSocketPolicy(false);
    if (toRegister.booleanValue()) {
        FunctionService.registerFunction(function);
    }
    Execution member = FunctionService.onServer(pool);
    try {
        ResultCollector rs = execute(member, Boolean.TRUE, function, isByName);
        assertEquals(Boolean.TRUE, ((List) rs.getResult()).get(0));
    } catch (Exception ex) {
        ex.printStackTrace();
        LogWriterUtils.getLogWriter().info("Exception : ", ex);
        fail("Test failed after the execute operation");
    }
    try {
        final HashSet testKeysSet = new HashSet();
        for (int i = 0; i < 20; i++) {
            testKeysSet.add("execKey-" + i);
        }
        ResultCollector rs = execute(member, testKeysSet, function, isByName);
        List resultList = (List) ((List) rs.getResult());
        for (int i = 0; i < 20; i++) {
            assertEquals(true, ((List) (resultList.get(0))).contains("execKey-" + i));
        }
    } catch (Exception ex) {
        ex.printStackTrace();
        LogWriterUtils.getLogWriter().info("Exception : ", ex);
        fail("Test failed after the execute operations");
    }
}
Also used : Execution(org.apache.geode.cache.execute.Execution) ArrayList(java.util.ArrayList) List(java.util.List) ResultCollector(org.apache.geode.cache.execute.ResultCollector) ServerConnectivityException(org.apache.geode.cache.client.ServerConnectivityException) ServerOperationException(org.apache.geode.cache.client.ServerOperationException) IgnoredException(org.apache.geode.test.dunit.IgnoredException) HashSet(java.util.HashSet)

Example 25 with ResultCollector

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

the class PRFunctionExecutionDUnitTest method testRemoteSingleKeyExecution_byName_FunctionInvocationTargetException.

/**
   * Test remote execution by a pure accessor which doesn't have the function factory
   * present.Function throws the FunctionInvocationTargetException. As this is the case of HA then
   * system should retry the function execution. After 5th attempt function will send Boolean as
   * last result.
   */
@Test
public void testRemoteSingleKeyExecution_byName_FunctionInvocationTargetException() throws Exception {
    final String rName = getUniqueName();
    Host host = Host.getHost(0);
    final VM accessor = host.getVM(2);
    final VM datastore = host.getVM(3);
    getCache();
    accessor.invoke(new SerializableCallable("Create PR") {

        public Object call() throws Exception {
            RegionAttributes ra = PartitionedRegionTestHelper.createRegionAttrsForPR(0, 0);
            getCache().createRegion(rName, ra);
            return Boolean.TRUE;
        }
    });
    datastore.invoke(new SerializableCallable("Create PR with Function Factory") {

        public Object call() throws Exception {
            RegionAttributes ra = PartitionedRegionTestHelper.createRegionAttrsForPR(0, 10);
            AttributesFactory raf = new AttributesFactory(ra);
            PartitionAttributesImpl pa = new PartitionAttributesImpl();
            pa.setAll(ra.getPartitionAttributes());
            raf.setPartitionAttributes(pa);
            getCache().createRegion(rName, raf.create());
            Function function = new TestFunction(true, TestFunction.TEST_FUNCTION_REEXECUTE_EXCEPTION);
            FunctionService.registerFunction(function);
            return Boolean.TRUE;
        }
    });
    accessor.invoke(new SerializableCallable("Create data, invoke exectuable") {

        public Object call() throws Exception {
            PartitionedRegion pr = (PartitionedRegion) getCache().getRegion(rName);
            final String testKey = "execKey";
            final Set testKeysSet = new HashSet();
            testKeysSet.add(testKey);
            DistributedSystem.setThreadsSocketPolicy(false);
            Function function = new TestFunction(true, TestFunction.TEST_FUNCTION_REEXECUTE_EXCEPTION);
            FunctionService.registerFunction(function);
            Execution dataSet = FunctionService.onRegion(pr);
            pr.put(testKey, new Integer(1));
            try {
                ResultCollector rs1 = dataSet.withFilter(testKeysSet).setArguments(Boolean.TRUE).execute(function.getId());
                List list = (ArrayList) rs1.getResult();
                assertEquals(list.get(0), 5);
            } catch (Throwable e) {
                e.printStackTrace();
                Assert.fail("This is not expected Exception", e);
            }
            return Boolean.TRUE;
        }
    });
}
Also used : LocalDataSet(org.apache.geode.internal.cache.LocalDataSet) Set(java.util.Set) HashSet(java.util.HashSet) TestFunction(org.apache.geode.internal.cache.functions.TestFunction) RegionAttributes(org.apache.geode.cache.RegionAttributes) Host(org.apache.geode.test.dunit.Host) IgnoredException(org.apache.geode.test.dunit.IgnoredException) FunctionException(org.apache.geode.cache.execute.FunctionException) Function(org.apache.geode.cache.execute.Function) TestFunction(org.apache.geode.internal.cache.functions.TestFunction) AttributesFactory(org.apache.geode.cache.AttributesFactory) PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) PartitionAttributesImpl(org.apache.geode.internal.cache.PartitionAttributesImpl) Execution(org.apache.geode.cache.execute.Execution) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) VM(org.apache.geode.test.dunit.VM) SerializableCallable(org.apache.geode.test.dunit.SerializableCallable) List(java.util.List) ArrayList(java.util.ArrayList) ResultCollector(org.apache.geode.cache.execute.ResultCollector) HashSet(java.util.HashSet) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest) Test(org.junit.Test)

Aggregations

ResultCollector (org.apache.geode.cache.execute.ResultCollector)235 Execution (org.apache.geode.cache.execute.Execution)164 HashSet (java.util.HashSet)148 ArrayList (java.util.ArrayList)144 FunctionException (org.apache.geode.cache.execute.FunctionException)126 PartitionedRegion (org.apache.geode.internal.cache.PartitionedRegion)122 List (java.util.List)112 Function (org.apache.geode.cache.execute.Function)111 TestFunction (org.apache.geode.internal.cache.functions.TestFunction)106 Test (org.junit.Test)101 IgnoredException (org.apache.geode.test.dunit.IgnoredException)94 Iterator (java.util.Iterator)81 Region (org.apache.geode.cache.Region)77 Set (java.util.Set)69 FunctionInvocationTargetException (org.apache.geode.cache.execute.FunctionInvocationTargetException)65 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)63 SerializableCallable (org.apache.geode.test.dunit.SerializableCallable)56 AttributesFactory (org.apache.geode.cache.AttributesFactory)53 Host (org.apache.geode.test.dunit.Host)53 VM (org.apache.geode.test.dunit.VM)53