geode-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jinmeil...@apache.org
Subject incubator-geode git commit: GEODE-1615: gfsh unable to destroy region that has an hyphen in its name
Date Wed, 06 Jul 2016 17:46:31 GMT
Repository: incubator-geode
Updated Branches:
  refs/heads/develop ff2637d7a -> 66e76379d


GEODE-1615: gfsh unable to destroy region that has an hyphen in its name

This closes #186


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

Branch: refs/heads/develop
Commit: 66e76379d9745e851bce7957ac843557bc4b2f98
Parents: ff2637d
Author: Kevin J. Duling <kduling@pivotal.io>
Authored: Thu Jun 30 15:07:22 2016 -0700
Committer: Jinmei Liao <jiliao@pivotal.io>
Committed: Wed Jul 6 10:46:02 2016 -0700

----------------------------------------------------------------------
 .../CreateAlterDestroyRegionCommands.java       | 33 +++++----
 ...eateAlterDestroyRegionCommandsDUnitTest.java | 78 ++++++++++++++------
 2 files changed, 74 insertions(+), 37 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/66e76379/geode-core/src/main/java/com/gemstone/gemfire/management/internal/cli/commands/CreateAlterDestroyRegionCommands.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/com/gemstone/gemfire/management/internal/cli/commands/CreateAlterDestroyRegionCommands.java
b/geode-core/src/main/java/com/gemstone/gemfire/management/internal/cli/commands/CreateAlterDestroyRegionCommands.java
index e525f37..b1ad27d 100644
--- a/geode-core/src/main/java/com/gemstone/gemfire/management/internal/cli/commands/CreateAlterDestroyRegionCommands.java
+++ b/geode-core/src/main/java/com/gemstone/gemfire/management/internal/cli/commands/CreateAlterDestroyRegionCommands.java
@@ -30,10 +30,15 @@ import java.util.Map.Entry;
 import java.util.Set;
 import java.util.TreeSet;
 import java.util.regex.Pattern;
+
 import javax.management.MBeanServer;
 import javax.management.MalformedObjectNameException;
 import javax.management.ObjectName;
 
+import org.springframework.shell.core.annotation.CliAvailabilityIndicator;
+import org.springframework.shell.core.annotation.CliCommand;
+import org.springframework.shell.core.annotation.CliOption;
+
 import com.gemstone.gemfire.LogWriter;
 import com.gemstone.gemfire.cache.Cache;
 import com.gemstone.gemfire.cache.CacheFactory;
@@ -81,10 +86,6 @@ import com.gemstone.gemfire.management.internal.configuration.SharedConfiguratio
 import com.gemstone.gemfire.management.internal.configuration.domain.XmlEntity;
 import com.gemstone.gemfire.management.internal.security.ResourceOperation;
 
-import org.springframework.shell.core.annotation.CliAvailabilityIndicator;
-import org.springframework.shell.core.annotation.CliCommand;
-import org.springframework.shell.core.annotation.CliOption;
-
 /**
  *
  * @since GemFire 7.0
@@ -1082,17 +1083,25 @@ public class CreateAlterDestroyRegionCommands extends AbstractCommandsSupport
{
     return result;
   }
 
-  private Set<DistributedMember> findMembersForRegion(Cache cache, ManagementService
managementService, String regionPath) {
+  private Set<DistributedMember> findMembersForRegion(Cache cache,
+                                                      ManagementService managementService,
+                                                      String regionPath) {
     Set<DistributedMember> membersList = new HashSet<>();
-    Set<String> regionMemberIds = Collections.emptySet();
+    Set<String> regionMemberIds = new HashSet<>();
     MBeanServer mbeanServer = MBeanJMXAdapter.mbeanServer;
-    String queryExp = MessageFormat.format(MBeanJMXAdapter.OBJECTNAME__REGION_MXBEAN, new
Object[] {regionPath, "*"});
+
+    // needs to be escaped with quotes if it contains a hyphen
+    if (regionPath.contains("-")) {
+      regionPath = "\"" + regionPath + "\"";
+    }
+
+    String queryExp = MessageFormat.format(MBeanJMXAdapter.OBJECTNAME__REGION_MXBEAN, regionPath,
"*");
 
     try {
       ObjectName queryExpON = new ObjectName(queryExp);
       Set<ObjectName> queryNames = mbeanServer.queryNames(null, queryExpON);
-      if (queryNames != null && queryNames.size() != 0) {
-        regionMemberIds      = new HashSet<>();
+      if (queryNames == null || queryNames.isEmpty()) {
+        return membersList; // protects against null pointer exception below
       }
 
       boolean addedOneRemote = false;
@@ -1117,7 +1126,7 @@ public class CreateAlterDestroyRegionCommands extends AbstractCommandsSupport
{
         } catch (ClassCastException e) {
           LogWriter logger = cache.getLogger();
           if (logger.finerEnabled()) {
-            logger.finer(regionMBeanObjectName+" is not a "+RegionMXBean.class.getSimpleName(),
e);
+            logger.finer(regionMBeanObjectName + " is not a " + RegionMXBean.class.getSimpleName(),
e);
           }
         }
       }
@@ -1125,9 +1134,7 @@ public class CreateAlterDestroyRegionCommands extends AbstractCommandsSupport
{
       if (!regionMemberIds.isEmpty()) {
         membersList = getMembersByIds(cache, regionMemberIds);
       }
-    } catch (MalformedObjectNameException e) {
-      LogWrapper.getInstance().info(e.getMessage(), e);
-    } catch (NullPointerException e) {
+    } catch (MalformedObjectNameException | NullPointerException e) {
       LogWrapper.getInstance().info(e.getMessage(), e);
     }
 

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/66e76379/geode-core/src/test/java/com/gemstone/gemfire/management/internal/cli/commands/CreateAlterDestroyRegionCommandsDUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/management/internal/cli/commands/CreateAlterDestroyRegionCommandsDUnitTest.java
b/geode-core/src/test/java/com/gemstone/gemfire/management/internal/cli/commands/CreateAlterDestroyRegionCommandsDUnitTest.java
index 5704ad7..21cdfbc 100644
--- a/geode-core/src/test/java/com/gemstone/gemfire/management/internal/cli/commands/CreateAlterDestroyRegionCommandsDUnitTest.java
+++ b/geode-core/src/test/java/com/gemstone/gemfire/management/internal/cli/commands/CreateAlterDestroyRegionCommandsDUnitTest.java
@@ -16,7 +16,38 @@
  */
 package com.gemstone.gemfire.management.internal.cli.commands;
 
-import com.gemstone.gemfire.cache.*;
+import static com.gemstone.gemfire.distributed.ConfigurationProperties.*;
+import static com.gemstone.gemfire.test.dunit.Assert.*;
+import static com.gemstone.gemfire.test.dunit.LogWriterUtils.*;
+import static com.jayway.awaitility.Awaitility.*;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.text.MessageFormat;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Properties;
+import java.util.concurrent.Callable;
+import java.util.concurrent.CopyOnWriteArrayList;
+import java.util.concurrent.TimeUnit;
+
+import javax.management.MBeanServer;
+import javax.management.MalformedObjectNameException;
+import javax.management.ObjectName;
+
+import org.junit.Ignore;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+
+import com.gemstone.gemfire.cache.Cache;
+import com.gemstone.gemfire.cache.PartitionAttributesFactory;
+import com.gemstone.gemfire.cache.Region;
+import com.gemstone.gemfire.cache.RegionAttributes;
+import com.gemstone.gemfire.cache.RegionFactory;
+import com.gemstone.gemfire.cache.RegionShortcut;
+import com.gemstone.gemfire.cache.Scope;
 import com.gemstone.gemfire.cache.asyncqueue.AsyncEvent;
 import com.gemstone.gemfire.cache.asyncqueue.AsyncEventListener;
 import com.gemstone.gemfire.cache.wan.GatewaySenderFactory;
@@ -39,29 +70,6 @@ import com.gemstone.gemfire.test.dunit.SerializableCallable;
 import com.gemstone.gemfire.test.dunit.VM;
 import com.gemstone.gemfire.test.junit.categories.DistributedTest;
 import com.gemstone.gemfire.test.junit.categories.FlakyTest;
-import org.junit.Ignore;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
-
-import javax.management.MBeanServer;
-import javax.management.MalformedObjectNameException;
-import javax.management.ObjectName;
-import java.io.File;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.OutputStream;
-import java.text.MessageFormat;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Properties;
-import java.util.concurrent.Callable;
-import java.util.concurrent.CopyOnWriteArrayList;
-import java.util.concurrent.TimeUnit;
-
-import static com.gemstone.gemfire.distributed.ConfigurationProperties.*;
-import static com.gemstone.gemfire.test.dunit.Assert.*;
-import static com.gemstone.gemfire.test.dunit.LogWriterUtils.getLogWriter;
-import static com.jayway.awaitility.Awaitility.waitAtMost;
 
 @Category(DistributedTest.class)
 public class CreateAlterDestroyRegionCommandsDUnitTest extends CliCommandTestBase {
@@ -289,6 +297,8 @@ public class CreateAlterDestroyRegionCommandsDUnitTest extends CliCommandTestBas
         final Cache cache = getCache();
         RegionFactory<Object, Object> factory = cache.createRegionFactory(RegionShortcut.PARTITION);
         factory.create("Customer");
+        factory.create("Customer-2");
+        factory.create("Customer_3");
       });
     }
 
@@ -297,6 +307,8 @@ public class CreateAlterDestroyRegionCommandsDUnitTest extends CliCommandTestBas
       RegionFactory<Object, Object> factory = cache.createRegionFactory(RegionShortcut.REPLICATE);
       factory.setScope(Scope.LOCAL);
       factory.create("Customer");
+      factory.create("Customer-2");
+      factory.create("Customer_3");
     });
 
     waitForRegionMBeanCreation("/Customer", 3);
@@ -318,10 +330,28 @@ public class CreateAlterDestroyRegionCommandsDUnitTest extends CliCommandTestBas
     getLogWriter().info("testDestroyRegion strr=" + strr);
     assertEquals(Result.Status.OK, cmdResult.getStatus());
 
+    command = "destroy region --name=/Customer_3";
+    getLogWriter().info("testDestroyRegion command=" + command);
+    cmdResult = executeCommand(command);
+    strr = commandResultToString(cmdResult);
+    assertTrue(stringContainsLine(strr, ".*Customer_3.*destroyed successfully.*"));
+    getLogWriter().info("testDestroyRegion strr=" + strr);
+    assertEquals(Result.Status.OK, cmdResult.getStatus());
+
+    command = "destroy region --name=/Customer-2";
+    getLogWriter().info("testDestroyRegion command=" + command);
+    cmdResult = executeCommand(command);
+    strr = commandResultToString(cmdResult);
+    assertTrue(stringContainsLine(strr, ".*Customer-2.*destroyed successfully.*"));
+    getLogWriter().info("testDestroyRegion strr=" + strr);
+    assertEquals(Result.Status.OK, cmdResult.getStatus());
+
     for (int i = 1; i <= 3; i++) {
       final int x = i;
       Host.getHost(0).getVM(i).invoke(() -> {
         assertNull("Region still exists in VM " + x, getCache().getRegion("Customer"));
+        assertNull("Region still exists in VM " + x, getCache().getRegion("Customer-2"));
+        assertNull("Region still exists in VM " + x, getCache().getRegion("Customer_3"));
       });
     }
   }


Mime
View raw message