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 957574d GEODE-6505: Use Enum instead of String for RegionConfig type (#3287) 957574d is described below commit 957574d7fdb4b6ab8fb6a1aead4d7ca1476bdbc9 Author: Peter Tran <peta...@users.noreply.github.com> AuthorDate: Thu Mar 14 10:27:12 2019 -0400 GEODE-6505: Use Enum instead of String for RegionConfig type (#3287) Co-authored-by: Jinmei Liao <jil...@pivotal.io> Co-authored-by: Peter Tran <pt...@pivotal.io> Co-authored-by: Owen Nichols <onich...@pivotal.io> --- .../resources/ManagementClientCreateRegion.java | 3 +- ...ClusterManagementLocatorReconnectDunitTest.java | 3 +- .../rest/ManagementRequestLoggingDUnitTest.java | 3 +- .../internal/rest/RegionManagementDunitTest.java | 5 +- .../RegionManagementRestSecurityDUnitTest.java | 3 +- .../internal/CacheConfigDAODUnitTest.java | 3 +- .../internal/api/RegionAPIDUnitTest.java | 4 +- .../RegionConfigMutatorIntegrationTest.java | 3 +- .../RegionConfigRealizerIntegrationTest.java | 3 +- .../internal/cli/commands/CreateRegionCommand.java | 2 +- .../validators/RegionConfigValidator.java | 7 +- .../geode/cache/configuration/CacheConfigTest.java | 5 +- .../cache/configuration/RegionConfigTest.java | 8 +- ...nternalConfigurationPersistenceServiceTest.java | 3 +- .../geode/internal/config/JAXBServiceTest.java | 3 +- .../cli/commands/AlterRegionCommandTest.java | 3 +- .../realizers/RegionConfigRealizerTest.java | 5 +- .../validators/RegionConfigValidatorTest.java | 3 +- .../org/apache/geode/cache/RegionShortcut.java | 116 ++++++++++----------- .../geode/cache/configuration/RegionConfig.java | 7 +- .../ClientClusterManagementServiceDUnitTest.java | 3 +- .../rest/RegionManagementIntegrationTest.java | 3 +- .../RegionManagementSecurityIntegrationTest.java | 3 +- 23 files changed, 106 insertions(+), 95 deletions(-) diff --git a/geode-assembly/src/acceptanceTest/resources/ManagementClientCreateRegion.java b/geode-assembly/src/acceptanceTest/resources/ManagementClientCreateRegion.java index 2ed8e9b..c6c23b2 100644 --- a/geode-assembly/src/acceptanceTest/resources/ManagementClientCreateRegion.java +++ b/geode-assembly/src/acceptanceTest/resources/ManagementClientCreateRegion.java @@ -13,6 +13,7 @@ * the License. */ +import org.apache.geode.cache.RegionShortcut; import org.apache.geode.cache.configuration.RegionConfig; import org.apache.geode.management.api.ClusterManagementResult; import org.apache.geode.management.api.ClusterManagementService; @@ -27,7 +28,7 @@ public class ManagementClientTestCreateRegion { RegionConfig config = new RegionConfig(); config.setName(regionName); - config.setType("REPLICATE"); + config.setType(RegionShortcut.REPLICATE); ClusterManagementResult result = cms.create(config, "cluster"); diff --git a/geode-assembly/src/distributedTest/java/org/apache/geode/management/internal/rest/ClusterManagementLocatorReconnectDunitTest.java b/geode-assembly/src/distributedTest/java/org/apache/geode/management/internal/rest/ClusterManagementLocatorReconnectDunitTest.java index 4f812e4..6e22574 100644 --- a/geode-assembly/src/distributedTest/java/org/apache/geode/management/internal/rest/ClusterManagementLocatorReconnectDunitTest.java +++ b/geode-assembly/src/distributedTest/java/org/apache/geode/management/internal/rest/ClusterManagementLocatorReconnectDunitTest.java @@ -25,6 +25,7 @@ import org.junit.Rule; import org.junit.Test; import org.apache.geode.cache.Region; +import org.apache.geode.cache.RegionShortcut; import org.apache.geode.cache.configuration.CacheConfig; import org.apache.geode.cache.configuration.CacheElement; import org.apache.geode.cache.configuration.RegionConfig; @@ -68,7 +69,7 @@ public class ClusterManagementLocatorReconnectDunitTest { private void makeRestCallAndVerifyResult(String regionName) throws Exception { RegionConfig regionConfig = new RegionConfig(); regionConfig.setName(regionName); - regionConfig.setType("REPLICATE"); + regionConfig.setType(RegionShortcut.REPLICATE); ObjectMapper mapper = new ObjectMapper(); String json = mapper.writeValueAsString(regionConfig); diff --git a/geode-assembly/src/distributedTest/java/org/apache/geode/management/internal/rest/ManagementRequestLoggingDUnitTest.java b/geode-assembly/src/distributedTest/java/org/apache/geode/management/internal/rest/ManagementRequestLoggingDUnitTest.java index 5cded99..68f4b6f 100644 --- a/geode-assembly/src/distributedTest/java/org/apache/geode/management/internal/rest/ManagementRequestLoggingDUnitTest.java +++ b/geode-assembly/src/distributedTest/java/org/apache/geode/management/internal/rest/ManagementRequestLoggingDUnitTest.java @@ -30,6 +30,7 @@ import org.junit.BeforeClass; import org.junit.ClassRule; import org.junit.Test; +import org.apache.geode.cache.RegionShortcut; import org.apache.geode.cache.configuration.RegionConfig; import org.apache.geode.management.api.ClusterManagementResult; import org.apache.geode.test.dunit.rules.ClusterStartupRule; @@ -62,7 +63,7 @@ public class ManagementRequestLoggingDUnitTest { RegionConfig regionConfig = new RegionConfig(); regionConfig.setName("customers"); - regionConfig.setType("REPLICATE"); + regionConfig.setType(RegionShortcut.REPLICATE); ObjectMapper mapper = new ObjectMapper(); String json = mapper.writeValueAsString(regionConfig); diff --git a/geode-assembly/src/distributedTest/java/org/apache/geode/management/internal/rest/RegionManagementDunitTest.java b/geode-assembly/src/distributedTest/java/org/apache/geode/management/internal/rest/RegionManagementDunitTest.java index 40a1913..937772b 100644 --- a/geode-assembly/src/distributedTest/java/org/apache/geode/management/internal/rest/RegionManagementDunitTest.java +++ b/geode-assembly/src/distributedTest/java/org/apache/geode/management/internal/rest/RegionManagementDunitTest.java @@ -24,6 +24,7 @@ import org.junit.Test; import org.apache.geode.cache.Cache; import org.apache.geode.cache.Region; +import org.apache.geode.cache.RegionShortcut; import org.apache.geode.cache.configuration.CacheConfig; import org.apache.geode.cache.configuration.CacheElement; import org.apache.geode.cache.configuration.RegionConfig; @@ -54,7 +55,7 @@ public class RegionManagementDunitTest { public void createsRegion() throws Exception { RegionConfig regionConfig = new RegionConfig(); regionConfig.setName("customers"); - regionConfig.setType("REPLICATE"); + regionConfig.setType(RegionShortcut.REPLICATE); ObjectMapper mapper = new ObjectMapper(); String json = mapper.writeValueAsString(regionConfig); @@ -84,7 +85,7 @@ public class RegionManagementDunitTest { public void createsRegionUsingClusterManagementClient() throws Exception { RegionConfig regionConfig = new RegionConfig(); regionConfig.setName("customers2"); - regionConfig.setType("REPLICATE"); + regionConfig.setType(RegionShortcut.REPLICATE); ObjectMapper mapper = new ObjectMapper(); String json = mapper.writeValueAsString(regionConfig); diff --git a/geode-assembly/src/distributedTest/java/org/apache/geode/management/internal/rest/RegionManagementRestSecurityDUnitTest.java b/geode-assembly/src/distributedTest/java/org/apache/geode/management/internal/rest/RegionManagementRestSecurityDUnitTest.java index 9069829..3968421 100644 --- a/geode-assembly/src/distributedTest/java/org/apache/geode/management/internal/rest/RegionManagementRestSecurityDUnitTest.java +++ b/geode-assembly/src/distributedTest/java/org/apache/geode/management/internal/rest/RegionManagementRestSecurityDUnitTest.java @@ -23,6 +23,7 @@ import org.junit.BeforeClass; import org.junit.ClassRule; import org.junit.Test; +import org.apache.geode.cache.RegionShortcut; import org.apache.geode.cache.configuration.RegionConfig; import org.apache.geode.examples.SimpleSecurityManager; import org.apache.geode.management.api.ClusterManagementResult; @@ -57,7 +58,7 @@ public class RegionManagementRestSecurityDUnitTest { RegionConfig regionConfig = new RegionConfig(); regionConfig.setName("customers"); - regionConfig.setType("REPLICATE"); + regionConfig.setType(RegionShortcut.REPLICATE); ObjectMapper mapper = new ObjectMapper(); json = mapper.writeValueAsString(regionConfig); } diff --git a/geode-core/src/distributedTest/java/org/apache/geode/distributed/internal/CacheConfigDAODUnitTest.java b/geode-core/src/distributedTest/java/org/apache/geode/distributed/internal/CacheConfigDAODUnitTest.java index 29a8ef1..e60252f 100644 --- a/geode-core/src/distributedTest/java/org/apache/geode/distributed/internal/CacheConfigDAODUnitTest.java +++ b/geode-core/src/distributedTest/java/org/apache/geode/distributed/internal/CacheConfigDAODUnitTest.java @@ -22,6 +22,7 @@ import static org.assertj.core.api.Assertions.assertThat; import org.junit.Rule; import org.junit.Test; +import org.apache.geode.cache.RegionShortcut; import org.apache.geode.cache.configuration.RegionConfig; import org.apache.geode.distributed.ConfigurationPersistenceService; import org.apache.geode.test.dunit.rules.ClusterStartupRule; @@ -45,7 +46,7 @@ public class CacheConfigDAODUnitTest { ccService.updateCacheConfig("cluster", cc -> { RegionConfig regionConfig = new RegionConfig(); regionConfig.setName("regionB"); - regionConfig.setType("REPLICATE"); + regionConfig.setType(RegionShortcut.REPLICATE); cc.getRegions().add(regionConfig); return cc; }); diff --git a/geode-core/src/distributedTest/java/org/apache/geode/management/internal/api/RegionAPIDUnitTest.java b/geode-core/src/distributedTest/java/org/apache/geode/management/internal/api/RegionAPIDUnitTest.java index 8633015..b7ea652 100644 --- a/geode-core/src/distributedTest/java/org/apache/geode/management/internal/api/RegionAPIDUnitTest.java +++ b/geode-core/src/distributedTest/java/org/apache/geode/management/internal/api/RegionAPIDUnitTest.java @@ -63,7 +63,7 @@ public class RegionAPIDUnitTest { locator.invoke(() -> { RegionConfig config = new RegionConfig(); config.setName(regionName); - config.setType(RegionShortcut.PARTITION.toString()); + config.setType(RegionShortcut.PARTITION); ClusterManagementResult result = ClusterStartupRule.getLocator().getClusterManagementService() .create(config, "cluster"); assertThat(result.isSuccessful()).isTrue(); @@ -88,7 +88,7 @@ public class RegionAPIDUnitTest { locator.invoke(() -> { RegionConfig config = new RegionConfig(); config.setName(regionName); - config.setType(RegionShortcut.REPLICATE.toString()); + config.setType(RegionShortcut.REPLICATE); ClusterManagementResult result = ClusterStartupRule.getLocator().getClusterManagementService() .create(config, "cluster"); assertThat(result.isSuccessful()).isTrue(); diff --git a/geode-core/src/integrationTest/java/org/apache/geode/management/internal/configuration/mutators/RegionConfigMutatorIntegrationTest.java b/geode-core/src/integrationTest/java/org/apache/geode/management/internal/configuration/mutators/RegionConfigMutatorIntegrationTest.java index a182652..5a599bb 100644 --- a/geode-core/src/integrationTest/java/org/apache/geode/management/internal/configuration/mutators/RegionConfigMutatorIntegrationTest.java +++ b/geode-core/src/integrationTest/java/org/apache/geode/management/internal/configuration/mutators/RegionConfigMutatorIntegrationTest.java @@ -20,6 +20,7 @@ import org.junit.Before; import org.junit.Rule; import org.junit.Test; +import org.apache.geode.cache.RegionShortcut; import org.apache.geode.cache.configuration.CacheConfig; import org.apache.geode.cache.configuration.CacheElement; import org.apache.geode.cache.configuration.RegionConfig; @@ -41,7 +42,7 @@ public class RegionConfigMutatorIntegrationTest { @Test public void sanity() throws Exception { - config.setType("REPLICATE"); + config.setType(RegionShortcut.REPLICATE); config.setName("test"); CacheConfig cacheConfig = locator.getLocator().getConfigurationPersistenceService().getCacheConfig("cluster", true); diff --git a/geode-core/src/integrationTest/java/org/apache/geode/management/internal/configuration/realizers/RegionConfigRealizerIntegrationTest.java b/geode-core/src/integrationTest/java/org/apache/geode/management/internal/configuration/realizers/RegionConfigRealizerIntegrationTest.java index 61bd0ab..c500fe0 100644 --- a/geode-core/src/integrationTest/java/org/apache/geode/management/internal/configuration/realizers/RegionConfigRealizerIntegrationTest.java +++ b/geode-core/src/integrationTest/java/org/apache/geode/management/internal/configuration/realizers/RegionConfigRealizerIntegrationTest.java @@ -22,6 +22,7 @@ import org.junit.Test; import org.apache.geode.cache.DataPolicy; import org.apache.geode.cache.Region; +import org.apache.geode.cache.RegionShortcut; import org.apache.geode.cache.Scope; import org.apache.geode.cache.configuration.RegionConfig; import org.apache.geode.test.junit.rules.ServerStarterRule; @@ -43,7 +44,7 @@ public class RegionConfigRealizerIntegrationTest { @Test public void sanityCheck() throws Exception { config.setName("test"); - config.setType("REPLICATE"); + config.setType(RegionShortcut.REPLICATE); realizer.create(config, server.getCache()); 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 f69eb3d..de328cb 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 @@ -226,7 +226,7 @@ public class CreateRegionCommand extends SingleGfshCommand { InternalConfigurationPersistenceService persistenceService = getConfigurationPersistenceService(); if (regionShortcut != null) { - regionConfig.setType(regionShortcut.name()); + regionConfig.setType(regionShortcut); } // get the attributes from the template region else { diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/configuration/validators/RegionConfigValidator.java b/geode-core/src/main/java/org/apache/geode/management/internal/configuration/validators/RegionConfigValidator.java index 6c11efc..222ac05 100644 --- a/geode-core/src/main/java/org/apache/geode/management/internal/configuration/validators/RegionConfigValidator.java +++ b/geode-core/src/main/java/org/apache/geode/management/internal/configuration/validators/RegionConfigValidator.java @@ -15,27 +15,26 @@ package org.apache.geode.management.internal.configuration.validators; +import org.apache.geode.cache.RegionShortcut; import org.apache.geode.cache.configuration.CacheConfig; import org.apache.geode.cache.configuration.CacheElement; import org.apache.geode.cache.configuration.RegionConfig; import org.apache.geode.internal.cache.RegionNameValidation; public class RegionConfigValidator implements ConfigurationValidator<RegionConfig> { - public static final String DEFAULT_REGION_TYPE = "PARTITION"; @Override public void validate(RegionConfig config) throws IllegalArgumentException { - // validate the name if (config.getName() == null) { throw new IllegalArgumentException("Name of the region has to be specified."); } RegionNameValidation.validate(config.getName()); - // validate the type if (config.getType() == null) { - config.setType(DEFAULT_REGION_TYPE); + RegionShortcut defaultRegion = RegionShortcut.PARTITION; + config.setType(defaultRegion); } } diff --git a/geode-core/src/test/java/org/apache/geode/cache/configuration/CacheConfigTest.java b/geode-core/src/test/java/org/apache/geode/cache/configuration/CacheConfigTest.java index 40dc5e5..adb59ad 100644 --- a/geode-core/src/test/java/org/apache/geode/cache/configuration/CacheConfigTest.java +++ b/geode-core/src/test/java/org/apache/geode/cache/configuration/CacheConfigTest.java @@ -23,6 +23,7 @@ import org.junit.After; import org.junit.Before; import org.junit.Test; +import org.apache.geode.cache.RegionShortcut; import org.apache.geode.internal.config.JAXBService; @@ -48,7 +49,7 @@ public class CacheConfigTest { service.validateWithLocalCacheXSD(); regionConfig = new RegionConfig(); regionConfig.setName("regionA"); - regionConfig.setType("REPLICATE"); + regionConfig.setType(RegionShortcut.REPLICATE); regionXml = "<region name=\"regionA\" refid=\"REPLICATE\">"; classNameTypeXml = "<class-name>my.className</class-name>"; @@ -172,7 +173,7 @@ public class CacheConfigTest { cacheConfig = new CacheConfig("1.0"); RegionConfig regionConfig = new RegionConfig(); regionConfig.setName("test"); - regionConfig.setType("REPLICATE"); + regionConfig.setType(RegionShortcut.REPLICATE); RegionAttributesType attributes = new RegionAttributesType(); attributes.setCacheLoader(new DeclarableType("abc.Foo")); regionConfig.setRegionAttributes(attributes); diff --git a/geode-core/src/test/java/org/apache/geode/cache/configuration/RegionConfigTest.java b/geode-core/src/test/java/org/apache/geode/cache/configuration/RegionConfigTest.java index 45efaa5..d78c97f 100644 --- a/geode-core/src/test/java/org/apache/geode/cache/configuration/RegionConfigTest.java +++ b/geode-core/src/test/java/org/apache/geode/cache/configuration/RegionConfigTest.java @@ -71,19 +71,13 @@ public class RegionConfigTest { RegionShortcut[] shortcuts = RegionShortcut.values(); for (RegionShortcut shortcut : shortcuts) { RegionConfig config = new RegionConfig(); - config.setType(shortcut.name()); + config.setType(shortcut); config.setName(shortcut.name()); RegionConfig masterRegion = CacheElement.findElement(master.getRegions(), shortcut.name()); assertThat(config).isEqualToComparingFieldByFieldRecursively(masterRegion); } } - @Test - public void invalidType() { - regionConfig.setName("test"); - assertThatThrownBy(() -> regionConfig.setType("INVALID-TYPE")).isInstanceOf( - IllegalArgumentException.class); - } @Test public void correctJsonAndXml() throws Exception { diff --git a/geode-core/src/test/java/org/apache/geode/distributed/internal/InternalConfigurationPersistenceServiceTest.java b/geode-core/src/test/java/org/apache/geode/distributed/internal/InternalConfigurationPersistenceServiceTest.java index 03252ee..d2c2ddb 100644 --- a/geode-core/src/test/java/org/apache/geode/distributed/internal/InternalConfigurationPersistenceServiceTest.java +++ b/geode-core/src/test/java/org/apache/geode/distributed/internal/InternalConfigurationPersistenceServiceTest.java @@ -43,6 +43,7 @@ import org.junit.runner.RunWith; import org.w3c.dom.Document; import org.apache.geode.cache.Region; +import org.apache.geode.cache.RegionShortcut; import org.apache.geode.cache.configuration.CacheConfig; import org.apache.geode.cache.configuration.JndiBindingsType; import org.apache.geode.cache.configuration.RegionConfig; @@ -82,7 +83,7 @@ public class InternalConfigurationPersistenceServiceTest { service.updateCacheConfig("cluster", cacheConfig -> { RegionConfig regionConfig = new RegionConfig(); regionConfig.setName("regionA"); - regionConfig.setType("REPLICATE"); + regionConfig.setType(RegionShortcut.REPLICATE); cacheConfig.getRegions().add(regionConfig); return cacheConfig; }); diff --git a/geode-core/src/test/java/org/apache/geode/internal/config/JAXBServiceTest.java b/geode-core/src/test/java/org/apache/geode/internal/config/JAXBServiceTest.java index 0eb0388..c86f63f 100644 --- a/geode-core/src/test/java/org/apache/geode/internal/config/JAXBServiceTest.java +++ b/geode-core/src/test/java/org/apache/geode/internal/config/JAXBServiceTest.java @@ -31,6 +31,7 @@ import javax.xml.bind.annotation.XmlType; import org.junit.Before; import org.junit.Test; +import org.apache.geode.cache.RegionShortcut; import org.apache.geode.cache.configuration.CacheConfig; import org.apache.geode.cache.configuration.CacheElement; import org.apache.geode.cache.configuration.RegionConfig; @@ -218,7 +219,7 @@ public class JAXBServiceTest { RegionConfig region = new RegionConfig(); region.setName("testRegion"); - region.setType("REPLICATE"); + region.setType(RegionShortcut.REPLICATE); cache.getRegions().add(region); } diff --git a/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/AlterRegionCommandTest.java b/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/AlterRegionCommandTest.java index 87553e7..0f8899a 100644 --- a/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/AlterRegionCommandTest.java +++ b/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/AlterRegionCommandTest.java @@ -34,6 +34,7 @@ import org.junit.Rule; import org.junit.Test; import org.apache.geode.cache.ExpirationAction; +import org.apache.geode.cache.RegionShortcut; import org.apache.geode.cache.configuration.CacheConfig; import org.apache.geode.cache.configuration.DeclarableType; import org.apache.geode.cache.configuration.EnumActionDestroyOverflow; @@ -78,7 +79,7 @@ public class AlterRegionCommandTest { cacheConfig = new CacheConfig(); existingRegionConfig = new RegionConfig(); existingRegionConfig.setName("/regionA"); - existingRegionConfig.setType("REPLICATE"); + existingRegionConfig.setType(RegionShortcut.REPLICATE); cacheConfig.getRegions().add(existingRegionConfig); when(ccService.getCacheConfig("cluster")).thenReturn(cacheConfig); } diff --git a/geode-core/src/test/java/org/apache/geode/management/internal/configuration/realizers/RegionConfigRealizerTest.java b/geode-core/src/test/java/org/apache/geode/management/internal/configuration/realizers/RegionConfigRealizerTest.java index 9706de4..bb7a4ae 100644 --- a/geode-core/src/test/java/org/apache/geode/management/internal/configuration/realizers/RegionConfigRealizerTest.java +++ b/geode-core/src/test/java/org/apache/geode/management/internal/configuration/realizers/RegionConfigRealizerTest.java @@ -27,6 +27,7 @@ import org.mockito.ArgumentCaptor; import org.apache.geode.cache.DataPolicy; import org.apache.geode.cache.RegionFactory; +import org.apache.geode.cache.RegionShortcut; import org.apache.geode.cache.configuration.RegionConfig; import org.apache.geode.internal.cache.InternalCache; @@ -47,7 +48,7 @@ public class RegionConfigRealizerTest { public void createsPartitionedInCache() { RegionConfig config = new RegionConfig(); config.setName("regionName"); - config.setType("PARTITION"); + config.setType(RegionShortcut.PARTITION); realizer.create(config, cache); @@ -62,7 +63,7 @@ public class RegionConfigRealizerTest { public void createsReplicateInCache() { RegionConfig config = new RegionConfig(); config.setName("regionName"); - config.setType("REPLICATE"); + config.setType(RegionShortcut.REPLICATE); realizer.create(config, cache); diff --git a/geode-core/src/test/java/org/apache/geode/management/internal/configuration/validators/RegionConfigValidatorTest.java b/geode-core/src/test/java/org/apache/geode/management/internal/configuration/validators/RegionConfigValidatorTest.java index af74078..bc27140 100644 --- a/geode-core/src/test/java/org/apache/geode/management/internal/configuration/validators/RegionConfigValidatorTest.java +++ b/geode-core/src/test/java/org/apache/geode/management/internal/configuration/validators/RegionConfigValidatorTest.java @@ -23,6 +23,7 @@ import static org.assertj.core.api.Assertions.assertThatThrownBy; import org.junit.Before; import org.junit.Test; +import org.apache.geode.cache.RegionShortcut; import org.apache.geode.cache.configuration.RegionConfig; public class RegionConfigValidatorTest { @@ -39,7 +40,7 @@ public class RegionConfigValidatorTest { @Test public void noChangesWhenTypeIsSet() { config.setName("regionName"); - config.setType("REPLICATE"); + config.setType(RegionShortcut.REPLICATE); validator.validate(config); assertThat(config.getType()).isEqualTo("REPLICATE"); } diff --git a/geode-core/src/main/java/org/apache/geode/cache/RegionShortcut.java b/geode-management/src/main/java/org/apache/geode/cache/RegionShortcut.java similarity index 69% rename from geode-core/src/main/java/org/apache/geode/cache/RegionShortcut.java rename to geode-management/src/main/java/org/apache/geode/cache/RegionShortcut.java index 6ba796e..45254f0 100644 --- a/geode-core/src/main/java/org/apache/geode/cache/RegionShortcut.java +++ b/geode-management/src/main/java/org/apache/geode/cache/RegionShortcut.java @@ -16,9 +16,9 @@ package org.apache.geode.cache; /** - * Each enum represents a predefined {@link RegionAttributes} in a {@link Cache}. These enum values - * can be used to create regions using a {@link RegionFactory} obtained by calling - * {@link Cache#createRegionFactory(RegionShortcut)}. + * Each enum represents a predefined {@code RegionAttributes} in a {@code Cache}. These enum values + * can be used to create regions using a {@code RegionFactory} obtained by calling + * {@code Cache.createRegionFactory(RegionShortcut)}. * <p> * Another way to use predefined region attributes is in cache.xml by setting the refid attribute on * a region element or region-attributes element to the string of each value. @@ -28,47 +28,47 @@ package org.apache.geode.cache; public enum RegionShortcut { /** * A PARTITION has local state that is partitioned across each peer member that created the - * region. The actual RegionAttributes for a PARTITION region set the {@link DataPolicy} to - * {@link DataPolicy#PARTITION}. + * region. The actual RegionAttributes for a PARTITION region set the {@code DataPolicy} to + * {@code DataPolicy.PARTITION}. */ PARTITION, /** * A PARTITION_REDUNDANT has local state that is partitioned across each peer member that created * the region. In addition an extra copy of the data is kept in memory. The actual - * RegionAttributes for a PARTITION_REDUNDANT region set the {@link DataPolicy} to - * {@link DataPolicy#PARTITION} and the redundant-copies to 1. + * RegionAttributes for a PARTITION_REDUNDANT region set the {@code DataPolicy} to + * {@code DataPolicy.PARTITION} and the redundant-copies to 1. */ PARTITION_REDUNDANT, /** * A PARTITION_PERSISTENT has local state that is partitioned across each peer member that created * the region. In addition its state is written to disk and recovered from disk when the region is * created. The actual RegionAttributes for a PARTITION_PERSISTENT region set the - * {@link DataPolicy} to {@link DataPolicy#PERSISTENT_PARTITION}. + * {@code DataPolicy} to {@code DataPolicy.PERSISTENT_PARTITION}. */ PARTITION_PERSISTENT, /** * A PARTITION_REDUNDANT_PERSISTENT has local state that is partitioned across each peer member * that created the region. In addition its state is written to disk and recovered from disk when * the region is created. In addition an extra copy of the data is kept in memory. The actual - * RegionAttributes for a PARTITION_REDUNDANT_PERSISTENT region set the {@link DataPolicy} to - * {@link DataPolicy#PERSISTENT_PARTITION} and the redundant-copies to 1. + * RegionAttributes for a PARTITION_REDUNDANT_PERSISTENT region set the {@code DataPolicy} to + * {@code DataPolicy.PERSISTENT_PARTITION} and the redundant-copies to 1. */ PARTITION_REDUNDANT_PERSISTENT, /** * A PARTITION_OVERFLOW has local state that is partitioned across each peer member that created * the region. It will also move the values of entries to disk once it detects that the java vm is * running low of memory. The actual RegionAttributes for a PARTITION_OVERFLOW region set the - * {@link DataPolicy} to {@link DataPolicy#PARTITION}. and {@link EvictionAttributes} are set to - * {@link EvictionAlgorithm#LRU_HEAP} with {@link EvictionAction#OVERFLOW_TO_DISK}. + * {@code DataPolicy} to {@code DataPolicy.PARTITION}. and {@code EvictionAttributes} are set to + * {@code EvictionAlgorithm.LRU_HEAP} with {@code EvictionAction.OVERFLOW_TO_DISK}. */ PARTITION_OVERFLOW, /** * A PARTITION_REDUNDANT_OVERFLOW has local state that is partitioned across each peer member that * created the region. In addition an extra copy of the data is kept in memory. It will also move * the values of entries to disk once it detects that the java vm is running low of memory. The - * actual RegionAttributes for a PARTITION_REDUNDANT_OVERFLOW region set the {@link DataPolicy} to - * {@link DataPolicy#PARTITION}, the redundant-copies to 1, and {@link EvictionAttributes} are set - * to {@link EvictionAlgorithm#LRU_HEAP} with {@link EvictionAction#OVERFLOW_TO_DISK}. + * actual RegionAttributes for a PARTITION_REDUNDANT_OVERFLOW region set the {@code DataPolicy} to + * {@code DataPolicy.PARTITION}, the redundant-copies to 1, and {@code EvictionAttributes} are set + * to {@code EvictionAlgorithm.LRU_HEAP} with {@code EvictionAction.OVERFLOW_TO_DISK}. */ PARTITION_REDUNDANT_OVERFLOW, /** @@ -76,9 +76,9 @@ public enum RegionShortcut { * that created the region. In addition its state is written to disk and recovered from disk when * the region is created. It will also remove the values of entries from memory once it detects * that the java vm is running low of memory. The actual RegionAttributes for a - * PARTITION_PERSISTENT_OVERFLOW region set the {@link DataPolicy} to - * {@link DataPolicy#PERSISTENT_PARTITION} and {@link EvictionAttributes} are set to - * {@link EvictionAlgorithm#LRU_HEAP} with {@link EvictionAction#OVERFLOW_TO_DISK}. + * PARTITION_PERSISTENT_OVERFLOW region set the {@code DataPolicy} to + * {@code DataPolicy.PERSISTENT_PARTITION} and {@code EvictionAttributes} are set to + * {@code EvictionAlgorithm.LRU_HEAP} with {@code EvictionAction.OVERFLOW_TO_DISK}. */ PARTITION_PERSISTENT_OVERFLOW, /** @@ -87,50 +87,50 @@ public enum RegionShortcut { * disk when the region is created. In addition an extra copy of the data is kept in memory. It * will also remove the values of entries from memory once it detects that the java vm is running * low of memory. The actual RegionAttributes for a PARTITION_REDUNDANT_PERSISTENT_OVERFLOW region - * set the {@link DataPolicy} to {@link DataPolicy#PERSISTENT_PARTITION}, the redundant-copies to - * 1, and {@link EvictionAttributes} are set to {@link EvictionAlgorithm#LRU_HEAP} with - * {@link EvictionAction#OVERFLOW_TO_DISK}. + * set the {@code DataPolicy} to {@code DataPolicy.PERSISTENT_PARTITION}, the redundant-copies to + * 1, and {@code EvictionAttributes} are set to {@code EvictionAlgorithm.LRU_HEAP} with + * {@code EvictionAction.OVERFLOW_TO_DISK}. */ PARTITION_REDUNDANT_PERSISTENT_OVERFLOW, /** * A PARTITION_HEAP_LRU has local state that is partitioned across each peer member that created * the region. It will also destroy entries once it detects that the java vm is running low of - * memory. The actual RegionAttributes for a PARTITION_HEAP_LRU region set the {@link DataPolicy} - * to {@link DataPolicy#PARTITION} and {@link EvictionAttributes} are set to - * {@link EvictionAlgorithm#LRU_HEAP} with {@link EvictionAction#LOCAL_DESTROY}. + * memory. The actual RegionAttributes for a PARTITION_HEAP_LRU region set the {@code DataPolicy} + * to {@code DataPolicy.PARTITION} and {@code EvictionAttributes} are set to + * {@code EvictionAlgorithm.LRU_HEAP} with {@code EvictionAction.LOCAL_DESTROY}. */ PARTITION_HEAP_LRU, /** * A PARTITION_REDUNDANT_HEAP_LRU has local state that is partitioned across each peer member that * created the region. In addition an extra copy of the data is kept in memory. It will also * destroy entries once it detects that the java vm is running low of memory. The actual - * RegionAttributes for a PARTITION_REDUNDANT_HEAP_LRU region set the {@link DataPolicy} to - * {@link DataPolicy#PARTITION}, the redundant-copies to 1, and {@link EvictionAttributes} are set - * to {@link EvictionAlgorithm#LRU_HEAP} with {@link EvictionAction#LOCAL_DESTROY}. + * RegionAttributes for a PARTITION_REDUNDANT_HEAP_LRU region set the {@code DataPolicy} to + * {@code DataPolicy.PARTITION}, the redundant-copies to 1, and {@code EvictionAttributes} are set + * to {@code EvictionAlgorithm.LRU_HEAP} with {@code EvictionAction.LOCAL_DESTROY}. */ PARTITION_REDUNDANT_HEAP_LRU, /** * A REPLICATE has local state that is kept in sync with all other replicate regions that exist in - * its peers. The actual RegionAttributes for a REPLICATE region set the {@link DataPolicy} to - * {@link DataPolicy#REPLICATE} and {@link Scope} to {@link Scope#DISTRIBUTED_ACK}. + * its peers. The actual RegionAttributes for a REPLICATE region set the {@code DataPolicy} to + * {@code DataPolicy.REPLICATE} and {@code Scope} to {@code Scope.DISTRIBUTED_ACK}. */ REPLICATE, /** * A REPLICATE_PERSISTENT has local state that is kept in sync with all other replicate regions * that exist in its peers. In addition its state is written to disk and recovered from disk when * the region is created. The actual RegionAttributes for a REPLICATE_PERSISTENT region set the - * {@link DataPolicy} to {@link DataPolicy#PERSISTENT_REPLICATE} and {@link Scope} to - * {@link Scope#DISTRIBUTED_ACK}. + * {@code DataPolicy} to {@code DataPolicy.PERSISTENT_REPLICATE} and {@code Scope} to + * {@code Scope.DISTRIBUTED_ACK}. */ REPLICATE_PERSISTENT, /** * A REPLICATE_OVERFLOW has local state that is kept in sync with all other replicate regions that * exist in its peers. The actual RegionAttributes for a REPLICATE_OVERFLOW region set the - * {@link DataPolicy} to {@link DataPolicy#REPLICATE}, the {@link Scope} to - * {@link Scope#DISTRIBUTED_ACK} and {@link EvictionAttributes} are set to - * {@link EvictionAlgorithm#LRU_HEAP} with {@link EvictionAction#OVERFLOW_TO_DISK}. + * {@code DataPolicy} to {@code DataPolicy.REPLICATE}, the {@code Scope} to + * {@code Scope.DISTRIBUTED_ACK} and {@code EvictionAttributes} are set to + * {@code EvictionAlgorithm.LRU_HEAP} with {@code EvictionAction.OVERFLOW_TO_DISK}. */ REPLICATE_OVERFLOW, /** @@ -138,50 +138,50 @@ public enum RegionShortcut { * regions that exist in its peers. In addition its state is written to disk and recovered from * disk when the region is created. It will also remove the values of entries from memory once it * detects that the java vm is running low of memory. The actual RegionAttributes for a - * REPLICATE_PERSISTENT_OVERFLOW region set the {@link DataPolicy} to - * {@link DataPolicy#PERSISTENT_REPLICATE}, the {@link Scope} to {@link Scope#DISTRIBUTED_ACK}, - * and {@link EvictionAttributes} are set to {@link EvictionAlgorithm#LRU_HEAP} with - * {@link EvictionAction#OVERFLOW_TO_DISK}. + * REPLICATE_PERSISTENT_OVERFLOW region set the {@code DataPolicy} to + * {@code DataPolicy.PERSISTENT_REPLICATE}, the {@code Scope} to {@code Scope.DISTRIBUTED_ACK}, + * and {@code EvictionAttributes} are set to {@code EvictionAlgorithm.LRU_HEAP} with + * {@code EvictionAction.OVERFLOW_TO_DISK}. */ REPLICATE_PERSISTENT_OVERFLOW, /** * A REPLICATE_HEAP_LRU has local state that is kept in sync with all other replicate regions that * exist in its peers. It will also destroy entries once it detects that the java vm is running * low of memory. The actual RegionAttributes for a REPLICATE_HEAP_LRU region set the - * {@link DataPolicy} to {@link DataPolicy#PRELOADED}, the {@link Scope} to - * {@link Scope#DISTRIBUTED_ACK}, {@link SubscriptionAttributes} to {@link InterestPolicy#ALL}, - * and {@link EvictionAttributes} are set to {@link EvictionAlgorithm#LRU_HEAP} with - * {@link EvictionAction#LOCAL_DESTROY}. + * {@code DataPolicy} to {@code DataPolicy.PRELOADED}, the {@code Scope} to + * {@code Scope.DISTRIBUTED_ACK}, {@code SubscriptionAttributes} to {@code InterestPolicy.ALL}, + * and {@code EvictionAttributes} are set to {@code EvictionAlgorithm.LRU_HEAP} with + * {@code EvictionAction.LOCAL_DESTROY}. */ REPLICATE_HEAP_LRU, /** * A LOCAL region only has local state and never sends operations to others. The actual - * RegionAttributes for a LOCAL region set the {@link DataPolicy} to {@link DataPolicy#NORMAL}. + * RegionAttributes for a LOCAL region set the {@code DataPolicy} to {@code DataPolicy.NORMAL}. */ LOCAL, /** * A LOCAL_PERSISTENT region only has local state and never sends operations to others but it does * write its state to disk and can recover that state when the region is created. The actual - * RegionAttributes for a LOCAL_PERSISTENT region set the {@link DataPolicy} to - * {@link DataPolicy#PERSISTENT_REPLICATE}. + * RegionAttributes for a LOCAL_PERSISTENT region set the {@code DataPolicy} to + * {@code DataPolicy.PERSISTENT_REPLICATE}. */ LOCAL_PERSISTENT, /** * A LOCAL_HEAP_LRU region only has local state and never sends operations to others. It will also * destroy entries once it detects that the java vm is running low of memory. The actual - * RegionAttributes for a LOCAL_HEAP_LRU region set the {@link DataPolicy} to - * {@link DataPolicy#NORMAL} and {@link EvictionAttributes} are set to - * {@link EvictionAlgorithm#LRU_HEAP} with {@link EvictionAction#LOCAL_DESTROY}. + * RegionAttributes for a LOCAL_HEAP_LRU region set the {@code DataPolicy} to + * {@code DataPolicy.NORMAL} and {@code EvictionAttributes} are set to + * {@code EvictionAlgorithm.LRU_HEAP} with {@code EvictionAction.LOCAL_DESTROY}. */ LOCAL_HEAP_LRU, /** * A LOCAL_OVERFLOW region only has local state and never sends operations to others. It will also * move the values of entries to disk once it detects that the java vm is running low of memory. - * The actual RegionAttributes for a LOCAL_OVERFLOW region set the {@link DataPolicy} to - * {@link DataPolicy#NORMAL} and {@link EvictionAttributes} are set to - * {@link EvictionAlgorithm#LRU_HEAP} with {@link EvictionAction#OVERFLOW_TO_DISK}. + * The actual RegionAttributes for a LOCAL_OVERFLOW region set the {@code DataPolicy} to + * {@code DataPolicy.NORMAL} and {@code EvictionAttributes} are set to + * {@code EvictionAlgorithm.LRU_HEAP} with {@code EvictionAction.OVERFLOW_TO_DISK}. */ LOCAL_OVERFLOW, /** @@ -189,31 +189,31 @@ public enum RegionShortcut { * but it does write its state to disk and can recover that state when the region is created. It * will also remove the values of entries from memory once it detects that the java vm is running * low of memory. The actual RegionAttributes for a LOCAL_PERSISTENT_OVERFLOW region set the - * {@link DataPolicy} to {@link DataPolicy#PERSISTENT_REPLICATE} and {@link EvictionAttributes} - * are set to {@link EvictionAlgorithm#LRU_HEAP} with {@link EvictionAction#OVERFLOW_TO_DISK}. + * {@code DataPolicy} to {@code DataPolicy.PERSISTENT_REPLICATE} and {@code EvictionAttributes} + * are set to {@code EvictionAlgorithm.LRU_HEAP} with {@code EvictionAction.OVERFLOW_TO_DISK}. */ LOCAL_PERSISTENT_OVERFLOW, /** * A PARTITION_PROXY has no local state and forwards all operations to a PARTITION or a * PARTITION_PERSISTENT that exists in its peers. The actual RegionAttributes for a - * PARTITION_PROXY region set the {@link DataPolicy} to {@link DataPolicy#PARTITION} and the + * PARTITION_PROXY region set the {@code DataPolicy} to {@code DataPolicy.PARTITION} and the * local-max-memory to 0. */ PARTITION_PROXY, /** * A PARTITION_PROXY_REDUNDANT has no local state and forwards all operations to a * PARTITION_REDUNDANT or a PARTITION_REDUNDANT_PERSISTENT that exists in its peers. The actual - * RegionAttributes for a PARTITION_PROXY_REDUNDANT region set the {@link DataPolicy} to - * {@link DataPolicy#PARTITION}, the local-max-memory to 0, and the redundant-copies to 1. + * RegionAttributes for a PARTITION_PROXY_REDUNDANT region set the {@code DataPolicy} to + * {@code DataPolicy.PARTITION}, the local-max-memory to 0, and the redundant-copies to 1. */ PARTITION_PROXY_REDUNDANT, /** * A REPLICATE_PROXY has no local state and forwards all operations (except queries) to a * REPLICATE or a REPLICATE_PERSISTENT that exists in its peers. Queries will be executed on this * PROXY region. The actual RegionAttributes for a REPLICATE_PROXY region set the - * {@link DataPolicy} to {@link DataPolicy#EMPTY} and {@link Scope} to - * {@link Scope#DISTRIBUTED_ACK}. + * {@code DataPolicy} to {@code DataPolicy.EMPTY} and {@code Scope} to + * {@code Scope.DISTRIBUTED_ACK}. */ REPLICATE_PROXY; diff --git a/geode-management/src/main/java/org/apache/geode/cache/configuration/RegionConfig.java b/geode-management/src/main/java/org/apache/geode/cache/configuration/RegionConfig.java index eae46ba..67df3ca 100644 --- a/geode-management/src/main/java/org/apache/geode/cache/configuration/RegionConfig.java +++ b/geode-management/src/main/java/org/apache/geode/cache/configuration/RegionConfig.java @@ -30,6 +30,7 @@ import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlType; import org.apache.geode.annotations.Experimental; +import org.apache.geode.cache.RegionShortcut; import org.apache.geode.management.api.RestfulEndpoint; @@ -356,9 +357,9 @@ public class RegionConfig implements CacheElement, RestfulEndpoint { * {@link String } * */ - public void setType(String value) { - this.type = value; - if (value != null && value.length() > 0) { + public void setType(RegionShortcut regionShortcut) { + if (regionShortcut != null) { + this.type = regionShortcut.name(); setShortcutAttributes(); } } diff --git a/geode-web-management/src/distributedTest/java/org/apache/geode/management/client/ClientClusterManagementServiceDUnitTest.java b/geode-web-management/src/distributedTest/java/org/apache/geode/management/client/ClientClusterManagementServiceDUnitTest.java index eeba0cc..df2a937 100644 --- a/geode-web-management/src/distributedTest/java/org/apache/geode/management/client/ClientClusterManagementServiceDUnitTest.java +++ b/geode-web-management/src/distributedTest/java/org/apache/geode/management/client/ClientClusterManagementServiceDUnitTest.java @@ -31,6 +31,7 @@ import org.springframework.test.web.servlet.setup.MockMvcBuilders; import org.springframework.web.client.ResponseErrorHandler; import org.springframework.web.context.WebApplicationContext; +import org.apache.geode.cache.RegionShortcut; import org.apache.geode.cache.configuration.RegionConfig; import org.apache.geode.management.api.ClusterManagementResult; import org.apache.geode.management.api.ClusterManagementService; @@ -73,7 +74,7 @@ public class ClientClusterManagementServiceDUnitTest { public void createRegion() { RegionConfig region = new RegionConfig(); region.setName("customer"); - region.setType("REPLICATE"); + region.setType(RegionShortcut.REPLICATE); ClusterManagementResult result = client.create(region, ""); diff --git a/geode-web-management/src/integrationTest/java/org/apache/geode/management/internal/rest/RegionManagementIntegrationTest.java b/geode-web-management/src/integrationTest/java/org/apache/geode/management/internal/rest/RegionManagementIntegrationTest.java index 1ccc006..590eb46 100644 --- a/geode-web-management/src/integrationTest/java/org/apache/geode/management/internal/rest/RegionManagementIntegrationTest.java +++ b/geode-web-management/src/integrationTest/java/org/apache/geode/management/internal/rest/RegionManagementIntegrationTest.java @@ -36,6 +36,7 @@ import org.springframework.test.web.servlet.request.RequestPostProcessor; import org.springframework.test.web.servlet.setup.MockMvcBuilders; import org.springframework.web.context.WebApplicationContext; +import org.apache.geode.cache.RegionShortcut; import org.apache.geode.cache.configuration.RegionConfig; @RunWith(SpringRunner.class) @@ -62,7 +63,7 @@ public class RegionManagementIntegrationTest { public void sanityCheck() throws Exception { RegionConfig regionConfig = new RegionConfig(); regionConfig.setName("customers"); - regionConfig.setType("REPLICATE"); + regionConfig.setType(RegionShortcut.REPLICATE); ObjectMapper mapper = new ObjectMapper(); String json = mapper.writeValueAsString(regionConfig); diff --git a/geode-web-management/src/integrationTest/java/org/apache/geode/management/internal/rest/RegionManagementSecurityIntegrationTest.java b/geode-web-management/src/integrationTest/java/org/apache/geode/management/internal/rest/RegionManagementSecurityIntegrationTest.java index aabc8bc..5cc66f3 100644 --- a/geode-web-management/src/integrationTest/java/org/apache/geode/management/internal/rest/RegionManagementSecurityIntegrationTest.java +++ b/geode-web-management/src/integrationTest/java/org/apache/geode/management/internal/rest/RegionManagementSecurityIntegrationTest.java @@ -36,6 +36,7 @@ import org.springframework.test.web.servlet.request.RequestPostProcessor; import org.springframework.test.web.servlet.setup.MockMvcBuilders; import org.springframework.web.context.WebApplicationContext; +import org.apache.geode.cache.RegionShortcut; import org.apache.geode.cache.configuration.RegionConfig; @RunWith(SpringRunner.class) @@ -58,7 +59,7 @@ public class RegionManagementSecurityIntegrationTest { public void before() throws JsonProcessingException { regionConfig = new RegionConfig(); regionConfig.setName("customers"); - regionConfig.setType("REPLICATE"); + regionConfig.setType(RegionShortcut.REPLICATE); ObjectMapper mapper = new ObjectMapper(); json = mapper.writeValueAsString(regionConfig); mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext)