You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@geode.apache.org by up...@apache.org on 2016/05/06 00:23:54 UTC
[1/2] incubator-geode git commit: GEODE-625: Adding tests for
exception handling of functions
Repository: incubator-geode
Updated Branches:
refs/heads/develop 8fcd9c0e6 -> aca7b288f
GEODE-625: Adding tests for exception handling of functions
Testing how functions propagate exceptions from within the function to
the caller or the result collector.
Project: http://git-wip-us.apache.org/repos/asf/incubator-geode/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-geode/commit/aca7b288
Tree: http://git-wip-us.apache.org/repos/asf/incubator-geode/tree/aca7b288
Diff: http://git-wip-us.apache.org/repos/asf/incubator-geode/diff/aca7b288
Branch: refs/heads/develop
Commit: aca7b288f378ec05e00ec3a9277265d1a9679b4a
Parents: 15a2a29
Author: Dan Smith <up...@apache.org>
Authored: Thu Apr 28 14:13:36 2016 -0700
Committer: Dan Smith <up...@apache.org>
Committed: Thu May 5 17:17:01 2016 -0700
----------------------------------------------------------------------
.../cache/execute/FunctionServiceBase.java | 287 +++++++++++++++++++
.../FunctionServiceLocalPRDUnitTest.java | 54 ++++
.../FunctionServiceLocalRRDUnitTest.java | 52 ++++
...unctionServiceMultipleOnMemberDUnitTest.java | 57 ++++
.../FunctionServicePeerAccessorPRDUnitTest.java | 73 +++++
.../FunctionServicePeerAccessorRRDUnitTest.java | 63 ++++
.../FunctionServiceSingleOnMemberDUnitTest.java | 49 ++++
7 files changed, 635 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/aca7b288/geode-core/src/test/java/com/gemstone/gemfire/internal/cache/execute/FunctionServiceBase.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/internal/cache/execute/FunctionServiceBase.java b/geode-core/src/test/java/com/gemstone/gemfire/internal/cache/execute/FunctionServiceBase.java
new file mode 100644
index 0000000..eeb7d8d
--- /dev/null
+++ b/geode-core/src/test/java/com/gemstone/gemfire/internal/cache/execute/FunctionServiceBase.java
@@ -0,0 +1,287 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.gemstone.gemfire.internal.cache.execute;
+
+import static org.hamcrest.Matchers.isA;
+import static org.hamcrest.core.Is.is;
+import static org.junit.Assert.*;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.concurrent.TimeUnit;
+import java.util.stream.Stream;
+
+import com.gemstone.gemfire.cache.execute.Execution;
+import com.gemstone.gemfire.cache.execute.FunctionException;
+import com.gemstone.gemfire.cache.execute.ResultCollector;
+import com.gemstone.gemfire.distributed.DistributedMember;
+import com.gemstone.gemfire.test.dunit.Host;
+import com.gemstone.gemfire.test.dunit.cache.internal.JUnit4CacheTestCase;
+import com.gemstone.gemfire.test.dunit.internal.JUnit4DistributedTestCase;
+
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+
+/*
+ * Base class for tests of FunctionService that are agnostic to the
+ * type of Execution that they are running on. The goal is to completely
+ * cover all common behavior of sending results and sending exceptions
+ * here.
+ */
+public abstract class FunctionServiceBase extends JUnit4CacheTestCase {
+
+ @Rule
+ public transient ExpectedException thrown = ExpectedException.none();
+
+ private transient CustomCollector customCollector;
+
+ @Before
+ public void createCollector() {
+ this.customCollector = new CustomCollector();
+ }
+
+ /**
+ * Return the execution used to execute functions for this
+ * test. Subclasses should override this to provide a specific
+ * execution, for example onMember.
+ */
+ public abstract Execution getExecution();
+
+ /**
+ * Return the number of members the function is expected
+ * to execute on
+ */
+ public abstract int numberOfExecutions();
+
+ @Test
+ public void defaultCollectorReturnsSingleResult() {
+ final Host host = Host.getHost(0);
+
+ ResultCollector rc = getExecution().execute((context) -> {context.getResultSender().lastResult("done");});
+ List<String> results = (List<String>) rc.getResult();
+ assertEquals(numberOfExecutions(), results.size());
+ results.stream().forEach(element -> assertEquals("done", element));
+ }
+
+ @Test()
+ public void defaultCollectorThrowsExceptionAfterFunctionThrowsIllegalState() {
+ final Host host = Host.getHost(0);
+
+ ResultCollector rc = getExecution().execute((context) -> {throw new IllegalStateException();});
+ thrown.expect(FunctionException.class);
+ thrown.expectCause(isA(IllegalStateException.class));
+ final Object result = rc.getResult();
+ }
+
+ @Test()
+ public void defaultCollectorThrowsExceptionAfterFunctionThrowsFunctionException() {
+ final Host host = Host.getHost(0);
+
+ ResultCollector rc = getExecution().execute((context) -> {throw new FunctionException();});
+
+ thrown.expect(FunctionException.class);
+ final Object result = rc.getResult();
+ }
+
+ /**
+ * Tests what happens if a function returns an exception as a result. This
+ * is kind a weird, but it seems that the default collector will just throw it
+ * as an exception
+ */
+ @Test()
+ public void defaultCollectorThrowsExceptionAfterFunctionReturnsIllegalStateException() {
+ final Host host = Host.getHost(0);
+
+ ResultCollector rc = getExecution().execute((context) -> {context.getResultSender().lastResult(new IllegalStateException());});
+
+ thrown.expect(FunctionException.class);
+ thrown.expectCause(isA(IllegalStateException.class));
+ final Object result = rc.getResult();
+ }
+
+ @Test()
+ public void defaultCollectorThrowsExceptionAfterFunctionReturnsFunctionException() {
+ final Host host = Host.getHost(0);
+
+ ResultCollector rc = getExecution().execute((context) -> {context.getResultSender().lastResult(new FunctionException());});
+ thrown.expect(FunctionException.class);
+ thrown.expectCause(is((Throwable) null));
+ final Object result = rc.getResult();
+ }
+
+ @Test()
+ public void defaultCollectorThrowsExceptionAfterFunctionReturnsIllegalStateExceptionAsIntermediateResult() {
+ final Host host = Host.getHost(0);
+
+ ResultCollector rc = getExecution().execute((context) -> {
+ context.getResultSender().sendResult(new IllegalStateException());
+ context.getResultSender().lastResult("done");
+ });
+ thrown.expect(FunctionException.class);
+ thrown.expectCause(isA(IllegalStateException.class));
+ final Object result = rc.getResult();
+ }
+
+ @Test()
+ public void defaultCollectorThrowsExceptionAfterFunctionReturnsFunctionExceptionAsIntermediateResult() {
+ final Host host = Host.getHost(0);
+
+ ResultCollector rc = getExecution().execute((context) -> {
+ context.getResultSender().sendResult(new FunctionException());
+ context.getResultSender().lastResult("done");
+ });
+ thrown.expect(FunctionException.class);
+ thrown.expectCause(is((Throwable) null));
+ final Object result = rc.getResult();
+ }
+
+ @Test
+ public void defaultCollectorReturnsResultOfSendException() {
+ final Host host = Host.getHost(0);
+
+ ResultCollector rc = getExecution().execute((context) -> {
+ context.getResultSender().sendException(new IllegalStateException());
+ });
+ final List<Object> result = (List<Object>) rc.getResult();
+ assertEquals(numberOfExecutions(), result.size());
+ result.stream().forEach(element -> assertEquals(IllegalStateException.class, element.getClass()));
+ }
+
+ @Test
+ public void defaultCollectorReturnsResultOfSendFunctionException() {
+ final Host host = Host.getHost(0);
+
+ ResultCollector rc = getExecution().execute((context) -> {
+ context.getResultSender().sendException(new FunctionException());
+ });
+ final List<Object> result = (List<Object>) rc.getResult();
+ assertEquals(numberOfExecutions(), result.size());
+ result.stream().forEach(element -> assertEquals(FunctionException.class, element.getClass()));
+ }
+
+ @Test
+ public void customCollectorDoesNotSeeExceptionFunctionThrowsIllegalState() {
+ final Host host = Host.getHost(0);
+
+ ResultCollector rc = getExecution().withCollector(customCollector).execute((context) -> {throw new IllegalStateException();});
+ try {
+ rc.getResult();
+ fail("should have received an exception");
+ } catch (FunctionException expected) {}
+
+ Assert.assertEquals(0, customCollector.getResult().size());
+ }
+
+ @Test
+ public void customCollectorDoesNotSeeExceptionFunctionThrowsFunctionException() {
+ final Host host = Host.getHost(0);
+
+ ResultCollector rc = getExecution().withCollector(customCollector).execute((context) -> {throw new FunctionException();});
+ try {
+ rc.getResult();
+ fail("should have received an exception");
+ } catch (FunctionException expected) {}
+
+ Assert.assertEquals(0, customCollector.getResult().size());
+ }
+
+ @Test
+ public void customCollectorDoesNotSeeExceptionAfterFunctionReturnsIllegalStateException() {
+ final Host host = Host.getHost(0);
+
+ ResultCollector rc = getExecution().execute((context) -> {context.getResultSender().lastResult(new IllegalStateException());});
+ try {
+ rc.getResult();
+ fail("should have received an exception");
+ } catch (FunctionException expected) {}
+ Assert.assertEquals(0, customCollector.getResult().size());
+ }
+
+ @Test
+ public void customCollectorDoesNotSeeExceptionAfterFunctionReturnsIllegalStateExceptionAsIntermediateResult() {
+ final Host host = Host.getHost(0);
+
+ ResultCollector rc = getExecution().execute((context) -> {
+ context.getResultSender().sendResult(new IllegalStateException());
+ context.getResultSender().lastResult("done");
+ });
+ try {
+ rc.getResult();
+ fail("should have received an exception");
+ } catch (FunctionException expected) {}
+ Assert.assertEquals(0, customCollector.getResult().size());
+ }
+
+ @Test
+ public void customCollectorReturnsResultOfSendException() {
+ final Host host = Host.getHost(0);
+
+ ResultCollector rc = getExecution().withCollector(customCollector).execute((context) -> {
+ context.getResultSender().sendException(new IllegalStateException());
+ });
+ final List<Object> result = (List<Object>) rc.getResult();
+ assertEquals(numberOfExecutions(), result.size());
+ result.stream().forEach(element -> assertEquals(IllegalStateException.class, element.getClass()));
+ assertEquals(result, customCollector.getResult());
+ }
+
+ @Test
+ public void customCollectorReturnsResultOfSendFunctionException() {
+ final Host host = Host.getHost(0);
+
+ ResultCollector rc = getExecution().withCollector(customCollector).execute((context) -> {
+ context.getResultSender().sendException(new FunctionException());
+ });
+ final List<Object> result = (List<Object>) rc.getResult();
+ assertEquals(numberOfExecutions(), result.size());
+ result.stream().forEach(element -> assertEquals(FunctionException.class, element.getClass()));
+ assertEquals(result, customCollector.getResult());
+ }
+
+ private static class CustomCollector implements ResultCollector<Object, List<Object>> {
+ private ArrayList<Object> results = new ArrayList<Object>();
+
+ @Override
+ public List<Object> getResult() throws FunctionException {
+ return results;
+ }
+
+ @Override
+ public List<Object> getResult(final long timeout, final TimeUnit unit)
+ throws FunctionException, InterruptedException
+ {
+ return results;
+ }
+
+ @Override
+ public void addResult(final DistributedMember memberID, final Object resultOfSingleExecution) {
+ results.add(resultOfSingleExecution);
+ }
+
+ @Override
+ public void endResults() {
+ }
+
+ @Override
+ public void clearResults() {
+ results.clear();
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/aca7b288/geode-core/src/test/java/com/gemstone/gemfire/internal/cache/execute/FunctionServiceLocalPRDUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/internal/cache/execute/FunctionServiceLocalPRDUnitTest.java b/geode-core/src/test/java/com/gemstone/gemfire/internal/cache/execute/FunctionServiceLocalPRDUnitTest.java
new file mode 100644
index 0000000..5617ee6
--- /dev/null
+++ b/geode-core/src/test/java/com/gemstone/gemfire/internal/cache/execute/FunctionServiceLocalPRDUnitTest.java
@@ -0,0 +1,54 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.gemstone.gemfire.internal.cache.execute;
+
+import com.gemstone.gemfire.cache.Region;
+import com.gemstone.gemfire.cache.RegionShortcut;
+import com.gemstone.gemfire.cache.execute.Execution;
+import com.gemstone.gemfire.cache.execute.FunctionService;
+import com.gemstone.gemfire.cache.partition.PartitionRegionHelper;
+import com.gemstone.gemfire.test.junit.categories.DistributedTest;
+
+import org.junit.Before;
+import org.junit.experimental.categories.Category;
+
+/**
+ * Test of the behavior of a custom ResultCollector when handling exceptions
+ */
+@Category(DistributedTest.class)
+public class FunctionServiceLocalPRDUnitTest extends FunctionServiceBase {
+
+ public static final String REGION = "region";
+
+ private transient Region<Object, Object> region;
+
+ @Before
+ public void createRegions() {
+ region = getCache().createRegionFactory(RegionShortcut.PARTITION)
+ .create(REGION);
+ PartitionRegionHelper.assignBucketsToPartitions(region);
+ }
+
+ @Override public Execution getExecution() {
+ return FunctionService.onRegion(region);
+ }
+
+ @Override public int numberOfExecutions() {
+ return 1;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/aca7b288/geode-core/src/test/java/com/gemstone/gemfire/internal/cache/execute/FunctionServiceLocalRRDUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/internal/cache/execute/FunctionServiceLocalRRDUnitTest.java b/geode-core/src/test/java/com/gemstone/gemfire/internal/cache/execute/FunctionServiceLocalRRDUnitTest.java
new file mode 100644
index 0000000..085e709
--- /dev/null
+++ b/geode-core/src/test/java/com/gemstone/gemfire/internal/cache/execute/FunctionServiceLocalRRDUnitTest.java
@@ -0,0 +1,52 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.gemstone.gemfire.internal.cache.execute;
+
+import com.gemstone.gemfire.cache.Region;
+import com.gemstone.gemfire.cache.RegionShortcut;
+import com.gemstone.gemfire.cache.execute.Execution;
+import com.gemstone.gemfire.cache.execute.FunctionService;
+import com.gemstone.gemfire.test.junit.categories.DistributedTest;
+
+import org.junit.Before;
+import org.junit.experimental.categories.Category;
+
+/**
+ * Test of the behavior of a custom ResultCollector when handling exceptions
+ */
+@Category(DistributedTest.class)
+public class FunctionServiceLocalRRDUnitTest extends FunctionServiceBase {
+
+ public static final String REGION = "region";
+
+ private transient Region<Object, Object> region;
+
+ @Before
+ public void createRegions() {
+ region = getCache().createRegionFactory(RegionShortcut.REPLICATE)
+ .create(REGION);
+ }
+
+ @Override public Execution getExecution() {
+ return FunctionService.onRegion(region);
+ }
+
+ @Override public int numberOfExecutions() {
+ return 1;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/aca7b288/geode-core/src/test/java/com/gemstone/gemfire/internal/cache/execute/FunctionServiceMultipleOnMemberDUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/internal/cache/execute/FunctionServiceMultipleOnMemberDUnitTest.java b/geode-core/src/test/java/com/gemstone/gemfire/internal/cache/execute/FunctionServiceMultipleOnMemberDUnitTest.java
new file mode 100644
index 0000000..cc67830
--- /dev/null
+++ b/geode-core/src/test/java/com/gemstone/gemfire/internal/cache/execute/FunctionServiceMultipleOnMemberDUnitTest.java
@@ -0,0 +1,57 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.gemstone.gemfire.internal.cache.execute;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import com.gemstone.gemfire.cache.execute.Execution;
+import com.gemstone.gemfire.cache.execute.FunctionService;
+import com.gemstone.gemfire.distributed.DistributedMember;
+import com.gemstone.gemfire.test.dunit.Host;
+import com.gemstone.gemfire.test.dunit.VM;
+import com.gemstone.gemfire.test.junit.categories.DistributedTest;
+
+import org.junit.Before;
+import org.junit.experimental.categories.Category;
+
+/**
+ * Test of the behavior of a custom ResultCollector when handling exceptions
+ */
+@Category(DistributedTest.class)
+public class FunctionServiceMultipleOnMemberDUnitTest extends FunctionServiceBase {
+
+ private Set<DistributedMember> members = new HashSet<DistributedMember>();
+
+ @Before
+ public void createDistributedSystems() {
+ getSystem();
+ Host host = Host.getHost(0);
+ VM vm0 = host.getVM(0);
+ VM vm1 = host.getVM(1);
+ members.add(vm0.invoke(() -> getSystem().getDistributedMember()));
+ members.add(vm1.invoke(() -> getSystem().getDistributedMember()));
+ }
+
+ @Override public Execution getExecution() {
+ return FunctionService.onMembers(members);
+ }
+
+ @Override public int numberOfExecutions() {
+ return 2;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/aca7b288/geode-core/src/test/java/com/gemstone/gemfire/internal/cache/execute/FunctionServicePeerAccessorPRDUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/internal/cache/execute/FunctionServicePeerAccessorPRDUnitTest.java b/geode-core/src/test/java/com/gemstone/gemfire/internal/cache/execute/FunctionServicePeerAccessorPRDUnitTest.java
new file mode 100644
index 0000000..e5bf2d2
--- /dev/null
+++ b/geode-core/src/test/java/com/gemstone/gemfire/internal/cache/execute/FunctionServicePeerAccessorPRDUnitTest.java
@@ -0,0 +1,73 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.gemstone.gemfire.internal.cache.execute;
+
+import com.gemstone.gemfire.cache.Region;
+import com.gemstone.gemfire.cache.RegionShortcut;
+import com.gemstone.gemfire.cache.execute.Execution;
+import com.gemstone.gemfire.cache.execute.FunctionService;
+import com.gemstone.gemfire.cache.partition.PartitionRegionHelper;
+import com.gemstone.gemfire.test.dunit.Host;
+import com.gemstone.gemfire.test.dunit.VM;
+import com.gemstone.gemfire.test.junit.categories.DistributedTest;
+
+import org.junit.Before;
+import org.junit.Ignore;
+import org.junit.experimental.categories.Category;
+
+/**
+ * Test of the behavior of a custom ResultCollector when handling exceptions
+ */
+@Category(DistributedTest.class)
+public class FunctionServicePeerAccessorPRDUnitTest extends FunctionServiceBase {
+
+ public static final String REGION = "region";
+
+ private transient Region<Object, Object> region;
+
+ @Before
+ public void createRegions() {
+ region = getCache().createRegionFactory(RegionShortcut.PARTITION_PROXY)
+ .create(REGION);
+ Host host = Host.getHost(0);
+ VM vm0 = host.getVM(0);
+ vm0.invoke(() -> {
+
+ getCache().createRegionFactory(RegionShortcut.PARTITION)
+ .create(REGION);
+
+ });
+
+ PartitionRegionHelper.assignBucketsToPartitions(region);
+ }
+
+ @Override public Execution getExecution() {
+ return FunctionService.onRegion(region);
+ }
+
+ @Override public int numberOfExecutions() {
+ return 1;
+ }
+
+ @Ignore("GEODE-1348 - With this topology, the exception is not wrapped in FunctionException")
+ @Override public void defaultCollectorThrowsExceptionAfterFunctionThrowsIllegalState() {
+ }
+
+ @Ignore("GEODE-1348 - With this topology, the exception is not wrapped in FunctionException")
+ @Override public void customCollectorDoesNotSeeExceptionFunctionThrowsIllegalState() {
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/aca7b288/geode-core/src/test/java/com/gemstone/gemfire/internal/cache/execute/FunctionServicePeerAccessorRRDUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/internal/cache/execute/FunctionServicePeerAccessorRRDUnitTest.java b/geode-core/src/test/java/com/gemstone/gemfire/internal/cache/execute/FunctionServicePeerAccessorRRDUnitTest.java
new file mode 100644
index 0000000..439e04f
--- /dev/null
+++ b/geode-core/src/test/java/com/gemstone/gemfire/internal/cache/execute/FunctionServicePeerAccessorRRDUnitTest.java
@@ -0,0 +1,63 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.gemstone.gemfire.internal.cache.execute;
+
+import com.gemstone.gemfire.cache.Region;
+import com.gemstone.gemfire.cache.RegionShortcut;
+import com.gemstone.gemfire.cache.execute.Execution;
+import com.gemstone.gemfire.cache.execute.FunctionService;
+import com.gemstone.gemfire.test.dunit.Host;
+import com.gemstone.gemfire.test.dunit.VM;
+import com.gemstone.gemfire.test.junit.categories.DistributedTest;
+
+import org.junit.Before;
+import org.junit.experimental.categories.Category;
+
+/**
+ * Test of the behavior of a custom ResultCollector when handling exceptions
+ */
+@Category(DistributedTest.class)
+public class FunctionServicePeerAccessorRRDUnitTest extends FunctionServiceBase {
+
+ public static final String REGION = "region";
+
+ private transient Region<Object, Object> region;
+
+ @Before
+ public void createRegions() {
+ region = getCache().createRegionFactory(RegionShortcut.REPLICATE_PROXY)
+ .create(REGION);
+ Host host = Host.getHost(0);
+ VM vm0 = host.getVM(0);
+ vm0.invoke(() -> {
+
+ getCache().createRegionFactory(RegionShortcut.REPLICATE)
+ .create(REGION);
+
+ });
+ }
+
+ @Override public Execution getExecution() {
+ return FunctionService.onRegion(region);
+ }
+
+ @Override public int numberOfExecutions() {
+ return 1;
+ }
+
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/aca7b288/geode-core/src/test/java/com/gemstone/gemfire/internal/cache/execute/FunctionServiceSingleOnMemberDUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/internal/cache/execute/FunctionServiceSingleOnMemberDUnitTest.java b/geode-core/src/test/java/com/gemstone/gemfire/internal/cache/execute/FunctionServiceSingleOnMemberDUnitTest.java
new file mode 100644
index 0000000..29dd3ee
--- /dev/null
+++ b/geode-core/src/test/java/com/gemstone/gemfire/internal/cache/execute/FunctionServiceSingleOnMemberDUnitTest.java
@@ -0,0 +1,49 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.gemstone.gemfire.internal.cache.execute;
+
+import com.gemstone.gemfire.cache.execute.Execution;
+import com.gemstone.gemfire.cache.execute.FunctionService;
+import com.gemstone.gemfire.distributed.internal.membership.InternalDistributedMember;
+import com.gemstone.gemfire.test.junit.categories.DistributedTest;
+
+import org.junit.Before;
+import org.junit.experimental.categories.Category;
+
+/**
+ * Test of the behavior of a custom ResultCollector when handling exceptions
+ */
+@Category(DistributedTest.class)
+public class FunctionServiceSingleOnMemberDUnitTest extends FunctionServiceBase {
+
+ private InternalDistributedMember memberId;
+
+ @Before
+ public void createDistributedSystem() {
+ memberId = getSystem().getDistributedMember();
+ }
+
+ @Override public Execution getExecution() {
+ return FunctionService.onMember(memberId);
+ }
+
+ @Override public int numberOfExecutions() {
+ return 1;
+ }
+
+
+}
[2/2] incubator-geode git commit: GEODE-641: Adding default methods
to the Function interface
Posted by up...@apache.org.
GEODE-641: Adding default methods to the Function interface
Adding default methods to Function so that Function is now a functional
interface and lambda expressions can be used for functions.
Project: http://git-wip-us.apache.org/repos/asf/incubator-geode/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-geode/commit/15a2a29d
Tree: http://git-wip-us.apache.org/repos/asf/incubator-geode/tree/15a2a29d
Diff: http://git-wip-us.apache.org/repos/asf/incubator-geode/diff/15a2a29d
Branch: refs/heads/develop
Commit: 15a2a29d996c60831ec67bb8f565660950e67a29
Parents: 8fcd9c0
Author: Dan Smith <up...@apache.org>
Authored: Wed Apr 27 17:53:18 2016 -0700
Committer: Dan Smith <up...@apache.org>
Committed: Thu May 5 17:17:01 2016 -0700
----------------------------------------------------------------------
.../gemfire/cache/execute/Function.java | 17 +++-
.../gemfire/cache/execute/FunctionAdapter.java | 87 +-------------------
.../cache/execute/FunctionAdapterJUnitTest.java | 65 +++++++++++++++
3 files changed, 80 insertions(+), 89 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/15a2a29d/geode-core/src/main/java/com/gemstone/gemfire/cache/execute/Function.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/com/gemstone/gemfire/cache/execute/Function.java b/geode-core/src/main/java/com/gemstone/gemfire/cache/execute/Function.java
index 553248e..f32fcad 100755
--- a/geode-core/src/main/java/com/gemstone/gemfire/cache/execute/Function.java
+++ b/geode-core/src/main/java/com/gemstone/gemfire/cache/execute/Function.java
@@ -35,6 +35,7 @@ import com.gemstone.gemfire.lang.Identifiable;
*
* @since 6.0
*/
+@FunctionalInterface
public interface Function extends Identifiable<String> {
/**
@@ -53,7 +54,9 @@ public interface Function extends Identifiable<String> {
* @return whether this function returns a Result back to the caller.
* @since 6.0
*/
- public boolean hasResult();
+ public default boolean hasResult() {
+ return true;
+ }
/**
* The method which contains the logic to be executed. This method should be
@@ -75,7 +78,9 @@ public interface Function extends Identifiable<String> {
* @return string identifying this function
* @since 6.0
*/
- public String getId();
+ public default String getId() {
+ return getClass().getCanonicalName();
+ }
/**
* <p>Return true to indicate to GemFire the method
@@ -94,7 +99,9 @@ public interface Function extends Identifiable<String> {
* @since 6.0
* @see FunctionService
*/
- public boolean optimizeForWrite();
+ public default boolean optimizeForWrite() {
+ return false;
+ }
/**
* Specifies whether the function is eligible for re-execution (in case of
@@ -105,6 +112,8 @@ public interface Function extends Identifiable<String> {
*
* @since 6.5
*/
- public boolean isHA();
+ public default boolean isHA() {
+ return true;
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/15a2a29d/geode-core/src/main/java/com/gemstone/gemfire/cache/execute/FunctionAdapter.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/com/gemstone/gemfire/cache/execute/FunctionAdapter.java b/geode-core/src/main/java/com/gemstone/gemfire/cache/execute/FunctionAdapter.java
index c4cfeed..674120c 100755
--- a/geode-core/src/main/java/com/gemstone/gemfire/cache/execute/FunctionAdapter.java
+++ b/geode-core/src/main/java/com/gemstone/gemfire/cache/execute/FunctionAdapter.java
@@ -32,92 +32,9 @@ package com.gemstone.gemfire.cache.execute;
*
* @since 6.0
* @see Function
+ * @deprecated Use {@link Function} instead. Function has default
+ * methods that now mimic the behavior of FunctionAdapter.
*
*/
public abstract class FunctionAdapter implements Function {
- /**
- * The method which contains the logic to be executed. This method should be
- * thread safe and may be invoked more than once on a given member for a
- * single {@link Execution}. The context provided to this function is the one
- * which was built using {@linkplain Execution}. The contexts can be data
- * dependent or data-independent so user should check to see if the context
- * provided in parameter is instance of {@link RegionFunctionContext}.
- *
- * @param context
- * as created by {@link Execution}
- * @since 6.0
- */
- public abstract void execute(FunctionContext context);
-
- /**
- * Return a unique function identifier, used to register the function with
- * {@link FunctionService}
- *
- * @return string identifying this function
- * @since 6.0
- */
- public abstract String getId();
-
- /**
- * Specifies whether the function sends results while executing. The method
- * returns false if no result is expected.<br>
- * <p>
- * If {@link Function#hasResult()} returns false,
- * {@link ResultCollector#getResult()} throws {@link FunctionException}.
- * </p>
- * <p>
- * If {@link Function#hasResult()} returns true,
- * {@link ResultCollector#getResult()} blocks and waits for the result of
- * function execution
- * </p>
- *
- * @return whether this function returns a Result back to the caller.
- * @since 6.0
- */
- public boolean hasResult() {
- return true;
- }
-
- /**
- * <p>
- * Return true to indicate to GemFire the method requires optimization for
- * writing the targeted
- * {@link FunctionService#onRegion(com.gemstone.gemfire.cache.Region)} and any
- * associated {@linkplain Execution#withFilter(java.util.Set) routing objects}
- * .
- * </p>
- *
- * <p>
- * Returning false will optimize for read behavior on the targeted
- * {@link FunctionService#onRegion(com.gemstone.gemfire.cache.Region)} and any
- * associated {@linkplain Execution#withFilter(java.util.Set) routing objects}
- * .
- * </p>
- *
- * <p>
- * This method is only consulted when invoked as a
- * {@linkplain FunctionService#onRegion(com.gemstone.gemfire.cache.Region)
- * data dependent function}
- * </p>
- *
- * @return false if the function is read only, otherwise returns true
- * @since 6.0
- * @see FunctionService
- */
- public boolean optimizeForWrite() {
- return false;
- }
-
- /**
- * Specifies whether the function is eligible for re-execution (in case of
- * failure).
- *
- * @return whether the function is eligible for re-execution.
- * @see RegionFunctionContext#isPossibleDuplicate()
- *
- * @since 6.5
- */
- public boolean isHA() {
- return true;
- }
}
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/15a2a29d/geode-core/src/test/java/com/gemstone/gemfire/cache/execute/FunctionAdapterJUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/cache/execute/FunctionAdapterJUnitTest.java b/geode-core/src/test/java/com/gemstone/gemfire/cache/execute/FunctionAdapterJUnitTest.java
new file mode 100644
index 0000000..6bb5aeb
--- /dev/null
+++ b/geode-core/src/test/java/com/gemstone/gemfire/cache/execute/FunctionAdapterJUnitTest.java
@@ -0,0 +1,65 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.gemstone.gemfire.cache.execute;
+
+import static org.junit.Assert.*;
+
+import com.gemstone.gemfire.test.junit.categories.UnitTest;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+
+@Category(UnitTest.class)
+public class FunctionAdapterJUnitTest {
+
+ private FunctionAdapter adapter;
+
+ @Before
+ public void createDefaultAdapter() {
+ adapter = new MyFunctionAdapter();
+ }
+
+ @Test
+ public void optimizeForWriteDefaultsFalse() {
+ assertFalse(adapter.optimizeForWrite());
+ }
+
+ @Test
+ public void idDefaultsToClassName() {
+ assertEquals(MyFunctionAdapter.class.getCanonicalName(), adapter.getId());
+ }
+
+ @Test
+ public void hasResultDefaultsTrue() {
+ assertTrue(adapter.hasResult());
+
+ }
+
+ @Test
+ public void isHADefaultsTrue() {
+ assertTrue(adapter.isHA());
+ }
+
+ private static class MyFunctionAdapter extends FunctionAdapter {
+
+ @Override
+ public void execute(final FunctionContext context) {
+ }
+
+ }
+}