You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@geode.apache.org by jc...@apache.org on 2019/02/25 17:01:28 UTC

[geode] branch develop updated: GEODE-6365: Fixed logic error in DestroyRegionCommand (#3216)

This is an automated email from the ASF dual-hosted git repository.

jchen21 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 9a02038  GEODE-6365: Fixed logic error in DestroyRegionCommand (#3216)
9a02038 is described below

commit 9a020385ab6090edecd06f39d316e2dd65798d4b
Author: BenjaminPerryRoss <39...@users.noreply.github.com>
AuthorDate: Mon Feb 25 09:01:18 2019 -0800

    GEODE-6365: Fixed logic error in DestroyRegionCommand (#3216)
    
    Co-authored-by: Ben Ross <br...@pivotal.io>
    Co-authored-by: Jianxia Chen <jc...@pivotal.io>
---
 .../internal/cli/ListMappingCommandDUnitTest.java  | 81 +++++++++++++++++++---
 .../cli/commands/DestroyRegionCommand.java         | 22 +++---
 2 files changed, 81 insertions(+), 22 deletions(-)

diff --git a/geode-connectors/src/distributedTest/java/org/apache/geode/connectors/jdbc/internal/cli/ListMappingCommandDUnitTest.java b/geode-connectors/src/distributedTest/java/org/apache/geode/connectors/jdbc/internal/cli/ListMappingCommandDUnitTest.java
index 4fbca01..c099131 100644
--- a/geode-connectors/src/distributedTest/java/org/apache/geode/connectors/jdbc/internal/cli/ListMappingCommandDUnitTest.java
+++ b/geode-connectors/src/distributedTest/java/org/apache/geode/connectors/jdbc/internal/cli/ListMappingCommandDUnitTest.java
@@ -208,10 +208,6 @@ public class ListMappingCommandDUnitTest implements Serializable {
               + IdAndName.class.getName();
       gfsh.executeAndAssertThat(mapping).statusIsSuccess();
 
-      CommandStringBuilder csbd = new CommandStringBuilder(
-          "describe jdbc-mapping --region=" + regionName + " --groups=" + TEST_GROUP1);
-      gfsh.executeAndAssertThat(csbd.toString());
-
       CommandStringBuilder csb =
           new CommandStringBuilder(LIST_MAPPING + " --groups=" + TEST_GROUP1);
       CommandResultAssert commandResultAssert = gfsh.executeAndAssertThat(csb.toString());
@@ -331,15 +327,80 @@ public class ListMappingCommandDUnitTest implements Serializable {
   @Test
   public void reportsNoRegionMappingsFound() throws Exception {
     locator = startupRule.startLocatorVM(0);
-    server1 = startupRule.startServerVM(1, locator.getPort());
+    server1 = startupRule.startServerVM(1, TEST_GROUP1, locator.getPort());
     gfsh.connectAndVerify(locator);
-    gfsh.executeAndAssertThat("create region --name=" + regionName + " --type=REPLICATE")
+    gfsh.executeAndAssertThat(
+        "create data-source --name=connection --url=\"jdbc:derby:memory:newDB;create=true\"")
+        .statusIsSuccess();
+    gfsh.executeAndAssertThat(
+        "create region --name=" + regionName + " --groups=" + TEST_GROUP1 + " --type=REPLICATE")
         .statusIsSuccess();
+    createTable();
+    try {
+      String mapping =
+          "create jdbc-mapping --region=" + regionName + " --groups=" + TEST_GROUP1
+              + " --data-source=connection --schema=mySchema --table=myTable --pdx-name="
+              + IdAndName.class.getName();
+      gfsh.executeAndAssertThat(mapping).statusIsSuccess();
 
-    CommandStringBuilder csb = new CommandStringBuilder(LIST_MAPPING);
+      CommandStringBuilder csb =
+          new CommandStringBuilder(LIST_MAPPING + " --groups=" + TEST_GROUP1);
+      CommandResultAssert commandResultAssert = gfsh.executeAndAssertThat(csb.toString());
+
+      commandResultAssert.statusIsSuccess();
+      commandResultAssert.tableHasRowCount(LIST_OF_MAPPINGS, 1);
+      commandResultAssert.tableHasColumnOnlyWithValues(LIST_OF_MAPPINGS, regionName);
+
+      csb = new CommandStringBuilder(LIST_MAPPING);
+      commandResultAssert = gfsh.executeAndAssertThat(csb.toString());
+      commandResultAssert.statusIsSuccess();
+      commandResultAssert.tableHasRowCount(LIST_OF_MAPPINGS, 0);
+    } finally {
+      dropTable();
+    }
+  }
 
-    CommandResultAssert commandResultAssert = gfsh.executeAndAssertThat(csb.toString());
-    commandResultAssert.statusIsSuccess();
-    commandResultAssert.containsOutput("No JDBC mappings found");
+  @Test
+  public void testDestroyRegionFailsWithExistingJdbcMapping() throws Exception {
+    locator = startupRule.startLocatorVM(0);
+    server1 = startupRule.startServerVM(1, TEST_GROUP1, locator.getPort());
+    server2 = startupRule.startServerVM(2, TEST_GROUP2, locator.getPort());
+
+    gfsh.connectAndVerify(locator);
+    gfsh.executeAndAssertThat(
+        "create data-source --name=connection --url=\"jdbc:derby:memory:newDB;create=true\"")
+        .statusIsSuccess();
+    gfsh.executeAndAssertThat(
+        "create region --name=" + GROUP1_REGION + " --groups=" + TEST_GROUP1 + " --type=REPLICATE")
+        .statusIsSuccess();
+    gfsh.executeAndAssertThat(
+        "create region --name=" + GROUP2_REGION + " --groups=" + TEST_GROUP2 + " --type=REPLICATE")
+        .statusIsSuccess();
+    createTable();
+    try {
+      String mapping =
+          "create jdbc-mapping --region=" + GROUP1_REGION + " --groups=" + TEST_GROUP1
+              + " --data-source=connection --schema=mySchema --table=myTable --pdx-name="
+              + IdAndName.class.getName();
+      gfsh.executeAndAssertThat(mapping).statusIsSuccess();
+
+      mapping =
+          "create jdbc-mapping --region=" + GROUP2_REGION + " --groups=" + TEST_GROUP2
+              + " --data-source=connection --schema=mySchema --table=myTable --pdx-name="
+              + IdAndName.class.getName();
+      gfsh.executeAndAssertThat(mapping).statusIsSuccess();
+
+      CommandStringBuilder csb = new CommandStringBuilder("destroy region --name=" + GROUP1_REGION);
+      gfsh.executeAndAssertThat(csb.toString()).statusIsError()
+          .containsOutput("Cannot destroy region \"" + GROUP1_REGION
+              + "\" because JDBC mapping exists. Use \"destroy jdbc-mapping\" first.");
+
+      csb = new CommandStringBuilder("destroy region --name=" + GROUP2_REGION);
+      gfsh.executeAndAssertThat(csb.toString()).statusIsError()
+          .containsOutput("Cannot destroy region \"" + GROUP2_REGION
+              + "\" because JDBC mapping exists. Use \"destroy jdbc-mapping\" first.");
+    } finally {
+      dropTable();
+    }
   }
 }
diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/DestroyRegionCommand.java b/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/DestroyRegionCommand.java
index 6df293e..129a3de 100644
--- a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/DestroyRegionCommand.java
+++ b/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/DestroyRegionCommand.java
@@ -102,18 +102,16 @@ public class DestroyRegionCommand extends InternalGfshCommand {
     groupNames.add("cluster");
     for (String groupName : groupNames) {
       CacheConfig cacheConfig = ccService.getCacheConfig(groupName);
-      if (cacheConfig == null) {
-        return;
-      }
-      RegionConfig regionConfig = CacheElement.findElement(cacheConfig.getRegions(), regionName);
-      if (regionConfig == null) {
-        return;
-      }
-      CacheElement element =
-          CacheElement.findElement(regionConfig.getCustomRegionElements(), "jdbc-mapping");
-      if (element != null) {
-        throw new IllegalStateException("Cannot destroy region \"" + regionName
-            + "\" because JDBC mapping exists. Use \"destroy jdbc-mapping\" first.");
+      if (cacheConfig != null) {
+        RegionConfig regionConfig = CacheElement.findElement(cacheConfig.getRegions(), regionName);
+        if (regionConfig != null) {
+          CacheElement element =
+              CacheElement.findElement(regionConfig.getCustomRegionElements(), "jdbc-mapping");
+          if (element != null) {
+            throw new IllegalStateException("Cannot destroy region \"" + regionName
+                + "\" because JDBC mapping exists. Use \"destroy jdbc-mapping\" first.");
+          }
+        }
       }
     }
   }