Search in sources :

Example 56 with Function

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

the class PRClientServerRegionFunctionExecutionSelectorNoSingleHopDUnitTest method testServerSingleKeyExecution_SocketTimeOut.

@Test
public void testServerSingleKeyExecution_SocketTimeOut() {
    createScenario();
    Function function = new TestFunction(true, TestFunction.TEST_FUNCTION_SOCKET_TIMEOUT);
    registerFunctionAtServer(function);
    isByName = new Boolean(true);
    client.invoke(() -> PRClientServerRegionFunctionExecutionSelectorNoSingleHopDUnitTest.serverSingleKeyExecutionSocketTimeOut(isByName));
}
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) FlakyTest(org.apache.geode.test.junit.categories.FlakyTest) ClientServerTest(org.apache.geode.test.junit.categories.ClientServerTest) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Example 57 with Function

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

Example 58 with Function

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

the class PRClientServerRegionFunctionExecutionSelectorNoSingleHopDUnitTest method serverMultiKeyExecution.

public static void serverMultiKeyExecution(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);
        }
        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(); ) {
            assertEquals(Boolean.TRUE, i.next());
        }
        List l2 = null;
        ResultCollector rc2 = execute(dataSet, testKeysSet, 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 : 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) ArrayList(java.util.ArrayList) 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) 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)

Example 59 with Function

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

the class PRClientServerRegionFunctionExecutionSelectorNoSingleHopDUnitTest method serverMultiKeyExecutionSocketTimeOut.

public static void serverMultiKeyExecutionSocketTimeOut(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_SOCKET_TIMEOUT);
    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);
        }
        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(); ) {
            assertEquals(Boolean.TRUE, i.next());
        }
    } catch (Exception e) {
        Assert.fail("Test failed after the function execution", e);
    }
}
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) 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) 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)

Example 60 with Function

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

the class PRClientServerRegionFunctionExecutionSingleHopDUnitTest method testServerSingleKeyExecution_byInstance.

/*
   * Execution of the function on server with single key as the routing object and using the
   * instance of the function
   */
@Test
public void testServerSingleKeyExecution_byInstance() {
    createScenario();
    Function function = new TestFunction(true, TEST_FUNCTION2);
    registerFunctionAtServer(function);
    isByName = new Boolean(false);
    client.invoke(() -> PRClientServerRegionFunctionExecutionSingleHopDUnitTest.serverSingleKeyExecution(isByName));
}
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) ClientServerTest(org.apache.geode.test.junit.categories.ClientServerTest) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

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