Search in sources :

Example 1 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 2 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 3 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 4 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)

Example 5 with TestFunction

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

the class PRFunctionExecutionDUnitTest method testRemoteMultiKeyExecution_BucketMoved.

@Test
public void testRemoteMultiKeyExecution_BucketMoved() throws Exception {
    final String rName = getUniqueName();
    Host host = Host.getHost(0);
    final VM accessor = host.getVM(3);
    final VM datastore0 = host.getVM(0);
    final VM datastore1 = host.getVM(1);
    final VM datastore2 = host.getVM(2);
    getCache();
    accessor.invoke(new SerializableCallable("Create PR") {

        public Object call() throws Exception {
            AttributesFactory factory = new AttributesFactory();
            PartitionAttributesFactory paf = new PartitionAttributesFactory();
            paf.setTotalNumBuckets(113);
            paf.setLocalMaxMemory(0);
            paf.setRedundantCopies(1);
            paf.setStartupRecoveryDelay(0);
            PartitionAttributes partitionAttributes = paf.create();
            factory.setDataPolicy(DataPolicy.PARTITION);
            factory.setPartitionAttributes(partitionAttributes);
            RegionAttributes attrs = factory.create();
            getCache().createRegion(rName, attrs);
            return Boolean.TRUE;
        }
    });
    SerializableCallable dataStoreCreate = new SerializableCallable("Create PR with Function Factory") {

        public Object call() throws Exception {
            AttributesFactory factory = new AttributesFactory();
            PartitionAttributesFactory paf = new PartitionAttributesFactory();
            paf.setTotalNumBuckets(113);
            paf.setLocalMaxMemory(40);
            paf.setRedundantCopies(1);
            paf.setStartupRecoveryDelay(0);
            PartitionAttributes partitionAttributes = paf.create();
            factory.setDataPolicy(DataPolicy.PARTITION);
            factory.setPartitionAttributes(partitionAttributes);
            RegionAttributes attrs = factory.create();
            getCache().createRegion(rName, attrs);
            Function function = new TestFunction(true, TestFunction.TEST_FUNCTION_LASTRESULT);
            FunctionService.registerFunction(function);
            return Boolean.TRUE;
        }
    };
    datastore0.invoke(dataStoreCreate);
    datastore1.invoke(dataStoreCreate);
    SerializableCallable put = new SerializableCallable("put in PR") {

        public Object call() throws Exception {
            PartitionedRegion pr = (PartitionedRegion) getCache().getRegion(rName);
            for (int i = 0; i < 113; i++) {
                pr.put(i, "execKey-" + i);
            }
            return Boolean.TRUE;
        }
    };
    accessor.invoke(put);
    datastore2.invoke(dataStoreCreate);
    Object result = accessor.invoke(new SerializableCallable("invoke exectuable") {

        public Object call() throws Exception {
            PartitionedRegion pr = (PartitionedRegion) getCache().getRegion(rName);
            DistributedSystem.setThreadsSocketPolicy(false);
            Function function = new TestFunction(true, TestFunction.TEST_FUNCTION_LASTRESULT);
            FunctionService.registerFunction(function);
            Execution dataSet = FunctionService.onRegion(pr);
            ResultCollector rc2 = dataSet.setArguments(Boolean.TRUE).execute(function.getId());
            List l = ((List) rc2.getResult());
            return l;
        }
    });
    List l = (List) result;
    assertEquals(2, l.size());
}
Also used : TestFunction(org.apache.geode.internal.cache.functions.TestFunction) RegionAttributes(org.apache.geode.cache.RegionAttributes) PartitionAttributes(org.apache.geode.cache.PartitionAttributes) 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) PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) AttributesFactory(org.apache.geode.cache.AttributesFactory) PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) 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) 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