[ https://issues.apache.org/jira/browse/GEODE-2236?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15815674#comment-15815674 ]
ASF GitHub Bot commented on GEODE-2236: --------------------------------------- Github user jinmeiliao commented on a diff in the pull request: https://github.com/apache/geode/pull/327#discussion_r95420817 --- Diff: geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/CreateAlterDestroyRegionCommandsDUnitTest.java --- @@ -833,6 +833,120 @@ private void regionAlterManipulatePlugInsTest() { }); } + @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); + AsyncEventListener listener = new AsyncEventListener() { --- End diff -- The EventListener is unnecessary for this test. > Attempting to remove all CacheListeners from a Region using gfsh throws > NullPointerException > -------------------------------------------------------------------------------------------- > > Key: GEODE-2236 > URL: https://issues.apache.org/jira/browse/GEODE-2236 > Project: Geode > Issue Type: Bug > Components: gfsh > Reporter: Kevin Duling > Assignee: Deepak Dixit > > The --cache-listener option to the alter region command replaces the existing > CacheListeners with the ones set in the option. > What happens in RegionAlterFunction is that the existing CacheListeners not > included in the new list are removed, then the new ones are added. > So, in theory, to remove all CacheListeners, an empty string could be passed > into the --cache-listener option like: > {noformat} > alter region --name=data --cache-listener='' > Executing - alter region --name=data --cache-listener="" > Member | Status > ------- | > ---------------------------------------------------------------------- > server2 | ERROR: java.lang.NullPointerException > at com.gemstone.gemfire.manag.. > server1 | ERROR: java.lang.NullPointerException > at com.gemstone.gemfire.manag.. > {noformat} > This actually works but it throws the NPE below. > {noformat} > [error 2016/09/13 09:48:59.943 PDT server1 <Function Execution Processor1> > tid=0x40] > java.lang.NullPointerException > at > com.gemstone.gemfire.management.internal.cli.functions.RegionAlterFunction.newInstance(RegionAlterFunction.java:320) > at > com.gemstone.gemfire.management.internal.cli.functions.RegionAlterFunction.alterRegion(RegionAlterFunction.java:228) > at > com.gemstone.gemfire.management.internal.cli.functions.RegionAlterFunction.execute(RegionAlterFunction.java:64) > at > com.gemstone.gemfire.internal.cache.MemberFunctionStreamingMessage.process(MemberFunctionStreamingMessage.java:185) > at > com.gemstone.gemfire.distributed.internal.DistributionMessage.scheduleAction(DistributionMessage.java:386) > at > com.gemstone.gemfire.distributed.internal.DistributionMessage$1.run(DistributionMessage.java:457) > at > java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) > at > java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) > at > com.gemstone.gemfire.distributed.internal.DistributionManager.runUntilShutdown(DistributionManager.java:692) > at > com.gemstone.gemfire.distributed.internal.DistributionManager$9$1.run(DistributionManager.java:1149) > at java.lang.Thread.run(Thread.java:745) > {noformat} > A work-around to this issue is to set a non-existent CacheListener in the > --cache-listener option like: > {noformat} > alter region --name=data --cache-listener=Fred > Executing - alter region --name=data --cache-listener=Fred > Member | Status > ------- | ------------------------------------------------------------------ > server1 | ERROR: Could not find class "Fred" specified for "cache-listener". > server2 | ERROR: Could not find class "Fred" specified for "cache-listener". > {noformat} > This correctly throws the ClassNotFoundException below and also removes all > the existing CacheListeners. > {noformat} > [error 2016/09/13 09:46:40.537 PDT server1 <Function Execution Processor1> > tid=0x40] Could not find class "Fred" specified for "cache-listener". > java.lang.RuntimeException: Could not find class "Fred" specified for > "cache-listener". > at > com.gemstone.gemfire.management.internal.cli.functions.RegionAlterFunction.forName(RegionAlterFunction.java:306) > at > com.gemstone.gemfire.management.internal.cli.functions.RegionAlterFunction.alterRegion(RegionAlterFunction.java:227) > at > com.gemstone.gemfire.management.internal.cli.functions.RegionAlterFunction.execute(RegionAlterFunction.java:64) > at > com.gemstone.gemfire.internal.cache.MemberFunctionStreamingMessage.process(MemberFunctionStreamingMessage.java:185) > at > com.gemstone.gemfire.distributed.internal.DistributionMessage.scheduleAction(DistributionMessage.java:386) > at > com.gemstone.gemfire.distributed.internal.DistributionMessage$1.run(DistributionMessage.java:457) > at > java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) > at > java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) > at > com.gemstone.gemfire.distributed.internal.DistributionManager.runUntilShutdown(DistributionManager.java:692) > at > com.gemstone.gemfire.distributed.internal.DistributionManager$9$1.run(DistributionManager.java:1149) > at java.lang.Thread.run(Thread.java:745) > Caused by: java.lang.ClassNotFoundException: Fred > at > com.gemstone.gemfire.internal.ClassPathLoader.forName(ClassPathLoader.java:422) > at > com.gemstone.gemfire.management.internal.cli.functions.RegionAlterFunction.forName(RegionAlterFunction.java:303) > ... 10 more > {noformat} -- This message was sent by Atlassian JIRA (v6.3.4#6332)