geode-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jensde...@apache.org
Subject [geode] branch develop updated: GEODE-4354: Add --if-not-exists option to create region (#1328)
Date Fri, 26 Jan 2018 17:58:33 GMT
This is an automated email from the ASF dual-hosted git repository.

jensdeppe 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 e63152a  GEODE-4354: Add --if-not-exists option to create region (#1328)
e63152a is described below

commit e63152ac0c2bb33a53897a26cb851ce16cda26ba
Author: Jens Deppe <jdeppe@pivotal.io>
AuthorDate: Fri Jan 26 09:58:30 2018 -0800

    GEODE-4354: Add --if-not-exists option to create region (#1328)
    
    - This supercedes and deprecates --skip-if-exists
---
 .../internal/cli/commands/CreateRegionCommand.java      |  5 ++++-
 .../internal/cli/functions/RegionCreateFunction.java    |  2 +-
 .../internal/cli/functions/RegionFunctionArgs.java      | 12 ++++++------
 .../geode/management/internal/cli/i18n/CliStrings.java  |  3 +++
 .../org/apache/geode/redis/internal/RegionProvider.java |  8 ++++----
 .../internal/cli/GfshParserAutoCompletionTest.java      |  2 +-
 .../commands/CreateRegionCommandIntegrationTest.java    | 17 +++++++++++++++++
 .../internal/cli/commands/CreateRegionCommandTest.java  |  2 +-
 8 files changed, 37 insertions(+), 14 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 04e72c7..c3b6aa5 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
@@ -79,6 +79,9 @@ 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",
+          unspecifiedDefaultValue = "false",
+          help = CliStrings.CREATE_REGION__IFNOTEXISTS__HELP) boolean ifNotExists,
 
       // the following should all be in alphabetical order according to
       // their key string
@@ -192,7 +195,7 @@ public class CreateRegionCommand implements GfshCommand {
     // creating the RegionFunctionArgs
     RegionFunctionArgs functionArgs = new RegionFunctionArgs();
     functionArgs.setRegionPath(regionPath);
-    functionArgs.setSkipIfExists(skipIfExists);
+    functionArgs.setIfNotExists(ifNotExists || skipIfExists);
     functionArgs.setKeyConstraint(keyConstraint);
     functionArgs.setValueConstraint(valueConstraint);
     functionArgs.setStatisticsEnabled(statisticsEnabled);
diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/cli/functions/RegionCreateFunction.java
b/geode-core/src/main/java/org/apache/geode/management/internal/cli/functions/RegionCreateFunction.java
index 0901a93..3c032da 100644
--- a/geode-core/src/main/java/org/apache/geode/management/internal/cli/functions/RegionCreateFunction.java
+++ b/geode-core/src/main/java/org/apache/geode/management/internal/cli/functions/RegionCreateFunction.java
@@ -84,7 +84,7 @@ public class RegionCreateFunction implements Function, InternalEntity {
 
     RegionFunctionArgs regionCreateArgs = (RegionFunctionArgs) context.getArguments();
 
-    if (regionCreateArgs.isSkipIfExists()) {
+    if (regionCreateArgs.isIfNotExists()) {
       Region<Object, Object> region = cache.getRegion(regionCreateArgs.getRegionPath());
       if (region != null) {
         resultSender.lastResult(new CliFunctionResult(memberNameOrId, true,
diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/cli/functions/RegionFunctionArgs.java
b/geode-core/src/main/java/org/apache/geode/management/internal/cli/functions/RegionFunctionArgs.java
index cec4cba..1b2bf5b 100644
--- a/geode-core/src/main/java/org/apache/geode/management/internal/cli/functions/RegionFunctionArgs.java
+++ b/geode-core/src/main/java/org/apache/geode/management/internal/cli/functions/RegionFunctionArgs.java
@@ -44,7 +44,7 @@ public class RegionFunctionArgs implements Serializable {
   private String regionPath;
   private RegionShortcut regionShortcut;
   private String templateRegion;
-  private boolean skipIfExists;
+  private boolean ifNotExists;
   private String keyConstraint;
   private String valueConstraint;
   private Boolean statisticsEnabled;
@@ -89,8 +89,8 @@ public class RegionFunctionArgs implements Serializable {
   }
 
 
-  public void setSkipIfExists(boolean skipIfExists) {
-    this.skipIfExists = skipIfExists;
+  public void setIfNotExists(boolean ifNotExists) {
+    this.ifNotExists = ifNotExists;
   }
 
   public void setKeyConstraint(String keyConstraint) {
@@ -251,10 +251,10 @@ public class RegionFunctionArgs implements Serializable {
   }
 
   /**
-   * @return the skipIfExists
+   * @return the ifNotExists
    */
-  public Boolean isSkipIfExists() {
-    return this.skipIfExists;
+  public Boolean isIfNotExists() {
+    return this.ifNotExists;
   }
 
   /**
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 306f32e..88db829 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
@@ -821,6 +821,9 @@ public class CliStrings {
       "Name/Path of the region whose attributes should be duplicated when creating this region.";
   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 =
       "Skip region creation if the region already exists.";
   public static final String CREATE_REGION__KEYCONSTRAINT = "key-constraint";
   public static final String CREATE_REGION__KEYCONSTRAINT__HELP =
diff --git a/geode-core/src/main/java/org/apache/geode/redis/internal/RegionProvider.java
b/geode-core/src/main/java/org/apache/geode/redis/internal/RegionProvider.java
index 4749251..de9f109 100644
--- a/geode-core/src/main/java/org/apache/geode/redis/internal/RegionProvider.java
+++ b/geode-core/src/main/java/org/apache/geode/redis/internal/RegionProvider.java
@@ -399,10 +399,10 @@ public class RegionProvider implements Closeable {
     if (r != null)
       return r;
     do {
-      Result result = createRegionCmd.createRegion(key, defaultRegionType, null, null, true,
null,
-          null, null, null, null, null, null, null, false, false, true, false, false, false,
true,
-          null, null, null, null, null, null, null, null, null, null, null, false, null,
null, null,
-          null, null, null, null, null, null, null, null);
+      Result result = createRegionCmd.createRegion(key, defaultRegionType, null, null, true,
true,
+          null, null, null, null, null, null, null, null, false, false, true, false, false,
false,
+          true, null, null, null, null, null, null, null, null, null, null, null, false,
null, null,
+          null, null, null, null, null, null, null, null, null);
 
       r = cache.getRegion(key);
       if (result.getStatus() == Status.ERROR && r == null) {
diff --git a/geode-core/src/test/java/org/apache/geode/management/internal/cli/GfshParserAutoCompletionTest.java
b/geode-core/src/test/java/org/apache/geode/management/internal/cli/GfshParserAutoCompletionTest.java
index 86da02b..b460a84 100644
--- a/geode-core/src/test/java/org/apache/geode/management/internal/cli/GfshParserAutoCompletionTest.java
+++ b/geode-core/src/test/java/org/apache/geode/management/internal/cli/GfshParserAutoCompletionTest.java
@@ -246,7 +246,7 @@ public class GfshParserAutoCompletionTest {
   public void testCompletWithRegionTypeWithSpace() throws Exception {
     buffer = "create region --name=test --type=REPLICATE ";
     candidate = parser.complete(buffer);
-    assertThat(candidate.size()).isEqualTo(42);
+    assertThat(candidate.size()).isEqualTo(43);
     assertThat(candidate.getFirstCandidate()).isEqualTo(buffer + "--async-event-queue-id");
   }
 
diff --git a/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/CreateRegionCommandIntegrationTest.java
b/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/CreateRegionCommandIntegrationTest.java
index de80f75..210b7ee 100644
--- a/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/CreateRegionCommandIntegrationTest.java
+++ b/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/CreateRegionCommandIntegrationTest.java
@@ -161,6 +161,23 @@ public class CreateRegionCommandIntegrationTest {
   }
 
   @Test
+  public void ifNotExistsIsIdempotent() throws Exception {
+    gfsh.executeAndAssertThat(
+        "create region --if-not-exists --type=PARTITION --name=/FOO --local-max-memory=0")
+        .statusIsSuccess().containsOutput("Region \"/FOO\" created");
+
+    gfsh.executeAndAssertThat(
+        "create region --skip-if-exists --type=PARTITION --name=/FOO --local-max-memory=0")
+        .statusIsSuccess().containsOutput("Region \"/FOO\" already exists.");
+
+    gfsh.executeAndAssertThat(
+        "create region --if-not-exists --type=PARTITION --name=/FOO --local-max-memory=0")
+        .statusIsSuccess().containsOutput("Region \"/FOO\" already exists.");
+
+    gfsh.executeAndAssertThat("destroy region --name=/FOO").statusIsSuccess();
+  }
+
+  @Test
   public void invalidCacheListener() throws Exception {
     gfsh.executeAndAssertThat("create region --name=/FOO --type=REPLICATE --cache-listener=abc-def")
         .statusIsError().containsOutput("Specify a valid class name for cache-listener");
diff --git a/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/CreateRegionCommandTest.java
b/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/CreateRegionCommandTest.java
index 4b360d4..e937673 100644
--- a/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/CreateRegionCommandTest.java
+++ b/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/CreateRegionCommandTest.java
@@ -157,7 +157,7 @@ public class CreateRegionCommandTest {
     assertThat(args.getRegionPath()).isEqualTo("/A");
     assertThat(args.getRegionShortcut()).isEqualTo(RegionShortcut.REPLICATE);
     assertThat(args.getTemplateRegion()).isNull();
-    assertThat(args.isSkipIfExists()).isFalse();
+    assertThat(args.isIfNotExists()).isFalse();
     assertThat(args.getKeyConstraint()).isNull();
     assertThat(args.getValueConstraint()).isNull();
     assertThat(args.isStatisticsEnabled()).isNull();

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

Mime
View raw message