Search in sources :

Example 71 with ResultCollector

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

the class ClientFunctionTimeoutRegressionTest method executeFunction.

private void executeFunction(String mode, Integer timeout) {
    Function function = new TestFunction(mode + timeout);
    FunctionService.registerFunction(function);
    Execution dataSet;
    if ("region".equalsIgnoreCase(mode)) {
        dataSet = FunctionService.onRegion(clientCache.getRegion(REGION_NAME)).setArguments(timeout);
    } else if ("server".equalsIgnoreCase(mode)) {
        dataSet = FunctionService.onServer(clientCache.getDefaultPool()).setArguments(timeout);
    } else {
        dataSet = FunctionService.onServers(clientCache).setArguments(timeout);
    }
    ResultCollector rs = dataSet.execute(function);
    assertThat((Boolean) ((ArrayList) rs.getResult()).get(0)).as("Server did not read client_function_timeout from client.").isTrue();
}
Also used : Function(org.apache.geode.cache.execute.Function) Execution(org.apache.geode.cache.execute.Execution) ArrayList(java.util.ArrayList) ResultCollector(org.apache.geode.cache.execute.ResultCollector)

Example 72 with ResultCollector

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

the class ClientServerFunctionExecutionDUnitTest method allServerExecution_Inline.

public static void allServerExecution_Inline() {
    DistributedSystem.setThreadsSocketPolicy(false);
    Execution member = FunctionService.onServers(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 true;
            }
        });
        List resultList = (List) rs.getResult();
        assertEquals(Boolean.TRUE, resultList.get(0));
        assertEquals(Boolean.TRUE, resultList.get(1));
        assertEquals(Boolean.TRUE, resultList.get(2));
    } catch (Exception ex) {
        ex.printStackTrace();
        LogWriterUtils.getLogWriter().info("Exception : ", ex);
        fail("Test failed after the execute operation asdfasdfa   ");
    }
}
Also used : Execution(org.apache.geode.cache.execute.Execution) FunctionAdapter(org.apache.geode.cache.execute.FunctionAdapter) ArrayList(java.util.ArrayList) List(java.util.List) 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 73 with ResultCollector

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

the class ClientServerFunctionExecutionDUnitTest method allServerExecution_NoLastResult.

public static void allServerExecution_NoLastResult(Boolean isByName, Function function, Boolean toRegister) {
    DistributedSystem.setThreadsSocketPolicy(false);
    if (toRegister.booleanValue()) {
        FunctionService.registerFunction(function);
    } else {
        FunctionService.unregisterFunction(function.getId());
        assertNull(FunctionService.getFunction(function.getId()));
    }
    Execution member = FunctionService.onServers(pool);
    try {
        ResultCollector rs = execute(member, Boolean.TRUE, function, isByName);
        List resultList = (List) rs.getResult();
        fail("Expected FunctionException : Function did not send last result");
    } catch (Exception ex) {
        assertTrue(ex.getMessage().contains("did not send last result"));
    }
}
Also used : Execution(org.apache.geode.cache.execute.Execution) ArrayList(java.util.ArrayList) List(java.util.List) ResultCollector(org.apache.geode.cache.execute.ResultCollector) ServerConnectivityException(org.apache.geode.cache.client.ServerConnectivityException) ServerOperationException(org.apache.geode.cache.client.ServerOperationException) IgnoredException(org.apache.geode.test.dunit.IgnoredException)

Example 74 with ResultCollector

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

the class ClientServerFunctionExecutionDUnitTest method serverFunctionExecution_FunctionInvocationTargetException.

@SuppressWarnings("rawtypes")
public static void serverFunctionExecution_FunctionInvocationTargetException(Boolean isByName, Function function, Boolean toRegister) {
    DistributedSystem.setThreadsSocketPolicy(false);
    if (toRegister.booleanValue()) {
        FunctionService.registerFunction(function);
    }
    Execution member = FunctionService.onServer(pool);
    try {
        ResultCollector rs = execute(member, Boolean.TRUE, function, isByName);
        ArrayList list = (ArrayList) rs.getResult();
        assertTrue("Value of send result of the executed function : " + list.get(0) + "does not match the expected value : " + 1, ((Integer) list.get(0)) == 1);
        assertTrue("Value of last result of the executed function : " + list.get(0) + "is not equal or more than expected value : " + 5, ((Integer) list.get(1)) >= 5);
    } catch (Exception ex) {
        ex.printStackTrace();
        Assert.fail("This is not expected Exception", ex);
    }
}
Also used : Execution(org.apache.geode.cache.execute.Execution) ArrayList(java.util.ArrayList) ResultCollector(org.apache.geode.cache.execute.ResultCollector) ServerConnectivityException(org.apache.geode.cache.client.ServerConnectivityException) ServerOperationException(org.apache.geode.cache.client.ServerOperationException) IgnoredException(org.apache.geode.test.dunit.IgnoredException)

Example 75 with ResultCollector

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

the class ClientServerFunctionExecutionDUnitTest method FunctionExecution_Inline_Bug40714.

public static void FunctionExecution_Inline_Bug40714() {
    DistributedSystem.setThreadsSocketPolicy(false);
    Execution member = FunctionService.onServers(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 "Function";
            }

            public boolean hasResult() {
                return true;
            }
        });
        List resultList = (List) rs.getResult();
        assertEquals(3, resultList.size());
        assertEquals(Boolean.TRUE, resultList.get(0));
        assertEquals(Boolean.TRUE, resultList.get(1));
        assertEquals(Boolean.TRUE, resultList.get(2));
    } catch (Exception ex) {
        ex.printStackTrace();
        LogWriterUtils.getLogWriter().info("Exception : ", ex);
        fail("Test failed after the execute operation.");
    }
}
Also used : Execution(org.apache.geode.cache.execute.Execution) FunctionAdapter(org.apache.geode.cache.execute.FunctionAdapter) ArrayList(java.util.ArrayList) List(java.util.List) 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)

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