Search in sources :

Example 16 with Function

use of org.apache.geode.cache.execute.Function 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 17 with Function

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

the class PRClientServerRegionFunctionExecutionDUnitTest method testClientWithoutPool_Bug41832.

@Test
public void testClientWithoutPool_Bug41832() {
    createScenarioWith2Regions();
    Function function = new TestFunction(true, TEST_FUNCTION2);
    registerFunctionAtServer(function);
    isByName = new Boolean(true);
    toRegister = new Boolean(true);
    SerializableRunnable suspect = new SerializableRunnable() {

        public void run() {
            cache.getLogger().info("<ExpectedException action=add>" + "No target node found for KEY = " + "|Server could not send the reply" + "|Unexpected exception during" + "</ExpectedException>");
        }
    };
    runOnAllServers(suspect);
    client.invoke(() -> PRClientServerRegionFunctionExecutionDUnitTest.serverSingleKeyExecutionWith2Regions(isByName, toRegister));
    SerializableRunnable endSuspect = new SerializableRunnable() {

        public void run() {
            cache.getLogger().info("<ExpectedException action=remove>" + "No target node found for KEY = " + "|Server could not send the reply" + "|Unexpected exception during" + "</ExpectedException>");
        }
    };
    runOnAllServers(endSuspect);
}
Also used : Function(org.apache.geode.cache.execute.Function) TestFunction(org.apache.geode.internal.cache.functions.TestFunction) TestFunction(org.apache.geode.internal.cache.functions.TestFunction) SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest) FlakyTest(org.apache.geode.test.junit.categories.FlakyTest) ClientServerTest(org.apache.geode.test.junit.categories.ClientServerTest) Test(org.junit.Test)

Example 18 with Function

use of org.apache.geode.cache.execute.Function 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 19 with Function

use of org.apache.geode.cache.execute.Function 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 20 with Function

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

the class PRClientServerRegionFunctionExecutionDUnitTest method testServerSingleKeyExecution_SendException.

@Test
public void testServerSingleKeyExecution_SendException() {
    createScenario();
    Function function = new TestFunction(true, TestFunction.TEST_FUNCTION_SEND_EXCEPTION);
    registerFunctionAtServer(function);
    isByName = new Boolean(true);
    toRegister = new Boolean(true);
    client.invoke(() -> PRClientServerRegionFunctionExecutionDUnitTest.serverSingleKeyExecution_SendException(isByName, toRegister));
}
Also used : Function(org.apache.geode.cache.execute.Function) TestFunction(org.apache.geode.internal.cache.functions.TestFunction) TestFunction(org.apache.geode.internal.cache.functions.TestFunction) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest) FlakyTest(org.apache.geode.test.junit.categories.FlakyTest) ClientServerTest(org.apache.geode.test.junit.categories.ClientServerTest) Test(org.junit.Test)

Aggregations

Function (org.apache.geode.cache.execute.Function)261 TestFunction (org.apache.geode.internal.cache.functions.TestFunction)204 Test (org.junit.Test)156 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)148 HashSet (java.util.HashSet)124 FunctionException (org.apache.geode.cache.execute.FunctionException)122 PartitionedRegion (org.apache.geode.internal.cache.PartitionedRegion)122 Execution (org.apache.geode.cache.execute.Execution)121 ArrayList (java.util.ArrayList)110 ResultCollector (org.apache.geode.cache.execute.ResultCollector)110 List (java.util.List)86 Region (org.apache.geode.cache.Region)83 IgnoredException (org.apache.geode.test.dunit.IgnoredException)75 FlakyTest (org.apache.geode.test.junit.categories.FlakyTest)74 Iterator (java.util.Iterator)68 ClientServerTest (org.apache.geode.test.junit.categories.ClientServerTest)67 SerializableCallable (org.apache.geode.test.dunit.SerializableCallable)63 VM (org.apache.geode.test.dunit.VM)62 Host (org.apache.geode.test.dunit.Host)61 AttributesFactory (org.apache.geode.cache.AttributesFactory)56