Search in sources :

Example 51 with ResultCollector

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

the class ClientServerFunctionExecutionDUnitTest method serverExecution_Inline_InvalidAttributes.

public static void serverExecution_Inline_InvalidAttributes() {
    DistributedSystem.setThreadsSocketPolicy(false);
    Execution member = FunctionService.onServer(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 getClass().getName();
            }

            public boolean hasResult() {
                return false;
            }

            public boolean isHA() {
                return true;
            }
        });
        fail("Should have failed with Invalid attributes.");
    } catch (Exception ex) {
        LogWriterUtils.getLogWriter().info("Exception : ", ex);
        assertTrue(ex.getMessage().contains("For Functions with isHA true, hasResult must also be true."));
    }
}
Also used : Execution(org.apache.geode.cache.execute.Execution) FunctionAdapter(org.apache.geode.cache.execute.FunctionAdapter) 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 52 with ResultCollector

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

the class PRClientServerRegionFunctionExecutionDUnitTest method serverSingleKeyExecution.

public static void serverSingleKeyExecution(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, TEST_FUNCTION2);
    if (toRegister.booleanValue()) {
        FunctionService.registerFunction(function);
    } else {
        FunctionService.unregisterFunction(function.getId());
        assertNull(FunctionService.getFunction(function.getId()));
    }
    Execution dataSet = FunctionService.onRegion(region);
    try {
        execute(dataSet, testKeysSet, Boolean.TRUE, function, isByName);
    } catch (Exception ex) {
        if (!(ex.getMessage().contains("No target node found for KEY = " + testKey) || ex.getMessage().startsWith("Server could not send the reply") || ex.getMessage().startsWith("Unexpected exception during"))) {
            throw ex;
        }
    }
    region.put(testKey, new Integer(1));
    ResultCollector rs = execute(dataSet, testKeysSet, Boolean.TRUE, function, isByName);
    assertEquals(Boolean.TRUE, ((List) rs.getResult()).get(0));
    ResultCollector rs2 = execute(dataSet, testKeysSet, testKey, function, isByName);
    assertEquals(new Integer(1), ((List) rs2.getResult()).get(0));
    HashMap putData = new HashMap();
    putData.put(testKey + "1", new Integer(2));
    putData.put(testKey + "2", new Integer(3));
    ResultCollector rs1 = execute(dataSet, testKeysSet, putData, function, isByName);
    assertEquals(Boolean.TRUE, ((List) rs1.getResult()).get(0));
    assertEquals(new Integer(2), region.get(testKey + "1"));
    assertEquals(new Integer(3), region.get(testKey + "2"));
}
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) HashMap(java.util.HashMap) 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 ResultCollector

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

the class PRClientServerRegionFunctionExecutionFailoverDUnitTest method executeFunction.

public static Object executeFunction() {
    Execution execute = FunctionService.onRegion(region);
    ResultCollector rc = execute.setArguments(Boolean.TRUE).execute(new TestFunction(true, TestFunction.TEST_FUNCTION_LASTRESULT));
    LogWriterUtils.getLogWriter().info("Exeuction Result :" + rc.getResult());
    List l = ((List) rc.getResult());
    return l;
}
Also used : Execution(org.apache.geode.cache.execute.Execution) TestFunction(org.apache.geode.internal.cache.functions.TestFunction) ArrayList(java.util.ArrayList) List(java.util.List) ResultCollector(org.apache.geode.cache.execute.ResultCollector)

Example 54 with ResultCollector

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

the class PRClientServerRegionFunctionExecutionNoSingleHopDUnitTest method serverAllKeyExecution.

public static void serverAllKeyExecution(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, TEST_FUNCTION2);
    FunctionService.registerFunction(function);
    Execution dataSet = FunctionService.onRegion(region);
    try {
        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 = executeOnAll(dataSet, Boolean.TRUE, function, isByName);
        List resultList = (List) ((List) rc1.getResult());
        LogWriterUtils.getLogWriter().info("Result size : " + resultList.size());
        LogWriterUtils.getLogWriter().info("Result are SSSS : " + resultList);
        assertEquals(3, resultList.size());
        Iterator resultIterator = resultList.iterator();
        Map.Entry entry = null;
        DistributedMember key = null;
        List resultListForMember = new ArrayList();
        // }
        for (Object result : resultList) {
            assertEquals(Boolean.TRUE, result);
        }
        List l2 = null;
        ResultCollector rc2 = executeOnAll(dataSet, testKeysSet, function, isByName);
        l2 = ((List) rc2.getResult());
        assertEquals(3, l2.size());
        HashSet foundVals = new HashSet();
        for (Iterator i = l2.iterator(); i.hasNext(); ) {
            ArrayList subL = (ArrayList) (i.next());
            assertTrue(subL.size() > 0);
            for (Iterator subI = subL.iterator(); subI.hasNext(); ) {
                assertTrue(foundVals.add(subI.next()));
            }
        }
        assertEquals(origVals, foundVals);
    } catch (Exception e) {
        Assert.fail("Test failed after the put operation", e);
    }
}
Also used : TestFunction(org.apache.geode.internal.cache.functions.TestFunction) ArrayList(java.util.ArrayList) FunctionInvocationTargetException(org.apache.geode.cache.execute.FunctionInvocationTargetException) ServerException(java.rmi.ServerException) FunctionException(org.apache.geode.cache.execute.FunctionException) SocketException(java.net.SocketException) CacheClosedException(org.apache.geode.cache.CacheClosedException) SocketTimeoutException(java.net.SocketTimeoutException) IOException(java.io.IOException) EOFException(java.io.EOFException) IgnoredException(org.apache.geode.test.dunit.IgnoredException) 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) DistributedMember(org.apache.geode.distributed.DistributedMember) Region(org.apache.geode.cache.Region) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) ArrayList(java.util.ArrayList) List(java.util.List) ResultCollector(org.apache.geode.cache.execute.ResultCollector) HashMap(java.util.HashMap) Map(java.util.Map) HashSet(java.util.HashSet)

Example 55 with ResultCollector

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

the class PRClientServerRegionFunctionExecutionSelectorNoSingleHopDUnitTest method serverSingleKeyExecution.

public static void serverSingleKeyExecution(Boolean isByName) {
    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, TEST_FUNCTION2);
    FunctionService.registerFunction(function);
    Execution dataSet = FunctionService.onRegion(region);
    try {
        execute(dataSet, testKeysSet, Boolean.TRUE, function, isByName);
    } catch (Exception expected) {
        assertTrue(expected.getMessage().contains("No target node found for KEY = " + testKey) || expected.getMessage().startsWith("Server could not send the reply") || expected.getMessage().startsWith("Unexpected exception during"));
    }
    region.put(testKey, new Integer(1));
    try {
        ResultCollector rs = execute(dataSet, testKeysSet, Boolean.TRUE, function, isByName);
        assertEquals(Boolean.TRUE, ((List) rs.getResult()).get(0));
        ResultCollector rs2 = execute(dataSet, testKeysSet, testKey, function, isByName);
        assertEquals(new Integer(1), ((List) rs2.getResult()).get(0));
        HashMap putData = new HashMap();
        putData.put(testKey + "1", new Integer(2));
        putData.put(testKey + "2", new Integer(3));
        ResultCollector rs1 = execute(dataSet, testKeysSet, putData, function, isByName);
        assertEquals(Boolean.TRUE, ((List) rs1.getResult()).get(0));
        assertEquals(new Integer(2), region.get(testKey + "1"));
        assertEquals(new Integer(3), region.get(testKey + "2"));
    } catch (Exception ex) {
        ex.printStackTrace();
        LogWriterUtils.getLogWriter().info("Exception : ", ex);
        Assert.fail("Test failed after the put operation", ex);
    }
}
Also used : Function(org.apache.geode.cache.execute.Function) TestFunction(org.apache.geode.internal.cache.functions.TestFunction) HashSet(java.util.HashSet) Set(java.util.Set) Execution(org.apache.geode.cache.execute.Execution) TestFunction(org.apache.geode.internal.cache.functions.TestFunction) HashMap(java.util.HashMap) Region(org.apache.geode.cache.Region) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) ResultCollector(org.apache.geode.cache.execute.ResultCollector) FunctionInvocationTargetException(org.apache.geode.cache.execute.FunctionInvocationTargetException) ServerException(java.rmi.ServerException) FunctionException(org.apache.geode.cache.execute.FunctionException) SocketException(java.net.SocketException) CacheClosedException(org.apache.geode.cache.CacheClosedException) SocketTimeoutException(java.net.SocketTimeoutException) IOException(java.io.IOException) EOFException(java.io.EOFException) IgnoredException(org.apache.geode.test.dunit.IgnoredException) HashSet(java.util.HashSet)

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