Search in sources :

Example 66 with Function

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

the class PRClientServerRegionFunctionExecutionSingleHopDUnitTest method testServerSingleKeyExecution_SocketTimeOut.

@Test
public void testServerSingleKeyExecution_SocketTimeOut() {
    createScenario();
    Function function = new TestFunction(true, TestFunction.TEST_FUNCTION_SOCKET_TIMEOUT);
    registerFunctionAtServer(function);
    isByName = Boolean.TRUE;
    // add expected exception for server going down after wait
    final IgnoredException expectedEx = IgnoredException.addIgnoredException(DistributedSystemDisconnectedException.class.getName(), server1);
    try {
        client.invoke(() -> PRClientServerRegionFunctionExecutionSingleHopDUnitTest.serverSingleKeyExecutionSocketTimeOut(isByName));
    } finally {
        expectedEx.remove();
    }
}
Also used : Function(org.apache.geode.cache.execute.Function) TestFunction(org.apache.geode.internal.cache.functions.TestFunction) DistributedSystemDisconnectedException(org.apache.geode.distributed.DistributedSystemDisconnectedException) TestFunction(org.apache.geode.internal.cache.functions.TestFunction) IgnoredException(org.apache.geode.test.dunit.IgnoredException) ClientServerTest(org.apache.geode.test.junit.categories.ClientServerTest) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Example 67 with Function

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

the class PRClientServerRegionFunctionExecutionSingleHopDUnitTest method testBucketFilter.

/*
   * Execution of the function on server with bucket as filter
   */
@Test
public void testBucketFilter() {
    createScenarioForBucketFilter();
    Function function = new TestFunction(true, TestFunction.TEST_FUNCTION_BUCKET_FILTER);
    registerFunctionAtServer(function);
    Set<Integer> bucketFilterSet = new HashSet<Integer>();
    bucketFilterSet.add(3);
    bucketFilterSet.add(6);
    bucketFilterSet.add(8);
    client.invoke(() -> PRClientServerTestBase.serverBucketFilterExecution(bucketFilterSet));
    bucketFilterSet.clear();
    // Test single filter
    bucketFilterSet.add(7);
    client.invoke(() -> PRClientServerTestBase.serverBucketFilterExecution(bucketFilterSet));
}
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) HashSet(java.util.HashSet) ClientServerTest(org.apache.geode.test.junit.categories.ClientServerTest) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Example 68 with Function

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

the class PRClientServerRegionFunctionExecutionSingleHopDUnitTest method testServerSingleKeyExecution_byName.

/*
   * Execution of the function on server with single key as the routing object and using the name of
   * the function
   */
@Test
public void testServerSingleKeyExecution_byName() {
    createScenario();
    Function function = new TestFunction(true, TEST_FUNCTION2);
    registerFunctionAtServer(function);
    isByName = new Boolean(true);
    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)

Example 69 with Function

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

the class PRClientServerRegionFunctionExecutionSingleHopDUnitTest 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;
        ArrayList resultListForMember = null;
        while (mapIterator.hasNext()) {
            entry = (Map.Entry) mapIterator.next();
            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) DistributedSystemDisconnectedException(org.apache.geode.distributed.DistributedSystemDisconnectedException) 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) 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 70 with Function

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

the class PRClientServerRegionFunctionExecutionSingleHopDUnitTest method testserverMultiKeyExecution_byInstance.

/*
   * Execution of the function on server with set multiple keys as the routing object and using the
   * instance of the function
   */
@Test
public void testserverMultiKeyExecution_byInstance() {
    createScenario();
    Function function = new TestFunction(true, TEST_FUNCTION2);
    registerFunctionAtServer(function);
    isByName = new Boolean(false);
    client.invoke(() -> PRClientServerRegionFunctionExecutionSingleHopDUnitTest.serverMultiKeyExecution(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