Search in sources :

Example 61 with ResultCollector

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

the class PRClientServerRegionFunctionExecutionDUnitTest method serverMultiKeyExecution_ThrowException.

public static void serverMultiKeyExecution_ThrowException(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_THROW_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);
        fail("Exception Expected");
    } catch (Exception ex) {
        ex.printStackTrace();
    }
}
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) 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) 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 62 with ResultCollector

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

the class PRClientServerRegionFunctionExecutionDUnitTest method serverSingleKeyExecution_FunctionInvocationTargetException.

public static void serverSingleKeyExecution_FunctionInvocationTargetException() 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_REEXECUTE_EXCEPTION);
    FunctionService.registerFunction(function);
    Execution dataSet = FunctionService.onRegion(region);
    region.put(testKey, new Integer(1));
    ResultCollector rs = execute(dataSet, testKeysSet, Boolean.TRUE, function, false);
    ArrayList list = (ArrayList) rs.getResult();
    assertTrue(((Integer) list.get(0)) >= 5);
}
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) ArrayList(java.util.ArrayList) 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 63 with ResultCollector

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

the class PRClientServerRegionFunctionExecutionDUnitTest method regionSingleKeyExecutionNonHA.

public static void regionSingleKeyExecutionNonHA(Boolean isByName, Function function, 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);
    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 {
        ArrayList<String> args = new ArrayList<String>();
        args.add(retryRegionName);
        args.add("regionSingleKeyExecutionNonHA");
        ResultCollector rs = execute(dataSet, testKeysSet, args, function, isByName);
        fail("Expected ServerConnectivityException not thrown!");
    } catch (Exception ex) {
        if (!(ex.getCause() instanceof ServerConnectivityException) && !(ex.getCause() instanceof FunctionInvocationTargetException)) {
            throw ex;
        }
    }
}
Also used : ServerConnectivityException(org.apache.geode.cache.client.ServerConnectivityException) Set(java.util.Set) HashSet(java.util.HashSet) Execution(org.apache.geode.cache.execute.Execution) ArrayList(java.util.ArrayList) FunctionInvocationTargetException(org.apache.geode.cache.execute.FunctionInvocationTargetException) 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 64 with ResultCollector

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

the class PRClientServerRegionFunctionExecutionSelectorNoSingleHopDUnitTest method executeFunction.

public static void executeFunction() throws ServerException, InterruptedException {
    Region region = cache.getRegion(PartitionedRegionName);
    assertNotNull(region);
    final HashSet testKeysSet = new HashSet();
    for (int i = (totalNumBuckets.intValue() * 10); 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 {
        ResultCollector rc1 = dataSet.withFilter(testKeysSet).setArguments(Boolean.TRUE).execute(function.getId());
        HashMap resultMap = ((HashMap) rc1.getResult());
        assertEquals(3, resultMap.size());
        Iterator mapIterator = resultMap.entrySet().iterator();
        Map.Entry entry = null;
        DistributedMember key = null;
        ArrayList resultListForMember = null;
        while (mapIterator.hasNext()) {
            entry = (Map.Entry) mapIterator.next();
            key = (DistributedMember) entry.getKey();
            resultListForMember = (ArrayList) entry.getValue();
            for (Object result : resultListForMember) {
                assertEquals(Boolean.TRUE, result);
            }
        }
    } catch (Exception e) {
        LogWriterUtils.getLogWriter().info("Got an exception : " + e.getMessage());
        assertTrue(e instanceof EOFException || e instanceof SocketException || e instanceof SocketTimeoutException || e instanceof ServerException || e instanceof IOException || e instanceof CacheClosedException);
    }
}
Also used : SocketException(java.net.SocketException) ServerException(java.rmi.ServerException) TestFunction(org.apache.geode.internal.cache.functions.TestFunction) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) IOException(java.io.IOException) CacheClosedException(org.apache.geode.cache.CacheClosedException) 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) SocketTimeoutException(java.net.SocketTimeoutException) Iterator(java.util.Iterator) DistributedMember(org.apache.geode.distributed.DistributedMember) EOFException(java.io.EOFException) Region(org.apache.geode.cache.Region) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) ResultCollector(org.apache.geode.cache.execute.ResultCollector) HashMap(java.util.HashMap) Map(java.util.Map) HashSet(java.util.HashSet)

Example 65 with ResultCollector

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

the class PRClientServerRegionFunctionExecutionNoSingleHopDUnitTest method serverMultiKeyExecutionNoResult.

public static void serverMultiKeyExecutionNoResult(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(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) {
        expected.printStackTrace();
        LogWriterUtils.getLogWriter().info("Exception : " + expected.getMessage());
        assertTrue(expected.getMessage().startsWith((LocalizedStrings.ExecuteFunction_CANNOT_0_RESULTS_HASRESULT_FALSE.toLocalizedString("return any"))));
    } catch (Exception notexpected) {
        Assert.fail("Test failed during execute or sleeping", notexpected);
    } 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) 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