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 <dschnei...@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());