You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@geode.apache.org by kl...@apache.org on 2017/10/11 23:41:12 UTC
[geode] branch develop updated: GEODE-3791: add new tests for
CacheListener on PartionedRegion
This is an automated email from the ASF dual-hosted git repository.
klund pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/geode.git
The following commit(s) were added to refs/heads/develop by this push:
new e4cadc3 GEODE-3791: add new tests for CacheListener on PartionedRegion
e4cadc3 is described below
commit e4cadc35e35d22736008e5e13c6aa334f5a94d3d
Author: Kirk Lund <kl...@apache.org>
AuthorDate: Mon Oct 9 13:24:22 2017 -0700
GEODE-3791: add new tests for CacheListener on PartionedRegion
---
.../cache/PRCacheListenerInvocationTest.java | 86 ++++++++++++++++++++++
...istenerWithInterestPolicyAllInvocationTest.java | 70 ++++++++++++++++++
.../ReplicateCacheListenerInvocationTest.java | 26 +++----
3 files changed, 169 insertions(+), 13 deletions(-)
diff --git a/geode-core/src/test/java/org/apache/geode/internal/cache/PRCacheListenerInvocationTest.java b/geode-core/src/test/java/org/apache/geode/internal/cache/PRCacheListenerInvocationTest.java
new file mode 100644
index 0000000..a6318e4
--- /dev/null
+++ b/geode-core/src/test/java/org/apache/geode/internal/cache/PRCacheListenerInvocationTest.java
@@ -0,0 +1,86 @@
+/*
+ * 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 org.apache.geode.internal.cache;
+
+import java.util.Arrays;
+
+import org.junit.experimental.categories.Category;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+import org.junit.runners.Parameterized.Parameter;
+import org.junit.runners.Parameterized.Parameters;
+
+import org.apache.geode.cache.CacheListener;
+import org.apache.geode.cache.DataPolicy;
+import org.apache.geode.cache.PartitionAttributesFactory;
+import org.apache.geode.cache.Region;
+import org.apache.geode.cache.RegionFactory;
+import org.apache.geode.test.junit.categories.DistributedTest;
+
+/**
+ * This class tests event triggering and handling in partitioned regions.
+ *
+ * <p>
+ * Converted from JUnit 3.
+ *
+ * @since GemFire 5.1
+ */
+@Category(DistributedTest.class)
+@RunWith(Parameterized.class)
+@SuppressWarnings("serial")
+public class PRCacheListenerInvocationTest extends ReplicateCacheListenerInvocationTest {
+
+ @Parameters(name = "{index}: redundancy={0}")
+ public static Iterable<Integer> data() {
+ return Arrays.asList(0, 3);
+ }
+
+ @Parameter
+ public int redundancy;
+
+ @Override
+ protected Region<String, Integer> createRegion(final String name,
+ final CacheListener<String, Integer> listener) {
+ PartitionAttributesFactory partitionFactory = new PartitionAttributesFactory();
+ partitionFactory.setRedundantCopies(redundancy);
+
+ RegionFactory<String, Integer> regionFactory = cacheRule.getCache().createRegionFactory();
+ regionFactory.addCacheListener(listener);
+ regionFactory.setDataPolicy(DataPolicy.PARTITION);
+ regionFactory.setPartitionAttributes(partitionFactory.create());
+
+ return regionFactory.create(name);
+ }
+
+ @Override
+ protected int expectedCreates() {
+ return 1;
+ }
+
+ @Override
+ protected int expectedUpdates() {
+ return 1;
+ }
+
+ @Override
+ protected int expectedInvalidates() {
+ return 1;
+ }
+
+ @Override
+ protected int expectedDestroys() {
+ return 1;
+ }
+}
diff --git a/geode-core/src/test/java/org/apache/geode/internal/cache/PRCacheListenerWithInterestPolicyAllInvocationTest.java b/geode-core/src/test/java/org/apache/geode/internal/cache/PRCacheListenerWithInterestPolicyAllInvocationTest.java
new file mode 100644
index 0000000..79cc825
--- /dev/null
+++ b/geode-core/src/test/java/org/apache/geode/internal/cache/PRCacheListenerWithInterestPolicyAllInvocationTest.java
@@ -0,0 +1,70 @@
+/*
+ * 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 org.apache.geode.internal.cache;
+
+import java.util.Arrays;
+
+import org.junit.experimental.categories.Category;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+import org.junit.runners.Parameterized.Parameter;
+import org.junit.runners.Parameterized.Parameters;
+
+import org.apache.geode.cache.CacheListener;
+import org.apache.geode.cache.DataPolicy;
+import org.apache.geode.cache.InterestPolicy;
+import org.apache.geode.cache.PartitionAttributesFactory;
+import org.apache.geode.cache.Region;
+import org.apache.geode.cache.RegionFactory;
+import org.apache.geode.cache.SubscriptionAttributes;
+import org.apache.geode.test.junit.categories.DistributedTest;
+
+/**
+ * This class tests event triggering and handling in partitioned regions.
+ *
+ * <p>
+ * Converted from JUnit 3.
+ *
+ * @since GemFire 5.1
+ */
+@Category(DistributedTest.class)
+@RunWith(Parameterized.class)
+@SuppressWarnings("serial")
+public class PRCacheListenerWithInterestPolicyAllInvocationTest
+ extends ReplicateCacheListenerInvocationTest {
+
+ @Parameters(name = "{index}: redundancy={0}")
+ public static Iterable<Integer> data() {
+ return Arrays.asList(0, 3);
+ }
+
+ @Parameter
+ public int redundancy;
+
+ @Override
+ protected Region<String, Integer> createRegion(final String name,
+ final CacheListener<String, Integer> listener) {
+ PartitionAttributesFactory partitionFactory = new PartitionAttributesFactory();
+ partitionFactory.setRedundantCopies(redundancy);
+
+ RegionFactory<String, Integer> regionFactory = cacheRule.getCache().createRegionFactory();
+ regionFactory.addCacheListener(listener);
+ regionFactory.setDataPolicy(DataPolicy.PARTITION);
+ regionFactory.setPartitionAttributes(partitionFactory.create());
+ regionFactory.setSubscriptionAttributes(new SubscriptionAttributes(InterestPolicy.ALL));
+
+ return regionFactory.create(name);
+ }
+}
diff --git a/geode-core/src/test/java/org/apache/geode/internal/cache/ReplicateCacheListenerInvocationTest.java b/geode-core/src/test/java/org/apache/geode/internal/cache/ReplicateCacheListenerInvocationTest.java
index 5b6c20f..cd00e1b 100644
--- a/geode-core/src/test/java/org/apache/geode/internal/cache/ReplicateCacheListenerInvocationTest.java
+++ b/geode-core/src/test/java/org/apache/geode/internal/cache/ReplicateCacheListenerInvocationTest.java
@@ -17,6 +17,7 @@ package org.apache.geode.internal.cache;
import static org.apache.geode.test.dunit.Host.getHost;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.fail;
+import static org.hamcrest.Matchers.anyOf;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.not;
import static org.hamcrest.Matchers.nullValue;
@@ -54,7 +55,7 @@ import org.apache.geode.test.junit.rules.serializable.SerializableTestName;
* <p>
* Converted from JUnit 3.
*
- * @since 2.0
+ * @since GemFire 2.0
*/
@Category(DistributedTest.class)
@SuppressWarnings("serial")
@@ -62,15 +63,15 @@ public class ReplicateCacheListenerInvocationTest implements Serializable {
private static final Logger logger = LogService.getLogger();
+ protected static final int ENTRY_VALUE = 0;
+ protected static final int UPDATED_ENTRY_VALUE = 1;
+
private static final String CREATES = "CREATES";
private static final String UPDATES = "UPDATES";
private static final String INVALIDATES = "INVALIDATES";
private static final String DESTROYS = "DESTROYS";
- private static final int ENTRY_VALUE = 0;
- private static final int UPDATED_ENTRY_VALUE = 1;
-
- private String regionName;
+ protected String regionName;
private String key;
@ClassRule
@@ -90,7 +91,7 @@ public class ReplicateCacheListenerInvocationTest implements Serializable {
@Before
public void setUp() throws Exception {
- regionName = testName.getMethodName();
+ regionName = getClass().getSimpleName();
key = "key-1";
sharedCountersRule.initialize(CREATES);
@@ -166,10 +167,9 @@ public class ReplicateCacheListenerInvocationTest implements Serializable {
protected Region<String, Integer> createRegion(final String name,
final CacheListener<String, Integer> listener) {
RegionFactory<String, Integer> regionFactory = cacheRule.getCache().createRegionFactory();
- regionFactory.setStatisticsEnabled(true);
- regionFactory.setScope(Scope.DISTRIBUTED_ACK);
- regionFactory.setDataPolicy(DataPolicy.REPLICATE);
regionFactory.addCacheListener(listener);
+ regionFactory.setDataPolicy(DataPolicy.REPLICATE);
+ regionFactory.setScope(Scope.DISTRIBUTED_ACK);
return regionFactory.create(name);
}
@@ -231,8 +231,8 @@ public class ReplicateCacheListenerInvocationTest implements Serializable {
errorCollector.checkThat(event.getDistributedMember(), equalTo(event.getCallbackArgument()));
errorCollector.checkThat(event.getOperation(), equalTo(Operation.CREATE));
- errorCollector.checkThat(event.getNewValue(), equalTo(ENTRY_VALUE));
errorCollector.checkThat(event.getOldValue(), nullValue());
+ errorCollector.checkThat(event.getNewValue(), equalTo(ENTRY_VALUE));
if (event.getSerializedOldValue() != null) {
errorCollector.checkThat(event.getSerializedOldValue().getDeserializedValue(),
@@ -261,7 +261,7 @@ public class ReplicateCacheListenerInvocationTest implements Serializable {
errorCollector.checkThat(event.getDistributedMember(), equalTo(event.getCallbackArgument()));
errorCollector.checkThat(event.getOperation(), equalTo(Operation.UPDATE));
- errorCollector.checkThat(event.getOldValue(), equalTo(ENTRY_VALUE));
+ errorCollector.checkThat(event.getOldValue(), anyOf(equalTo(ENTRY_VALUE), nullValue()));
errorCollector.checkThat(event.getNewValue(), equalTo(UPDATED_ENTRY_VALUE));
if (event.getSerializedOldValue() != null) {
@@ -295,7 +295,7 @@ public class ReplicateCacheListenerInvocationTest implements Serializable {
equalTo(cacheRule.getSystem().getDistributedMember()));
}
errorCollector.checkThat(event.getOperation(), equalTo(Operation.INVALIDATE));
- errorCollector.checkThat(event.getOldValue(), equalTo(ENTRY_VALUE));
+ errorCollector.checkThat(event.getOldValue(), anyOf(equalTo(ENTRY_VALUE), nullValue()));
errorCollector.checkThat(event.getNewValue(), nullValue());
}
}
@@ -320,7 +320,7 @@ public class ReplicateCacheListenerInvocationTest implements Serializable {
equalTo(cacheRule.getSystem().getDistributedMember()));
}
errorCollector.checkThat(event.getOperation(), equalTo(Operation.DESTROY));
- errorCollector.checkThat(event.getOldValue(), equalTo(ENTRY_VALUE));
+ errorCollector.checkThat(event.getOldValue(), anyOf(equalTo(ENTRY_VALUE), nullValue()));
errorCollector.checkThat(event.getNewValue(), nullValue());
}
}
--
To stop receiving notification emails like this one, please contact
['"commits@geode.apache.org" <co...@geode.apache.org>'].