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/08 20:35:30 UTC

[geode] branch feature/GEODE-6010 updated (ade6e6a -> 7fcf4d0)

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

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


    from ade6e6a  CreateMappingCommandTest now passes
     new 0b8dd98  now makes sure the region does not have a cache loader
     new 7fcf4d0  added check for existing async-event-queue

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../jdbc/internal/cli/CreateMappingCommand.java    | 43 +++++++++++++--
 .../internal/cli/CreateMappingCommandTest.java     | 64 +++++++++++++++++++++-
 2 files changed, 100 insertions(+), 7 deletions(-)


[geode] 01/02: now makes sure the region does not have a cache loader

Posted by ds...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 0b8dd98b4e2dc6bc0baf57c896fc1785cbc72645
Author: Darrel Schneider <ds...@pivotal.io>
AuthorDate: Thu Nov 8 12:06:58 2018 -0800

    now makes sure the region does not have a cache loader
---
 .../jdbc/internal/cli/CreateMappingCommand.java    | 25 +++++++++++++++----
 .../internal/cli/CreateMappingCommandTest.java     | 29 ++++++++++++++++++++++
 2 files changed, 49 insertions(+), 5 deletions(-)

diff --git a/geode-connectors/src/main/java/org/apache/geode/connectors/jdbc/internal/cli/CreateMappingCommand.java b/geode-connectors/src/main/java/org/apache/geode/connectors/jdbc/internal/cli/CreateMappingCommand.java
index f00c015..e34573f 100644
--- a/geode-connectors/src/main/java/org/apache/geode/connectors/jdbc/internal/cli/CreateMappingCommand.java
+++ b/geode-connectors/src/main/java/org/apache/geode/connectors/jdbc/internal/cli/CreateMappingCommand.java
@@ -14,6 +14,7 @@
  */
 package org.apache.geode.connectors.jdbc.internal.cli;
 
+
 import java.util.List;
 import java.util.Set;
 
@@ -22,6 +23,9 @@ import org.springframework.shell.core.annotation.CliOption;
 
 import org.apache.geode.annotations.Experimental;
 import org.apache.geode.cache.configuration.CacheConfig;
+import org.apache.geode.cache.configuration.DeclarableType;
+import org.apache.geode.cache.configuration.RegionAttributesType;
+import org.apache.geode.cache.configuration.RegionConfig;
 import org.apache.geode.connectors.jdbc.internal.configuration.RegionMapping;
 import org.apache.geode.distributed.ConfigurationPersistenceService;
 import org.apache.geode.distributed.DistributedMember;
@@ -75,15 +79,26 @@ public class CreateMappingCommand extends SingleGfshCommand {
       return ResultModel.createError("Cluster Configuration must be enabled.");
     }
 
-    if (!configurationPersistenceService
-        .getCacheConfig(null)
-        .getRegions()
-        .stream()
-        .anyMatch(regionConfig -> regionConfig.getName().equals(mapping.getRegionName()))) {
+    RegionConfig regionConfig = configurationPersistenceService.getCacheConfig(null)
+        .getRegions().stream().filter(region -> region.getName().equals(mapping.getRegionName()))
+        .findFirst().orElse(null);
+    if (regionConfig == null) {
       return ResultModel
           .createError("Cluster Configuration must contain a region named " + regionName);
     }
 
+    RegionAttributesType regionAttributes = regionConfig.getRegionAttributes().stream()
+        .filter(attributes -> attributes.getCacheLoader() != null).findFirst().orElse(null);
+    if (regionAttributes != null) {
+      DeclarableType loaderDeclarable = regionAttributes.getCacheLoader();
+      if (loaderDeclarable != null) {
+        return ResultModel
+            .createError("The existing region " + regionName
+                + " must not already have a cache-loader, but it has "
+                + loaderDeclarable.getClassName());
+      }
+    }
+
     List<CliFunctionResult> results =
         executeAndGetFunctionResult(new CreateMappingFunction(), mapping, targetMembers);
 
diff --git a/geode-connectors/src/test/java/org/apache/geode/connectors/jdbc/internal/cli/CreateMappingCommandTest.java b/geode-connectors/src/test/java/org/apache/geode/connectors/jdbc/internal/cli/CreateMappingCommandTest.java
index 0b84043..eeb6f46 100644
--- a/geode-connectors/src/test/java/org/apache/geode/connectors/jdbc/internal/cli/CreateMappingCommandTest.java
+++ b/geode-connectors/src/test/java/org/apache/geode/connectors/jdbc/internal/cli/CreateMappingCommandTest.java
@@ -32,6 +32,8 @@ import org.junit.Test;
 
 import org.apache.geode.cache.configuration.CacheConfig;
 import org.apache.geode.cache.configuration.CacheElement;
+import org.apache.geode.cache.configuration.DeclarableType;
+import org.apache.geode.cache.configuration.RegionAttributesType;
 import org.apache.geode.cache.configuration.RegionConfig;
 import org.apache.geode.connectors.jdbc.internal.configuration.RegionMapping;
 import org.apache.geode.distributed.ConfigurationPersistenceService;
@@ -160,6 +162,33 @@ public class CreateMappingCommandTest {
   }
 
   @Test
+  public void createsMappingReturnsStatusERRORWhenClusterConfigRegionHasLoader() {
+    results.add(successFunctionResult);
+    ConfigurationPersistenceService configurationPersistenceService =
+        mock(ConfigurationPersistenceService.class);
+    doReturn(configurationPersistenceService).when(createRegionMappingCommand)
+        .getConfigurationPersistenceService();
+    when(configurationPersistenceService.getCacheConfig(null)).thenReturn(cacheConfig);
+    List<RegionConfig> list = new ArrayList<>();
+    list.add(matchingRegion);
+    when(cacheConfig.getRegions()).thenReturn(list);
+    List<RegionAttributesType> attributes = new ArrayList<>();
+    RegionAttributesType loaderAttribute = mock(RegionAttributesType.class);
+    DeclarableType loaderDeclarable = mock(DeclarableType.class);
+    when(loaderDeclarable.getClassName()).thenReturn("MyCacheLoaderClass");
+    when(loaderAttribute.getCacheLoader()).thenReturn(loaderDeclarable);
+    attributes.add(loaderAttribute);
+    when(matchingRegion.getRegionAttributes()).thenReturn(attributes);
+
+    ResultModel result = createRegionMappingCommand.createMapping(regionName, dataSourceName,
+        tableName, pdxClass);
+
+    assertThat(result.getStatus()).isSameAs(Result.Status.ERROR);
+    assertThat(result.toString()).contains("The existing region " + regionName
+        + " must not already have a cache-loader, but it has MyCacheLoaderClass");
+  }
+
+  @Test
   public void testUpdateClusterConfigWithNoRegionsAndNoExistingElement() {
     doReturn(null).when(cacheConfig).findCustomRegionElement(any(), any(), any());
     when(cacheConfig.getRegions()).thenReturn(Collections.emptyList());


[geode] 02/02: added check for existing async-event-queue

Posted by ds...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 7fcf4d0830eea8a4ccf7887b394d7e62d2dc65a2
Author: Darrel Schneider <ds...@pivotal.io>
AuthorDate: Thu Nov 8 12:34:56 2018 -0800

    added check for existing async-event-queue
---
 .../jdbc/internal/cli/CreateMappingCommand.java    | 24 ++++++++++++---
 .../internal/cli/CreateMappingCommandTest.java     | 35 +++++++++++++++++++++-
 2 files changed, 54 insertions(+), 5 deletions(-)

diff --git a/geode-connectors/src/main/java/org/apache/geode/connectors/jdbc/internal/cli/CreateMappingCommand.java b/geode-connectors/src/main/java/org/apache/geode/connectors/jdbc/internal/cli/CreateMappingCommand.java
index e34573f..0218e61 100644
--- a/geode-connectors/src/main/java/org/apache/geode/connectors/jdbc/internal/cli/CreateMappingCommand.java
+++ b/geode-connectors/src/main/java/org/apache/geode/connectors/jdbc/internal/cli/CreateMappingCommand.java
@@ -15,6 +15,7 @@
 package org.apache.geode.connectors.jdbc.internal.cli;
 
 
+
 import java.util.List;
 import java.util.Set;
 
@@ -23,6 +24,7 @@ import org.springframework.shell.core.annotation.CliOption;
 
 import org.apache.geode.annotations.Experimental;
 import org.apache.geode.cache.configuration.CacheConfig;
+import org.apache.geode.cache.configuration.CacheConfig.AsyncEventQueue;
 import org.apache.geode.cache.configuration.DeclarableType;
 import org.apache.geode.cache.configuration.RegionAttributesType;
 import org.apache.geode.cache.configuration.RegionConfig;
@@ -79,12 +81,14 @@ public class CreateMappingCommand extends SingleGfshCommand {
       return ResultModel.createError("Cluster Configuration must be enabled.");
     }
 
-    RegionConfig regionConfig = configurationPersistenceService.getCacheConfig(null)
-        .getRegions().stream().filter(region -> region.getName().equals(mapping.getRegionName()))
-        .findFirst().orElse(null);
+    CacheConfig cacheConfig = configurationPersistenceService.getCacheConfig(null);
+
+    RegionConfig regionConfig = cacheConfig.getRegions().stream()
+        .filter(region -> region.getName().equals(mapping.getRegionName())).findFirst()
+        .orElse(null);
     if (regionConfig == null) {
       return ResultModel
-          .createError("Cluster Configuration must contain a region named " + regionName);
+          .createError("A region named " + regionName + " must already exist.");
     }
 
     RegionAttributesType regionAttributes = regionConfig.getRegionAttributes().stream()
@@ -98,6 +102,14 @@ public class CreateMappingCommand extends SingleGfshCommand {
                 + loaderDeclarable.getClassName());
       }
     }
+    String queueName = getAsyncEventQueueName(regionName);
+    AsyncEventQueue asyncEventQueue = cacheConfig.getAsyncEventQueues().stream()
+        .filter(queue -> queue.getId().equals(queueName)).findFirst().orElse(null);
+    if (asyncEventQueue != null) {
+      return ResultModel
+          .createError("An async-event-queue named " + queueName + " must not already exist.");
+    }
+
 
     List<CliFunctionResult> results =
         executeAndGetFunctionResult(new CreateMappingFunction(), mapping, targetMembers);
@@ -108,6 +120,10 @@ public class CreateMappingCommand extends SingleGfshCommand {
     return result;
   }
 
+  String getAsyncEventQueueName(String regionName) {
+    return "JDBC-" + regionName;
+  }
+
   @Override
   public void updateClusterConfig(String group, CacheConfig cacheConfig, Object element) {
     RegionMapping newCacheElement = (RegionMapping) element;
diff --git a/geode-connectors/src/test/java/org/apache/geode/connectors/jdbc/internal/cli/CreateMappingCommandTest.java b/geode-connectors/src/test/java/org/apache/geode/connectors/jdbc/internal/cli/CreateMappingCommandTest.java
index eeb6f46..37d7901 100644
--- a/geode-connectors/src/test/java/org/apache/geode/connectors/jdbc/internal/cli/CreateMappingCommandTest.java
+++ b/geode-connectors/src/test/java/org/apache/geode/connectors/jdbc/internal/cli/CreateMappingCommandTest.java
@@ -31,6 +31,7 @@ import org.junit.Before;
 import org.junit.Test;
 
 import org.apache.geode.cache.configuration.CacheConfig;
+import org.apache.geode.cache.configuration.CacheConfig.AsyncEventQueue;
 import org.apache.geode.cache.configuration.CacheElement;
 import org.apache.geode.cache.configuration.DeclarableType;
 import org.apache.geode.cache.configuration.RegionAttributesType;
@@ -158,7 +159,7 @@ public class CreateMappingCommandTest {
 
     assertThat(result.getStatus()).isSameAs(Result.Status.ERROR);
     assertThat(result.toString())
-        .contains("Cluster Configuration must contain a region named " + regionName);
+        .contains("A region named " + regionName + " must already exist.");
   }
 
   @Test
@@ -188,6 +189,38 @@ public class CreateMappingCommandTest {
         + " must not already have a cache-loader, but it has MyCacheLoaderClass");
   }
 
+
+  @Test
+  public void createsMappingReturnsStatusERRORWhenAsycnEventQueueAlreadyExists() {
+    results.add(successFunctionResult);
+    ConfigurationPersistenceService configurationPersistenceService =
+        mock(ConfigurationPersistenceService.class);
+    doReturn(configurationPersistenceService).when(createRegionMappingCommand)
+        .getConfigurationPersistenceService();
+    when(configurationPersistenceService.getCacheConfig(null)).thenReturn(cacheConfig);
+    List<RegionConfig> list = new ArrayList<>();
+    list.add(matchingRegion);
+    when(cacheConfig.getRegions()).thenReturn(list);
+    List<RegionAttributesType> attributes = new ArrayList<>();
+    RegionAttributesType loaderAttribute = mock(RegionAttributesType.class);
+    when(loaderAttribute.getCacheLoader()).thenReturn(null);
+    attributes.add(loaderAttribute);
+    when(matchingRegion.getRegionAttributes()).thenReturn(attributes);
+    List<AsyncEventQueue> asyncEventQueues = new ArrayList<>();
+    AsyncEventQueue matchingQueue = mock(AsyncEventQueue.class);
+    String queueName = createRegionMappingCommand.getAsyncEventQueueName(regionName);
+    when(matchingQueue.getId()).thenReturn(queueName);
+    asyncEventQueues.add(matchingQueue);
+    when(cacheConfig.getAsyncEventQueues()).thenReturn(asyncEventQueues);
+
+    ResultModel result = createRegionMappingCommand.createMapping(regionName, dataSourceName,
+        tableName, pdxClass);
+
+    assertThat(result.getStatus()).isSameAs(Result.Status.ERROR);
+    assertThat(result.toString())
+        .contains("An async-event-queue named " + queueName + " must not already exist.");
+  }
+
   @Test
   public void testUpdateClusterConfigWithNoRegionsAndNoExistingElement() {
     doReturn(null).when(cacheConfig).findCustomRegionElement(any(), any(), any());