This is an automated email from the ASF dual-hosted git repository.
jensdeppe 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 f1d1144 GEODE-4389 Overriding a cache listener from a template region
works correctly (#1345)
f1d1144 is described below
commit f1d1144f295d83282fe4de071fada658435078a6
Author: Jens Deppe <[email protected]>
AuthorDate: Fri Jan 26 08:33:04 2018 -0800
GEODE-4389 Overriding a cache listener from a template region works
correctly (#1345)
- When overriding a cache listener from a template region this would
previously
add the new listener instead of replacing all existing listeners.
---
.../cli/functions/RegionCreateFunction.java | 8 +++-
.../cli/commands/CreateRegionCommandDUnitTest.java | 44 +++++++++++++++++++---
2 files changed, 44 insertions(+), 8 deletions(-)
diff --git
a/geode-core/src/main/java/org/apache/geode/management/internal/cli/functions/RegionCreateFunction.java
b/geode-core/src/main/java/org/apache/geode/management/internal/cli/functions/RegionCreateFunction.java
index 3729d75..0901a93 100644
---
a/geode-core/src/main/java/org/apache/geode/management/internal/cli/functions/RegionCreateFunction.java
+++
b/geode-core/src/main/java/org/apache/geode/management/internal/cli/functions/RegionCreateFunction.java
@@ -14,8 +14,10 @@
*/
package org.apache.geode.management.internal.cli.functions;
+import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
+import java.util.List;
import java.util.Set;
import org.apache.commons.lang.StringUtils;
@@ -281,12 +283,14 @@ public class RegionCreateFunction implements Function,
InternalEntity {
// Set plugins
final Set<String> cacheListeners = regionCreateArgs.getCacheListeners();
if (cacheListeners != null && !cacheListeners.isEmpty()) {
+ List<CacheListener<K, V>> newListeners = new ArrayList<>();
for (String cacheListener : cacheListeners) {
Class<CacheListener<K, V>> cacheListenerKlass =
CliUtil.forName(cacheListener,
CliStrings.CREATE_REGION__CACHELISTENER);
- factory.addCacheListener(
- CliUtil.newInstance(cacheListenerKlass,
CliStrings.CREATE_REGION__CACHELISTENER));
+ newListeners
+ .add(CliUtil.newInstance(cacheListenerKlass,
CliStrings.CREATE_REGION__CACHELISTENER));
}
+ factory.initCacheListeners(newListeners.toArray(new CacheListener[0]));
}
// Compression provider
diff --git
a/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/CreateRegionCommandDUnitTest.java
b/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/CreateRegionCommandDUnitTest.java
index 2cc8c85..66eccd8 100644
---
a/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/CreateRegionCommandDUnitTest.java
+++
b/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/CreateRegionCommandDUnitTest.java
@@ -18,6 +18,9 @@ package org.apache.geode.management.internal.cli.commands;
import static org.assertj.core.api.Assertions.assertThat;
import java.io.File;
+import java.io.Serializable;
+import java.util.Arrays;
+import java.util.stream.Collectors;
import org.junit.BeforeClass;
import org.junit.ClassRule;
@@ -30,6 +33,7 @@ import org.junit.rules.TestName;
import org.apache.geode.cache.Cache;
import org.apache.geode.cache.PartitionResolver;
import org.apache.geode.cache.Region;
+import org.apache.geode.cache.util.CacheListenerAdapter;
import org.apache.geode.compression.SnappyCompressor;
import org.apache.geode.internal.cache.PartitionedRegion;
import org.apache.geode.internal.cache.RegionEntryContext;
@@ -43,7 +47,14 @@ import
org.apache.geode.test.junit.rules.serializable.SerializableTestName;
@Category(DistributedTest.class)
public class CreateRegionCommandDUnitTest {
- private static MemberVM locator, server;
+ private static MemberVM locator, server1, server2;
+
+ public static class TestCacheListener extends CacheListenerAdapter
implements Serializable {
+ }
+
+ public static class AnotherTestCacheListener extends CacheListenerAdapter
+ implements Serializable {
+ }
@ClassRule
public static ClusterStartupRule lsRule = new ClusterStartupRule();
@@ -60,7 +71,8 @@ public class CreateRegionCommandDUnitTest {
@BeforeClass
public static void before() throws Exception {
locator = lsRule.startLocatorVM(0);
- server = lsRule.startServerVM(1, locator.getPort());
+ server1 = lsRule.startServerVM(1, locator.getPort());
+ server2 = lsRule.startServerVM(2, locator.getPort());
gfsh.connectAndVerify(locator);
}
@@ -72,7 +84,7 @@ public class CreateRegionCommandDUnitTest {
+ " --type=REPLICATE --compressor=" +
RegionEntryContext.DEFAULT_COMPRESSION_PROVIDER)
.statusIsSuccess();
- server.invoke(() -> {
+ server1.invoke(() -> {
Cache cache = ClusterStartupRule.getCache();
Region region = cache.getRegion(regionName);
assertThat(region).isNotNull();
@@ -88,7 +100,7 @@ public class CreateRegionCommandDUnitTest {
"create region --name=" + regionName + " --type=REPLICATE
--compressor=BAD_COMPRESSOR")
.statusIsError();
- server.invoke(() -> {
+ server1.invoke(() -> {
Cache cache = ClusterStartupRule.getCache();
Region region = cache.getRegion(regionName);
assertThat(region).isNull();
@@ -101,7 +113,7 @@ public class CreateRegionCommandDUnitTest {
gfsh.executeAndAssertThat("create region --name=" + regionName + "
--type=REPLICATE")
.statusIsSuccess();
- server.invoke(() -> {
+ server1.invoke(() -> {
Cache cache = ClusterStartupRule.getCache();
Region region = cache.getRegion(regionName);
assertThat(region).isNotNull();
@@ -127,7 +139,7 @@ public class CreateRegionCommandDUnitTest {
+ " --type=PARTITION
--partition-resolver=io.pivotal.TestPartitionResolver")
.statusIsSuccess();
- server.invoke(() -> {
+ server1.invoke(() -> {
Cache cache = ClusterStartupRule.getCache();
PartitionedRegion region = (PartitionedRegion)
cache.getRegion(regionName);
PartitionResolver resolver =
region.getPartitionAttributes().getPartitionResolver();
@@ -149,4 +161,24 @@ public class CreateRegionCommandDUnitTest {
+ " --type=REPLICATE --partition-resolver=InvalidPartitionResolver")
.containsOutput("\"/" + regionName + "\" is not a Partitioned
Region").statusIsError();
}
+
+ @Test
+ public void overrideListenerFromTemplate() throws Exception {
+ gfsh.executeAndAssertThat("create region --name=/TEMPLATE
--type=PARTITION_REDUNDANT"
+ + " --cache-listener=" +
TestCacheListener.class.getName()).statusIsSuccess();
+
+ gfsh.executeAndAssertThat("create region --name=/COPY
--template-region=/TEMPLATE"
+ + " --cache-listener=" +
AnotherTestCacheListener.class.getName()).statusIsSuccess();
+
+ server1.getVM().invoke(() -> {
+ Region copy = ClusterStartupRule.getCache().getRegion("/COPY");
+
+ assertThat(Arrays.stream(copy.getAttributes().getCacheListeners())
+ .map(c -> c.getClass().getName()).collect(Collectors.toSet()))
+ .containsExactly(AnotherTestCacheListener.class.getName());
+ });
+
+ gfsh.executeAndAssertThat("destroy region --name=/COPY").statusIsSuccess();
+ gfsh.executeAndAssertThat("destroy region
--name=/TEMPLATE").statusIsSuccess();
+ }
}
--
To stop receiving notification emails like this one, please contact
[email protected].