geode-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sai_boorlaga...@apache.org
Subject [geode] branch develop updated: GEODE-4394: gfsh put command: change option --skip-if-exists to --if-… (#1425)
Date Fri, 16 Feb 2018 00:05:08 GMT
This is an automated email from the ASF dual-hosted git repository.

sai_boorlagadda pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/geode.git


The following commit(s) were added to refs/heads/develop by this push:
     new 0e6e228  GEODE-4394: gfsh put command: change option --skip-if-exists to --if-…
(#1425)
0e6e228 is described below

commit 0e6e228ea05fe6b4474b0365f846ad6ee54bfd0a
Author: Sai Boorlagadda <sai.boorlagadda@gmail.com>
AuthorDate: Thu Feb 15 16:05:02 2018 -0800

    GEODE-4394: gfsh put command: change option --skip-if-exists to --if-… (#1425)
    
    …not-exists
---
 .../internal/cli/commands/CreateRegionCommand.java |  2 +-
 .../internal/cli/commands/PutCommand.java          |  9 ++++----
 .../management/internal/cli/i18n/CliStrings.java   |  8 +++++---
 .../cli/commands/PutCommandIntegrationTest.java    | 24 ++++++++++++++++++++++
 4 files changed, 35 insertions(+), 8 deletions(-)

diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/CreateRegionCommand.java
b/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/CreateRegionCommand.java
index 1ffc6e5..43869f5 100644
--- a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/CreateRegionCommand.java
+++ b/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/CreateRegionCommand.java
@@ -85,7 +85,7 @@ public class CreateRegionCommand implements GfshCommand {
       @CliOption(key = CliStrings.CREATE_REGION__SKIPIFEXISTS, specifiedDefaultValue = "true",
           unspecifiedDefaultValue = "false",
           help = CliStrings.CREATE_REGION__SKIPIFEXISTS__HELP) boolean skipIfExists,
-      @CliOption(key = CliStrings.CREATE_REGION__IFNOTEXISTS, specifiedDefaultValue = "true",
+      @CliOption(key = CliStrings.IFNOTEXISTS, specifiedDefaultValue = "true",
           unspecifiedDefaultValue = "false",
           help = CliStrings.CREATE_REGION__IFNOTEXISTS__HELP) boolean ifNotExists,
 
diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/PutCommand.java
b/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/PutCommand.java
index af35e7c..cc4aaa8 100644
--- a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/PutCommand.java
+++ b/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/PutCommand.java
@@ -52,8 +52,9 @@ public class PutCommand implements GfshCommand {
           help = CliStrings.PUT__KEYCLASS__HELP) String keyClass,
       @CliOption(key = {CliStrings.PUT__VALUEKLASS},
           help = CliStrings.PUT__VALUEKLASS__HELP) String valueClass,
-      @CliOption(key = {CliStrings.PUT__PUTIFABSENT}, help = CliStrings.PUT__PUTIFABSENT__HELP,
-          specifiedDefaultValue = "true", unspecifiedDefaultValue = "false") boolean putIfAbsent)
{
+      @CliOption(key = {CliStrings.IFNOTEXISTS, CliStrings.PUT__PUTIFABSENT},
+          help = CliStrings.PUT__PUTIFNOTEXISTS__HELP, specifiedDefaultValue = "true",
+          unspecifiedDefaultValue = "false") boolean putIfNotExists) {
 
     InternalCache cache = getCache();
     cache.getSecurityService().authorize(Resource.DATA, Operation.WRITE, regionPath);
@@ -72,7 +73,7 @@ public class PutCommand implements GfshCommand {
         request.setKeyClass(keyClass);
         request.setRegionName(regionPath);
         request.setValueClass(valueClass);
-        request.setPutIfAbsent(putIfAbsent);
+        request.setPutIfAbsent(putIfNotExists);
         dataResult = callFunctionForRegion(request, putfn, memberList);
       } else {
         dataResult = DataCommandResult.createPutInfoResult(key, value, null,
@@ -80,7 +81,7 @@ public class PutCommand implements GfshCommand {
             false);
       }
     } else {
-      dataResult = putfn.put(key, value, putIfAbsent, keyClass, valueClass, regionPath, cache);
+      dataResult = putfn.put(key, value, putIfNotExists, keyClass, valueClass, regionPath,
cache);
     }
     dataResult.setKeyClass(keyClass);
     if (valueClass != null) {
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 6335b84..44f32bb 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
@@ -80,11 +80,14 @@ public class CliStrings {
   public static final String MEMBER = "member";
   public static final String MEMBERS = "members";
   public static final String IFEXISTS = "if-exists";
+  public static final String IFNOTEXISTS = "if-not-exists";
   public static final String JAR = "jar";
   public static final String JARS = "jars";
 
   public static final String IFEXISTS_HELP =
       "If true, the command will be a no-op if the entity does not exist.";
+  public static final String IFNOTEXISTS_HELP =
+      "If true, the command will be a no-op if the entity does exist.";
   public static final String ENTRY_IDLE_TIME_CUSTOM_EXPIRY = "entry-idle-time-custom-expiry";
   public static final String ENTRY_TTL_CUSTOM_EXPIRY = "entry-time-to-live-custom-expiry";
   public static final String ENTRY_IDLE_TIME_CUSTOM_EXPIRY_HELP =
@@ -828,7 +831,6 @@ public class CliStrings {
   public static final String CREATE_REGION__SKIPIFEXISTS = "skip-if-exists";
   public static final String CREATE_REGION__SKIPIFEXISTS__HELP =
       "(Deprecated: Use --if-not-exists) Skip region creation if the region already exists.";
-  public static final String CREATE_REGION__IFNOTEXISTS = "if-not-exists";
   public static final String CREATE_REGION__IFNOTEXISTS__HELP =
       "By default, an attempt to create a duplicate region is reported as an error. If this
option is specified without a value or is specified with a value of true, then gfsh displays
a \"Skipping...\" acknowledgement, but does not throw an error.";
   public static final String CREATE_REGION__KEYCONSTRAINT = "key-constraint";
@@ -1806,8 +1808,8 @@ public class CliStrings {
   public static final String PUT__VALUE__HELP =
       "String or JSON text from which to create the value.  Examples include: \"manager\",
\"100L\" and \"('value': 'widget')\".";
   public static final String PUT__PUTIFABSENT = "skip-if-exists";
-  public static final String PUT__PUTIFABSENT__HELP =
-      "Skip the put operation when an entry with the same key already exists. The default
is to overwrite the entry (false).";
+  public static final String PUT__PUTIFNOTEXISTS__HELP =
+      "Skip the put operation when an entry with the same key already exists. The default
is to overwrite the entry (false). Synonym skip-if-exists is deprecated.";
   public static final String PUT__KEYCLASS = "key-class";
   public static final String PUT__KEYCLASS__HELP =
       "Fully qualified class name of the key's type. The default is java.lang.String.";
diff --git a/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/PutCommandIntegrationTest.java
b/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/PutCommandIntegrationTest.java
index e164d10..fe3ac4c 100644
--- a/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/PutCommandIntegrationTest.java
+++ b/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/PutCommandIntegrationTest.java
@@ -70,6 +70,30 @@ public class PutCommandIntegrationTest {
   }
 
   @Test
+  public void putIfNotExists() throws Exception {
+    gfsh.executeAndAssertThat("put --region=/testRegion --key=key1 --value=value1")
+        .statusIsSuccess().containsKeyValuePair("Result", "true");
+    assertThat(server.getCache().getRegion("testRegion").get("key1")).isEqualTo("value1");
+
+    // if unspecified if-not-exits=false, so override
+    gfsh.executeAndAssertThat("put --region=/testRegion --key=key1 --value=value2")
+        .statusIsSuccess().containsKeyValuePair("Result", "true");
+    assertThat(server.getCache().getRegion("testRegion").get("key1")).isEqualTo("value2");
+
+    // if specified then true, so skip it
+    gfsh.executeAndAssertThat("put --region=/testRegion --key=key1 --value=value3 --if-not-exists")
+        .statusIsSuccess().containsKeyValuePair("Result", "true");
+    assertThat(server.getCache().getRegion("testRegion").get("key1")).isEqualTo("value2");
+
+    // skip-if-exists is deprecated and honored
+    gfsh.executeAndAssertThat("help put").statusIsSuccess()
+        .containsOutput("Synonym skip-if-exists is deprecated.");
+    gfsh.executeAndAssertThat("put --region=/testRegion --key=key1 --value=value3 --skip-if-exists")
+        .statusIsSuccess().containsKeyValuePair("Result", "true");
+    assertThat(server.getCache().getRegion("testRegion").get("key1")).isEqualTo("value2");
+  }
+
+  @Test
   // Bug : 51587 : GFSH command failing when ; is present in either key or value in put operation
   public void putWithSemicoln() throws Exception {
     gfsh.executeAndAssertThat("put --region=/testRegion --key=key1;key1 --value=value1;value1")

-- 
To stop receiving notification emails like this one, please contact
sai_boorlagadda@apache.org.

Mime
View raw message