Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id A72B8200C1F for ; Fri, 3 Feb 2017 19:35:34 +0100 (CET) Received: by cust-asf.ponee.io (Postfix) id A6101160B3F; Fri, 3 Feb 2017 18:35:34 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id B6B3D160B72 for ; Fri, 3 Feb 2017 19:35:32 +0100 (CET) Received: (qmail 28727 invoked by uid 500); 3 Feb 2017 18:35:31 -0000 Mailing-List: contact commits-help@geode.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@geode.apache.org Delivered-To: mailing list commits@geode.apache.org Received: (qmail 28271 invoked by uid 99); 3 Feb 2017 18:35:31 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 03 Feb 2017 18:35:31 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 5E24CE0A74; Fri, 3 Feb 2017 18:35:31 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: klund@apache.org To: commits@geode.apache.org Date: Fri, 03 Feb 2017 18:35:51 -0000 Message-Id: In-Reply-To: <1dbb6ff161b34c86aba4d6609ff05b0f@git.apache.org> References: <1dbb6ff161b34c86aba4d6609ff05b0f@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [22/32] geode git commit: GEODE-2269 Allow region entries with non null empty key such as zero length strings to be removed archived-at: Fri, 03 Feb 2017 18:35:34 -0000 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 Authored: Tue Jan 24 16:13:25 2017 -0500 Committer: Dan Smith 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 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 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 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";