geode-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kl...@apache.org
Subject [09/17] geode git commit: GEODE-2236: Remove all cache-listners using Gfsh * Added check before instantiating cache listner class. Added test to verify change. * this closes #327
Date Thu, 12 Jan 2017 23:25:41 GMT
GEODE-2236: Remove all cache-listners using Gfsh
* Added check before instantiating cache listner class. Added test to verify change.
* this closes #327


Project: http://git-wip-us.apache.org/repos/asf/geode/repo
Commit: http://git-wip-us.apache.org/repos/asf/geode/commit/a5e24a7c
Tree: http://git-wip-us.apache.org/repos/asf/geode/tree/a5e24a7c
Diff: http://git-wip-us.apache.org/repos/asf/geode/diff/a5e24a7c

Branch: refs/heads/feature/GEODE-1930-2
Commit: a5e24a7c1d4c1ee0e71688be6ef0dae380017de3
Parents: a654662
Author: Deepak Dixit <deepakdixit2011@gmail.com>
Authored: Mon Jan 2 12:04:24 2017 +0530
Committer: Jinmei Liao <jiliao@pivotal.io>
Committed: Thu Jan 12 13:44:13 2017 -0800

----------------------------------------------------------------------
 .../cli/functions/RegionAlterFunction.java      |  3 +
 ...eateAlterDestroyRegionCommandsDUnitTest.java | 95 ++++++++++++++++++++
 2 files changed, 98 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/geode/blob/a5e24a7c/geode-core/src/main/java/org/apache/geode/management/internal/cli/functions/RegionAlterFunction.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/cli/functions/RegionAlterFunction.java
b/geode-core/src/main/java/org/apache/geode/management/internal/cli/functions/RegionAlterFunction.java
index 29627d2..6c0e14b 100644
--- a/geode-core/src/main/java/org/apache/geode/management/internal/cli/functions/RegionAlterFunction.java
+++ b/geode-core/src/main/java/org/apache/geode/management/internal/cli/functions/RegionAlterFunction.java
@@ -229,6 +229,9 @@ public class RegionAlterFunction extends FunctionAdapter implements InternalEnti
 
       // Add new cache listeners that don't already exist
       for (String newCacheListenerName : newCacheListenerNames) {
+        if (newCacheListenerName.isEmpty()) {
+          continue;
+        }
         boolean nameFound = false;
         for (CacheListener oldCacheListener : oldCacheListeners) {
           if (oldCacheListener.getClass().getName().equals(newCacheListenerName)) {

http://git-wip-us.apache.org/repos/asf/geode/blob/a5e24a7c/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/CreateAlterDestroyRegionCommandsDUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/CreateAlterDestroyRegionCommandsDUnitTest.java
b/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/CreateAlterDestroyRegionCommandsDUnitTest.java
index dbfa653..fde7580 100644
--- a/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/CreateAlterDestroyRegionCommandsDUnitTest.java
+++ b/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/CreateAlterDestroyRegionCommandsDUnitTest.java
@@ -860,6 +860,101 @@ public class CreateAlterDestroyRegionCommandsDUnitTest extends CliCommandTestBas
     });
   }
 
+  @Test
+  public void testAlterRegionResetCacheListeners() throws IOException {
+    setUpJmxManagerOnVm0ThenConnect(null);
+
+    CommandResult cmdResult = executeCommand(CliStrings.LIST_REGION);
+    assertEquals(Result.Status.OK, cmdResult.getStatus());
+    assertTrue(commandResultToString(cmdResult).contains("No Regions Found"));
+
+    Host.getHost(0).getVM(0).invoke(() -> {
+      Cache cache = getCache();
+      cache.createRegionFactory(RegionShortcut.PARTITION).setStatisticsEnabled(true)
+          .create(alterRegionName);
+    });
+
+    this.alterVm1 = Host.getHost(0).getVM(1);
+    this.alterVm1Name = "VM" + this.alterVm1.getPid();
+    this.alterVm1.invoke(() -> {
+      Properties localProps = new Properties();
+      localProps.setProperty(NAME, alterVm1Name);
+      localProps.setProperty(GROUPS, "Group1");
+      getSystem(localProps);
+      Cache cache = getCache();
+
+      // Setup queues and gateway senders to be used by all tests
+      cache.createRegionFactory(RegionShortcut.PARTITION).setStatisticsEnabled(true)
+          .create(alterRegionName);
+    });
+
+    this.alterVm2 = Host.getHost(0).getVM(2);
+    this.alterVm2Name = "VM" + this.alterVm2.getPid();
+    this.alterVm2.invoke(() -> {
+      Properties localProps = new Properties();
+      localProps.setProperty(NAME, alterVm2Name);
+      localProps.setProperty(GROUPS, "Group1,Group2");
+      getSystem(localProps);
+      Cache cache = getCache();
+
+      cache.createRegionFactory(RegionShortcut.PARTITION).setStatisticsEnabled(true)
+          .create(alterRegionName);
+    });
+
+    deployJarFilesForRegionAlter();
+
+    CommandStringBuilder commandStringBuilder = new CommandStringBuilder(CliStrings.ALTER_REGION);
+    commandStringBuilder.addOption(CliStrings.ALTER_REGION__REGION, "/" + this.alterRegionName);
+    commandStringBuilder.addOption(CliStrings.ALTER_REGION__CACHELISTENER,
+        "com.cadrdunit.RegionAlterCacheListenerA");
+    commandStringBuilder.addOption(CliStrings.ALTER_REGION__CACHELISTENER,
+        "com.cadrdunit.RegionAlterCacheListenerB");
+    commandStringBuilder.addOption(CliStrings.ALTER_REGION__CACHELISTENER,
+        "com.cadrdunit.RegionAlterCacheListenerC");
+
+    cmdResult = executeCommand(commandStringBuilder.toString());
+    assertEquals(Result.Status.OK, cmdResult.getStatus());
+    String stringResult = commandResultToString(cmdResult);
+
+    assertEquals(5, countLinesInString(stringResult, false));
+    assertEquals(false, stringResult.contains("ERROR"));
+    assertTrue(stringContainsLine(stringResult,
+        this.alterVm1Name + ".*Region \"/" + this.alterRegionName + "\" altered.*"));
+    assertTrue(stringContainsLine(stringResult,
+        this.alterVm2Name + ".*Region \"/" + this.alterRegionName + "\" altered.*"));
+
+    this.alterVm1.invoke(() -> {
+      RegionAttributes attributes = getCache().getRegion(alterRegionName).getAttributes();
+      assertEquals(3, attributes.getCacheListeners().length);
+      assertEquals("com.cadrdunit.RegionAlterCacheListenerA",
+          attributes.getCacheListeners()[0].getClass().getName());
+      assertEquals("com.cadrdunit.RegionAlterCacheListenerB",
+          attributes.getCacheListeners()[1].getClass().getName());
+      assertEquals("com.cadrdunit.RegionAlterCacheListenerC",
+          attributes.getCacheListeners()[2].getClass().getName());
+    });
+
+    // Add 1 back to each of the sets
+    commandStringBuilder = new CommandStringBuilder(CliStrings.ALTER_REGION);
+    commandStringBuilder.addOption(CliStrings.ALTER_REGION__REGION, "/" + this.alterRegionName);
+    commandStringBuilder.addOption(CliStrings.ALTER_REGION__GROUP, "Group1");
+    commandStringBuilder.addOption(CliStrings.ALTER_REGION__CACHELISTENER, "''");
+    cmdResult = executeCommand(commandStringBuilder.toString());
+    assertEquals(Result.Status.OK, cmdResult.getStatus());
+    stringResult = commandResultToString(cmdResult);
+    assertEquals(4, countLinesInString(stringResult, false));
+    assertEquals(false, stringResult.contains("ERROR"));
+    assertTrue(stringContainsLine(stringResult,
+        this.alterVm1Name + ".*Region \"/" + this.alterRegionName + "\" altered.*"));
+    assertTrue(stringContainsLine(stringResult,
+        this.alterVm2Name + ".*Region \"/" + this.alterRegionName + "\" altered.*"));
+
+    this.alterVm1.invoke(() -> {
+      RegionAttributes attributes = getCache().getRegion(alterRegionName).getAttributes();
+      assertEquals(0, attributes.getCacheListeners().length);
+    });
+  }
+
   /**
    * Asserts that creating, altering and destroying regions correctly updates the shared
    * configuration.


Mime
View raw message