geode-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kl...@apache.org
Subject [22/32] geode git commit: GEODE-2269 Allow region entries with non null empty key such as zero length strings to be removed
Date Fri, 03 Feb 2017 18:35:51 GMT
GEODE-2269 Allow region entries with non null empty key such as zero length strings to be removed

This closes #353


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

Branch: refs/heads/feature/GEODE-1930-2
Commit: c1bedbce87a0ca09b333afd1590f5d1bdd9e463c
Parents: d2a626e
Author: Gregory Green <ggreen@ggreenMac.local>
Authored: Tue Jan 24 16:13:25 2017 -0500
Committer: Dan Smith <upthewaterspout@apache.org>
Committed: Thu Feb 2 15:29:46 2017 -0800

----------------------------------------------------------------------
 .../internal/cli/commands/DataCommands.java     |  2 +-
 .../cli/functions/DataCommandFunction.java      |  2 +-
 .../internal/cli/i18n/CliStrings.java           |  2 +-
 .../commands/GemfireDataCommandsDUnitTest.java  | 81 ++++++++++++++++++++
 4 files changed, 84 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/geode/blob/c1bedbce/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/DataCommands.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/DataCommands.java
b/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/DataCommands.java
index 2db52a4..a938987 100644
--- a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/DataCommands.java
+++ b/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/DataCommands.java
@@ -1093,7 +1093,7 @@ public class DataCommands implements CommandMarker {
           null, CliStrings.REMOVE__MSG__REGIONNAME_EMPTY, false));
     }
 
-    if (!removeAllKeys && (key == null || key.isEmpty())) {
+    if (!removeAllKeys && (key == null)) {
       return makePresentationResult(dataResult = DataCommandResult.createRemoveResult(key,
null,
           null, CliStrings.REMOVE__MSG__KEY_EMPTY, false));
     }

http://git-wip-us.apache.org/repos/asf/geode/blob/c1bedbce/geode-core/src/main/java/org/apache/geode/management/internal/cli/functions/DataCommandFunction.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/cli/functions/DataCommandFunction.java
b/geode-core/src/main/java/org/apache/geode/management/internal/cli/functions/DataCommandFunction.java
index f9c1395..bb77466 100644
--- a/geode-core/src/main/java/org/apache/geode/management/internal/cli/functions/DataCommandFunction.java
+++ b/geode-core/src/main/java/org/apache/geode/management/internal/cli/functions/DataCommandFunction.java
@@ -384,7 +384,7 @@ public class DataCommandFunction extends FunctionAdapter implements InternalEnti
     }
 
     boolean allKeysFlag = (removeAllKeys == null || removeAllKeys.isEmpty());
-    if (allKeysFlag && (key == null || key.isEmpty())) {
+    if (allKeysFlag && (key == null)) {
       return DataCommandResult.createRemoveResult(key, null, null,
           CliStrings.REMOVE__MSG__KEY_EMPTY, false);
     }

http://git-wip-us.apache.org/repos/asf/geode/blob/c1bedbce/geode-core/src/main/java/org/apache/geode/management/internal/cli/i18n/CliStrings.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/cli/i18n/CliStrings.java
b/geode-core/src/main/java/org/apache/geode/management/internal/cli/i18n/CliStrings.java
index fbeca62..393b0c4 100644
--- a/geode-core/src/main/java/org/apache/geode/management/internal/cli/i18n/CliStrings.java
+++ b/geode-core/src/main/java/org/apache/geode/management/internal/cli/i18n/CliStrings.java
@@ -1888,7 +1888,7 @@ public class CliStrings {
   public static final String REMOVE__ALL__HELP =
       "Clears the region by removing all entries. Partitioned region does not support remove-all";
   public static final String REMOVE__MSG__REGIONNAME_EMPTY = "Region name is either empty
or Null";
-  public static final String REMOVE__MSG__KEY_EMPTY = "Key is either empty or Null";
+  public static final String REMOVE__MSG__KEY_EMPTY = "Key is Null";
   public static final String REMOVE__MSG__VALUE_EMPTY = "Value is either empty or Null";
   public static final String REMOVE__MSG__REGION_NOT_FOUND_ON_ALL_MEMBERS =
       "Region <{0}> not found in any of the members";

http://git-wip-us.apache.org/repos/asf/geode/blob/c1bedbce/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/GemfireDataCommandsDUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/GemfireDataCommandsDUnitTest.java
b/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/GemfireDataCommandsDUnitTest.java
index f0eceb3..8a20631 100644
--- a/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/GemfireDataCommandsDUnitTest.java
+++ b/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/GemfireDataCommandsDUnitTest.java
@@ -738,6 +738,87 @@ public class GemfireDataCommandsDUnitTest extends CliCommandTestBase
{
     }
   }
 
+  /**
+   * Test remove an a region with a zero length string GEODE-2269
+   * 
+   * @author Gregory Green
+   */
+  @Test
+  public void testRemoveEmptyKey() {
+    // set the test region/data
+    setupForGetPutRemoveLocateEntry("testRemoveEmptyKey");
+
+    // Test across two virtual machines
+    final VM vm1 = Host.getHost(0).getVM(1);
+    final VM vm2 = Host.getHost(0).getVM(2);
+
+    // Initial empty key/value
+    String key = "";
+    String value = "";
+
+    // Get empty key in region
+    SerializableRunnable checkPutKeys = new SerializableRunnable() {
+      @Override
+      public void run() {
+        Cache cache = getCache();
+        Region<Object, Object> region = cache.getRegion(DATA_REGION_NAME_PATH);
+        assertNotNull(region);
+        region.put(key, value);
+      }
+    };
+
+    vm1.invoke(checkPutKeys);
+    vm2.invoke(checkPutKeys);
+
+    // Check if keys were put correctly
+    SerializableRunnable checkPutKeysExists = new SerializableRunnable() {
+      @Override
+      public void run() {
+        Cache cache = getCache();
+        Region<Object, Object> region = cache.getRegion(DATA_REGION_NAME_PATH);
+        assertNotNull(region);
+        assertEquals(value, region.get(key));
+      }
+    };
+
+    vm1.invoke(checkPutKeysExists);
+    vm2.invoke(checkPutKeysExists);
+
+    // Remove empty key entry using gfsh remove command
+    String command = "remove ";
+
+    command = command + " " + "--key=\"'" + key + "'\" --region=" + DATA_REGION_NAME_PATH;
+    CommandResult cmdResult = executeCommand(command);
+    printCommandOutput(cmdResult);
+
+    assertNotNull(cmdResult);
+    assertNotNull(cmdResult.getResultData());
+    assertNotNull(cmdResult.getResultData().getGfJsonObject());
+    assertTrue(
+        cmdResult.getResultData().getGfJsonObject() + " not contains message:"
+            + CliStrings.REMOVE__MSG__KEY_EMPTY,
+        !cmdResult.getResultData().getGfJsonObject().toString()
+            .contains(CliStrings.REMOVE__MSG__KEY_EMPTY));
+
+    validateResult(cmdResult, true);
+    assertEquals(Result.Status.OK, cmdResult.getStatus());
+
+    // Check that key were removed
+    SerializableRunnable checkPutKeysDoesNotExists = new SerializableRunnable() {
+      @Override
+      public void run() {
+        Cache cache = getCache();
+        Region<Object, Object> region = cache.getRegion(DATA_REGION_NAME_PATH);
+        assertNotNull(region);
+        assertFalse(value, region.containsKey(key));
+      }
+    };
+
+    vm1.invoke(checkPutKeysDoesNotExists);
+    vm2.invoke(checkPutKeysDoesNotExists);
+  }
+
+
   @Test
   public void testSimplePutCommand() {
     final String keyPrefix = "testKey";


Mime
View raw message