You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@geode.apache.org by ds...@apache.org on 2018/11/16 22:27:55 UTC

[geode] branch feature/GEODE-6068 updated: added verification to dunit test of DestroyMapping on the server

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

dschneider pushed a commit to branch feature/GEODE-6068
in repository https://gitbox.apache.org/repos/asf/geode.git


The following commit(s) were added to refs/heads/feature/GEODE-6068 by this push:
     new fd36017  added verification to dunit test of DestroyMapping on the server
fd36017 is described below

commit fd360179ac39ca48cf31a89fe72749ff37134923
Author: Darrel Schneider <ds...@pivotal.io>
AuthorDate: Fri Nov 16 14:27:00 2018 -0800

    added verification to dunit test of DestroyMapping on the server
---
 .../cli/DestroyMappingCommandDunitTest.java        | 68 +++++++++++++++++++---
 1 file changed, 61 insertions(+), 7 deletions(-)

diff --git a/geode-connectors/src/distributedTest/java/org/apache/geode/connectors/jdbc/internal/cli/DestroyMappingCommandDunitTest.java b/geode-connectors/src/distributedTest/java/org/apache/geode/connectors/jdbc/internal/cli/DestroyMappingCommandDunitTest.java
index cb42dcb..b032928 100644
--- a/geode-connectors/src/distributedTest/java/org/apache/geode/connectors/jdbc/internal/cli/DestroyMappingCommandDunitTest.java
+++ b/geode-connectors/src/distributedTest/java/org/apache/geode/connectors/jdbc/internal/cli/DestroyMappingCommandDunitTest.java
@@ -18,7 +18,7 @@ import static org.apache.geode.connectors.jdbc.internal.cli.CreateMappingCommand
 import static org.apache.geode.connectors.jdbc.internal.cli.CreateMappingCommand.CREATE_MAPPING__DATA_SOURCE_NAME;
 import static org.apache.geode.connectors.jdbc.internal.cli.CreateMappingCommand.CREATE_MAPPING__PDX_NAME;
 import static org.apache.geode.connectors.jdbc.internal.cli.CreateMappingCommand.CREATE_MAPPING__REGION_NAME;
-import static org.apache.geode.connectors.jdbc.internal.cli.CreateMappingCommand.CREATE_MAPPING__TABLE_NAME;
+import static org.apache.geode.connectors.jdbc.internal.cli.CreateMappingCommand.CREATE_MAPPING__SYNCHRONOUS_NAME;
 import static org.apache.geode.connectors.jdbc.internal.cli.DestroyMappingCommand.DESTROY_MAPPING;
 import static org.apache.geode.connectors.jdbc.internal.cli.DestroyMappingCommand.DESTROY_MAPPING__REGION_NAME;
 import static org.assertj.core.api.Assertions.assertThat;
@@ -30,6 +30,7 @@ import org.junit.Rule;
 import org.junit.Test;
 import org.junit.experimental.categories.Category;
 
+import org.apache.geode.cache.Region;
 import org.apache.geode.connectors.jdbc.internal.JdbcConnectorService;
 import org.apache.geode.connectors.jdbc.internal.configuration.RegionMapping;
 import org.apache.geode.distributed.internal.InternalLocator;
@@ -68,18 +69,30 @@ public class DestroyMappingCommandDunitTest implements Serializable {
 
     gfsh.executeAndAssertThat("create region --name=" + REGION_NAME + " --type=REPLICATE")
         .statusIsSuccess();
+  }
+
+  private void setupAsyncMapping() {
+    CommandStringBuilder csb = new CommandStringBuilder(CREATE_MAPPING);
+    csb.addOption(CREATE_MAPPING__REGION_NAME, REGION_NAME);
+    csb.addOption(CREATE_MAPPING__DATA_SOURCE_NAME, "myDataSource");
+    csb.addOption(CREATE_MAPPING__PDX_NAME, "myPdxClass");
+
+    gfsh.executeAndAssertThat(csb.toString()).statusIsSuccess();
+  }
 
+  private void setupSynchronousMapping() {
     CommandStringBuilder csb = new CommandStringBuilder(CREATE_MAPPING);
     csb.addOption(CREATE_MAPPING__REGION_NAME, REGION_NAME);
-    csb.addOption(CREATE_MAPPING__DATA_SOURCE_NAME, "connection");
-    csb.addOption(CREATE_MAPPING__TABLE_NAME, "myTable");
+    csb.addOption(CREATE_MAPPING__DATA_SOURCE_NAME, "myDataSource");
     csb.addOption(CREATE_MAPPING__PDX_NAME, "myPdxClass");
+    csb.addOption(CREATE_MAPPING__SYNCHRONOUS_NAME, "true");
 
     gfsh.executeAndAssertThat(csb.toString()).statusIsSuccess();
   }
 
   @Test
-  public void destroysRegionMapping() throws Exception {
+  public void destroysAsyncMapping() throws Exception {
+    setupAsyncMapping();
     CommandStringBuilder csb = new CommandStringBuilder(DESTROY_MAPPING);
     csb.addOption(DESTROY_MAPPING__REGION_NAME, REGION_NAME);
 
@@ -93,9 +106,50 @@ public class DestroyMappingCommandDunitTest implements Serializable {
 
     server.invoke(() -> {
       InternalCache cache = ClusterStartupRule.getCache();
-      RegionMapping mapping =
-          cache.getService(JdbcConnectorService.class).getMappingForRegion(REGION_NAME);
-      assertThat(mapping).isNull();
+      verifyMappingRemovedFromService(cache);
+      verifyRegionAltered(cache);
+      verifyQueueRemoved(cache);
     });
   }
+
+  @Test
+  public void destroysSynchronousMapping() throws Exception {
+    setupSynchronousMapping();
+    CommandStringBuilder csb = new CommandStringBuilder(DESTROY_MAPPING);
+    csb.addOption(DESTROY_MAPPING__REGION_NAME, REGION_NAME);
+
+    gfsh.executeAndAssertThat(csb.toString()).statusIsSuccess();
+
+    locator.invoke(() -> {
+      String xml = InternalLocator.getLocator().getConfigurationPersistenceService()
+          .getConfiguration("cluster").getCacheXmlContent();
+      assertThat(xml).doesNotContain("jdbc:mapping");
+    });
+
+    server.invoke(() -> {
+      InternalCache cache = ClusterStartupRule.getCache();
+      verifyMappingRemovedFromService(cache);
+      verifyRegionAltered(cache);
+      verifyQueueRemoved(cache);
+    });
+  }
+
+  private void verifyQueueRemoved(InternalCache cache) {
+    String queueName = CreateMappingCommand.createAsyncEventQueueName(REGION_NAME);
+    assertThat(cache.getAsyncEventQueue(queueName)).isNull();
+  }
+
+  private void verifyRegionAltered(InternalCache cache) {
+    Region<?, ?> region = cache.getRegion(REGION_NAME);
+    assertThat(region.getAttributes().getCacheLoader()).isNull();
+    assertThat(region.getAttributes().getCacheWriter()).isNull();
+    String queueName = CreateMappingCommand.createAsyncEventQueueName(REGION_NAME);
+    assertThat(region.getAttributes().getAsyncEventQueueIds()).doesNotContain(queueName);
+  }
+
+  private void verifyMappingRemovedFromService(InternalCache cache) {
+    RegionMapping mapping =
+        cache.getService(JdbcConnectorService.class).getMappingForRegion(REGION_NAME);
+    assertThat(mapping).isNull();
+  }
 }