Search in sources :

Example 76 with TestFunction

use of org.apache.geode.internal.cache.functions.TestFunction 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)

Example 77 with TestFunction

use of org.apache.geode.internal.cache.functions.TestFunction in project geode by apache.

the class ClientServerFunctionExecutionDUnitTest method testServerExecution_byName_WithoutRegister.

@Test
public void testServerExecution_byName_WithoutRegister() {
    createScenario();
    // function = new TestFunction1();
    function = new TestFunction(true, TEST_FUNCTION1);
    registerFunctionAtServer(function);
    isByName = new Boolean(true);
    toRegister = new Boolean(false);
    LogWriterUtils.getLogWriter().info("ClientServerFFunctionExecutionDUnitTest#testServerSingleKeyExecution_byName : Starting test");
    client.invoke(() -> ClientServerFunctionExecutionDUnitTest.serverExecution(isByName, function, toRegister));
    client.invoke(() -> ClientServerFunctionExecutionDUnitTest.allServerExecution(isByName, function, toRegister));
}
Also used : 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 78 with TestFunction

use of org.apache.geode.internal.cache.functions.TestFunction in project geode by apache.

the class ClientServerFunctionExecutionDUnitTest method testServerExecution_byName.

/*
   * Execution of the function on server using the name of the function
   */
@Test
public void testServerExecution_byName() {
    createScenario();
    // function = new TestFunction1();
    function = new TestFunction(true, TEST_FUNCTION1);
    registerFunctionAtServer(function);
    isByName = new Boolean(true);
    toRegister = new Boolean(true);
    LogWriterUtils.getLogWriter().info("ClientServerFFunctionExecutionDUnitTest#testServerSingleKeyExecution_byName : Starting test");
    client.invoke(() -> ClientServerFunctionExecutionDUnitTest.serverExecution(isByName, function, toRegister));
    client.invoke(() -> ClientServerFunctionExecutionDUnitTest.allServerExecution(isByName, function, toRegister));
}
Also used : 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 79 with TestFunction

use of org.apache.geode.internal.cache.functions.TestFunction in project geode by apache.

the class ClientServerFunctionExecutionDUnitTest method testOnServerFailoverWithTwoServerDownHA.

@SuppressWarnings("rawtypes")
@Test
public void testOnServerFailoverWithTwoServerDownHA() throws InterruptedException {
    // The test code appears to trigger this because the first
    // call to the function disconnects from the DS but does not call
    // last result;
    IgnoredException.addIgnoredException("Socket Closed");
    IgnoredException.addIgnoredException("did not send last result");
    createScenario();
    server1.invoke(() -> ClientServerFunctionExecutionDUnitTest.createReplicatedRegion());
    server2.invoke(() -> ClientServerFunctionExecutionDUnitTest.createReplicatedRegion());
    server3.invoke(() -> ClientServerFunctionExecutionDUnitTest.createReplicatedRegion());
    client.invoke(() -> ClientServerFunctionExecutionDUnitTest.createProxyRegion(NetworkUtils.getServerHostName(server1.getHost())));
    function = new TestFunction(true, TestFunction.TEST_FUNCTION_HA_SERVER);
    registerFunctionAtServer(function);
    client.invoke(() -> ClientServerFunctionExecutionDUnitTest.serverExecutionHATwoServerDown(Boolean.FALSE, function, Boolean.FALSE));
    client.invoke(() -> ClientServerFunctionExecutionDUnitTest.verifyMetaData(new Integer(2), new Integer(0)));
}
Also used : 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 80 with TestFunction

use of org.apache.geode.internal.cache.functions.TestFunction in project geode by apache.

the class PRFunctionExecutionDUnitTest method testRemoteSingleKeyExecution_byName_FunctionInvocationTargetException.

/**
   * Test remote execution by a pure accessor which doesn't have the function factory
   * present.Function throws the FunctionInvocationTargetException. As this is the case of HA then
   * system should retry the function execution. After 5th attempt function will send Boolean as
   * last result.
   */
@Test
public void testRemoteSingleKeyExecution_byName_FunctionInvocationTargetException() throws Exception {
    final String rName = getUniqueName();
    Host host = Host.getHost(0);
    final VM accessor = host.getVM(2);
    final VM datastore = host.getVM(3);
    getCache();
    accessor.invoke(new SerializableCallable("Create PR") {

        public Object call() throws Exception {
            RegionAttributes ra = PartitionedRegionTestHelper.createRegionAttrsForPR(0, 0);
            getCache().createRegion(rName, ra);
            return Boolean.TRUE;
        }
    });
    datastore.invoke(new SerializableCallable("Create PR with Function Factory") {

        public Object call() throws Exception {
            RegionAttributes ra = PartitionedRegionTestHelper.createRegionAttrsForPR(0, 10);
            AttributesFactory raf = new AttributesFactory(ra);
            PartitionAttributesImpl pa = new PartitionAttributesImpl();
            pa.setAll(ra.getPartitionAttributes());
            raf.setPartitionAttributes(pa);
            getCache().createRegion(rName, raf.create());
            Function function = new TestFunction(true, TestFunction.TEST_FUNCTION_REEXECUTE_EXCEPTION);
            FunctionService.registerFunction(function);
            return Boolean.TRUE;
        }
    });
    accessor.invoke(new SerializableCallable("Create data, invoke exectuable") {

        public Object call() throws Exception {
            PartitionedRegion pr = (PartitionedRegion) getCache().getRegion(rName);
            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(pr);
            pr.put(testKey, new Integer(1));
            try {
                ResultCollector rs1 = dataSet.withFilter(testKeysSet).setArguments(Boolean.TRUE).execute(function.getId());
                List list = (ArrayList) rs1.getResult();
                assertEquals(list.get(0), 5);
            } catch (Throwable e) {
                e.printStackTrace();
                Assert.fail("This is not expected Exception", e);
            }
            return Boolean.TRUE;
        }
    });
}
Also used : LocalDataSet(org.apache.geode.internal.cache.LocalDataSet) Set(java.util.Set) HashSet(java.util.HashSet) TestFunction(org.apache.geode.internal.cache.functions.TestFunction) RegionAttributes(org.apache.geode.cache.RegionAttributes) Host(org.apache.geode.test.dunit.Host) IgnoredException(org.apache.geode.test.dunit.IgnoredException) FunctionException(org.apache.geode.cache.execute.FunctionException) Function(org.apache.geode.cache.execute.Function) TestFunction(org.apache.geode.internal.cache.functions.TestFunction) AttributesFactory(org.apache.geode.cache.AttributesFactory) PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) PartitionAttributesImpl(org.apache.geode.internal.cache.PartitionAttributesImpl) Execution(org.apache.geode.cache.execute.Execution) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) VM(org.apache.geode.test.dunit.VM) SerializableCallable(org.apache.geode.test.dunit.SerializableCallable) List(java.util.List) ArrayList(java.util.ArrayList) ResultCollector(org.apache.geode.cache.execute.ResultCollector) HashSet(java.util.HashSet) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest) Test(org.junit.Test)

Aggregations

TestFunction (org.apache.geode.internal.cache.functions.TestFunction)214 Function (org.apache.geode.cache.execute.Function)198 Test (org.junit.Test)151 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)150 HashSet (java.util.HashSet)112 Execution (org.apache.geode.cache.execute.Execution)106 ResultCollector (org.apache.geode.cache.execute.ResultCollector)104 PartitionedRegion (org.apache.geode.internal.cache.PartitionedRegion)104 ArrayList (java.util.ArrayList)96 FunctionException (org.apache.geode.cache.execute.FunctionException)89 List (java.util.List)81 ClientServerTest (org.apache.geode.test.junit.categories.ClientServerTest)79 IgnoredException (org.apache.geode.test.dunit.IgnoredException)72 FlakyTest (org.apache.geode.test.junit.categories.FlakyTest)72 Iterator (java.util.Iterator)67 Region (org.apache.geode.cache.Region)65 SerializableCallable (org.apache.geode.test.dunit.SerializableCallable)57 AttributesFactory (org.apache.geode.cache.AttributesFactory)55 VM (org.apache.geode.test.dunit.VM)55 Host (org.apache.geode.test.dunit.Host)54