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-not-exists (#1466)
Date Fri, 16 Feb 2018 22:46:45 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 54e80bf  GEODE-4394: gfsh put command: change option --skip-if-exists to --if-not-exists
(#1466)
54e80bf is described below

commit 54e80bf2d5db1c321135f4443a2eb1a1872d458f
Author: Sai Boorlagadda <sai.boorlagadda@gmail.com>
AuthorDate: Fri Feb 16 14:46:42 2018 -0800

    GEODE-4394: gfsh put command: change option --skip-if-exists to --if-not-exists (#1466)
    
    --skip-if-exists is not an alias but a deprecated option.
---
 .../internal/cli/commands/PutCommand.java          | 11 +++++---
 .../management/internal/cli/i18n/CliStrings.java   |  4 ++-
 .../cli/commands/PutCommandIntegrationTest.java    | 30 +++++++++++++++++-----
 3 files changed, 33 insertions(+), 12 deletions(-)

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 cc4aaa8..4a638ef 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,10 @@ 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.IFNOTEXISTS, CliStrings.PUT__PUTIFABSENT},
-          help = CliStrings.PUT__PUTIFNOTEXISTS__HELP, specifiedDefaultValue = "true",
+      @CliOption(key = {CliStrings.PUT__PUTIFABSENT}, help = CliStrings.PUT__PUTIFABSENT__HELP,
+          specifiedDefaultValue = "true", unspecifiedDefaultValue = "false") boolean putIfAbsent,
+      @CliOption(key = {CliStrings.IFNOTEXISTS}, help = CliStrings.PUT__PUTIFNOTEXISTS__HELP,
+          specifiedDefaultValue = "true",
           unspecifiedDefaultValue = "false") boolean putIfNotExists) {
 
     InternalCache cache = getCache();
@@ -73,7 +75,7 @@ public class PutCommand implements GfshCommand {
         request.setKeyClass(keyClass);
         request.setRegionName(regionPath);
         request.setValueClass(valueClass);
-        request.setPutIfAbsent(putIfNotExists);
+        request.setPutIfAbsent(putIfNotExists || putIfAbsent);
         dataResult = callFunctionForRegion(request, putfn, memberList);
       } else {
         dataResult = DataCommandResult.createPutInfoResult(key, value, null,
@@ -81,7 +83,8 @@ public class PutCommand implements GfshCommand {
             false);
       }
     } else {
-      dataResult = putfn.put(key, value, putIfNotExists, keyClass, valueClass, regionPath,
cache);
+      dataResult = putfn.put(key, value, putIfNotExists || putIfAbsent, 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 4587330..f24eba1 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
@@ -1809,8 +1809,10 @@ 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 =
+      "(Deprecated: Use --if-not-exists). 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.";
+      "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__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 fe3ac4c..b62d7c6 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
@@ -85,12 +85,11 @@ public class PutCommandIntegrationTest {
         .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")
+    // if specified and set to false then honor it
+    gfsh.executeAndAssertThat(
+        "put --region=/testRegion --key=key1 --value=value3 --if-not-exists=false")
         .statusIsSuccess().containsKeyValuePair("Result", "true");
-    assertThat(server.getCache().getRegion("testRegion").get("key1")).isEqualTo("value2");
+    assertThat(server.getCache().getRegion("testRegion").get("key1")).isEqualTo("value3");
   }
 
   @Test
@@ -104,11 +103,28 @@ public class PutCommandIntegrationTest {
 
   @Test
   public void putIfAbsent() throws Exception {
+    // skip-if-exists is deprecated.
+    gfsh.executeAndAssertThat("help put").statusIsSuccess()
+        .containsOutput("(Deprecated: Use --if-not-exists).");
+
     gfsh.executeAndAssertThat("put --region=/testRegion --key=key1 --value=value1")
         .statusIsSuccess().containsKeyValuePair("Result", "true");
-    gfsh.executeAndAssertThat("put --region=/testRegion --key=key1 --value=value2 --skip-if-exists")
+
+    // if unspecified then override
+    gfsh.executeAndAssertThat("put --region=/testRegion --key=key1 --value=value2")
         .statusIsSuccess();
-    assertThat(server.getCache().getRegion("testRegion").get("key1")).isEqualTo("value1");
+    assertThat(server.getCache().getRegion("testRegion").get("key1")).isEqualTo("value2");
+
+    // if specified then don't override
+    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");
+
+    // if specified and set to false then honor it
+    gfsh.executeAndAssertThat(
+        "put --region=/testRegion --key=key1 --value=value3 --skip-if-exists=false")
+        .statusIsSuccess().containsKeyValuePair("Result", "true");
+    assertThat(server.getCache().getRegion("testRegion").get("key1")).isEqualTo("value3");
   }
 
   @Test

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

Mime
View raw message