Adding option partition-resolver in gfsh while creating a region.
Project: http://git-wip-us.apache.org/repos/asf/incubator-geode/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-geode/commit/95ad1643 Tree: http://git-wip-us.apache.org/repos/asf/incubator-geode/tree/95ad1643 Diff: http://git-wip-us.apache.org/repos/asf/incubator-geode/diff/95ad1643 Branch: refs/heads/feature/GEODE-1930 Commit: 95ad1643874cd37d8c3b9dbcae8923ea58fe5be7 Parents: 3db9b30 Author: adongre <[email protected]> Authored: Fri Oct 28 16:04:15 2016 +0530 Committer: Anthony Baker <[email protected]> Committed: Sat Nov 12 07:55:22 2016 -0800 ---------------------------------------------------------------------- .../CreateAlterDestroyRegionCommands.java | 45 +++++-- .../cli/functions/RegionCreateFunction.java | 42 ++++++ .../cli/functions/RegionFunctionArgs.java | 42 +++++- .../internal/cli/i18n/CliStrings.java | 21 +++ .../geode/redis/internal/RegionProvider.java | 2 +- ...eateAlterDestroyRegionCommandsDUnitTest.java | 129 ++++++++++++++++++- .../cli/commands/golden-help-offline.properties | 12 +- 7 files changed, 263 insertions(+), 30 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/95ad1643/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/CreateAlterDestroyRegionCommands.java ---------------------------------------------------------------------- diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/CreateAlterDestroyRegionCommands.java b/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/CreateAlterDestroyRegionCommands.java index 5dba0d8..58af6cb 100644 --- a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/CreateAlterDestroyRegionCommands.java +++ b/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/CreateAlterDestroyRegionCommands.java @@ -31,19 +31,13 @@ import javax.management.MBeanServer; import javax.management.MalformedObjectNameException; import javax.management.ObjectName; +import joptsimple.internal.Strings; +import org.apache.geode.cache.*; import org.springframework.shell.core.annotation.CliAvailabilityIndicator; import org.springframework.shell.core.annotation.CliCommand; import org.springframework.shell.core.annotation.CliOption; import org.apache.geode.LogWriter; -import org.apache.geode.cache.Cache; -import org.apache.geode.cache.CacheFactory; -import org.apache.geode.cache.DataPolicy; -import org.apache.geode.cache.ExpirationAttributes; -import org.apache.geode.cache.Region; -import org.apache.geode.cache.RegionAttributes; -import org.apache.geode.cache.RegionShortcut; -import org.apache.geode.cache.Scope; import org.apache.geode.cache.execute.ResultCollector; import org.apache.geode.compression.Compressor; import org.apache.geode.distributed.DistributedMember; @@ -199,6 +193,9 @@ public class CreateAlterDestroyRegionCommands extends AbstractCommandsSupport { unspecifiedDefaultValue = CliMetaData.ANNOTATION_NULL_VALUE, specifiedDefaultValue = "true", help = CliStrings.CREATE_REGION__OFF_HEAP__HELP) Boolean offHeap, + @CliOption(key = CliStrings.CREATE_REGION__PARTITION_RESOLVER, + unspecifiedDefaultValue = CliMetaData.ANNOTATION_NULL_VALUE, + help = CliStrings.CREATE_REGION__PARTITION_RESOLVER__HELP) String partitionResolver, @CliOption(key = CliStrings.CREATE_REGION__REGIONEXPIRATIONIDLETIME, unspecifiedDefaultValue = CliMetaData.ANNOTATION_NULL_VALUE, help = CliStrings.CREATE_REGION__REGIONEXPIRATIONIDLETIME__HELP) Integer regionExpirationIdleTime, @@ -299,7 +296,7 @@ public class CreateAlterDestroyRegionCommands extends AbstractCommandsSupport { asyncEventQueueIds, gatewaySenderIds, concurrencyChecksEnabled, cloningEnabled, concurrencyLevel, prColocatedWith, prLocalMaxMemory, prRecoveryDelay, prRedundantCopies, prStartupRecoveryDelay, prTotalMaxMemory, prTotalNumBuckets, offHeap, mcastEnabled, - regionAttributes); + regionAttributes, partitionResolver); if (regionAttributes.getPartitionAttributes() == null @@ -318,7 +315,7 @@ public class CreateAlterDestroyRegionCommands extends AbstractCommandsSupport { asyncEventQueueIds, gatewaySenderIds, concurrencyChecksEnabled, cloningEnabled, concurrencyLevel, prColocatedWith, prLocalMaxMemory, prRecoveryDelay, prRedundantCopies, prStartupRecoveryDelay, prTotalMaxMemory, prTotalNumBuckets, null, compressor, offHeap, - mcastEnabled); + mcastEnabled, partitionResolver); if (!regionShortcut.name().startsWith("PARTITION") && regionFunctionArgs.hasPartitionAttributes()) { @@ -369,7 +366,6 @@ public class CreateAlterDestroyRegionCommands extends AbstractCommandsSupport { xmlEntity = regionCreateResult.getXmlEntity(); } } - result = ResultBuilder.buildResult(tabularResultData); verifyDistributedRegionMbean(cache, regionPath); @@ -550,7 +546,7 @@ public class CreateAlterDestroyRegionCommands extends AbstractCommandsSupport { regionFunctionArgs = new RegionFunctionArgs(regionPath, null, null, false, null, null, null, entryIdle, entryTTL, regionIdle, regionTTL, null, null, null, null, cacheListeners, cacheLoader, cacheWriter, asyncEventQueueIds, gatewaySenderIds, null, cloningEnabled, - null, null, null, null, null, null, null, null, evictionMax, null, null, null); + null, null, null, null, null, null, null, null, evictionMax, null, null, null, null); Set<String> cacheListenersSet = regionFunctionArgs.getCacheListeners(); if (cacheListenersSet != null && !cacheListenersSet.isEmpty()) { @@ -907,6 +903,31 @@ public class CreateAlterDestroyRegionCommands extends AbstractCommandsSupport { new Object[] {regionFunctionArgs.getCompressor()})); } } + + if (regionFunctionArgs.hasPartitionAttributes()) { + boolean partitionResolverFailure = false; + if (regionFunctionArgs.isPartitionResolverSet()) { + String partitionResolverClassName = regionFunctionArgs.getPartitionResolver(); + Object partitionResolver = null; + + try { + Class<?> compressorClass = + (Class<?>) ClassPathLoader.getLatest().forName(partitionResolverClassName); + partitionResolver = compressorClass.newInstance(); + } catch (InstantiationException e) { + partitionResolverFailure = true; + } catch (IllegalAccessException e) { + partitionResolverFailure = true; + } catch (ClassNotFoundException e) { + partitionResolverFailure = true; + } + if (partitionResolverFailure || !(partitionResolver instanceof PartitionResolver)) { + throw new IllegalArgumentException( + CliStrings.format(CliStrings.CREATE_REGION__MSG__INVALID_PARTITION_RESOLVER, + new Object[] {regionFunctionArgs.getCompressor()})); + } + } + } } private boolean diskStoreExists(Cache cache, String diskStoreName) { http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/95ad1643/geode-core/src/main/java/org/apache/geode/management/internal/cli/functions/RegionCreateFunction.java ---------------------------------------------------------------------- diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/cli/functions/RegionCreateFunction.java b/geode-core/src/main/java/org/apache/geode/management/internal/cli/functions/RegionCreateFunction.java index c7c27cc..b925936 100644 --- a/geode-core/src/main/java/org/apache/geode/management/internal/cli/functions/RegionCreateFunction.java +++ b/geode-core/src/main/java/org/apache/geode/management/internal/cli/functions/RegionCreateFunction.java @@ -16,6 +16,8 @@ package org.apache.geode.management.internal.cli.functions; import java.util.Set; +import joptsimple.internal.Strings; +import org.apache.geode.internal.ClassPathLoader; import org.apache.logging.log4j.Logger; import org.apache.geode.cache.Cache; @@ -26,6 +28,7 @@ import org.apache.geode.cache.CacheWriter; import org.apache.geode.cache.DataPolicy; import org.apache.geode.cache.PartitionAttributes; import org.apache.geode.cache.PartitionAttributesFactory; +import org.apache.geode.cache.PartitionResolver; import org.apache.geode.cache.Region; import org.apache.geode.cache.RegionAttributes; import org.apache.geode.cache.RegionExistsException; @@ -405,9 +408,48 @@ public class RegionCreateFunction extends FunctionAdapter implements InternalEnt prAttrFactory.setStartupRecoveryDelay(partitionArgs.getPrStartupRecoveryDelay()); } + if (regionCreateArgs.isPartitionResolverSet()) { + Class<?> partitionResolverClass = forName(regionCreateArgs.getPartitionResolver(), + CliStrings.CREATE_REGION__PARTITION_RESOLVER); + prAttrFactory + .setPartitionResolver((PartitionResolver<K, V>) newInstance(partitionResolverClass, + CliStrings.CREATE_REGION__PARTITION_RESOLVER)); + } return prAttrFactory.create(); } + + private static Class<?> forName(String className, String neededFor) { + if (Strings.isNullOrEmpty(className)) { + return null; + } + try { + return ClassPathLoader.getLatest().forName(className); + } catch (ClassNotFoundException e) { + throw new RuntimeException(CliStrings.format( + CliStrings.CREATE_REGION_PARTITION_RESOLVER__MSG__COULDNOT_FIND_CLASS_0_SPECIFIED_FOR_1, + new Object[] {className, neededFor}), e); + } catch (ClassCastException e) { + throw new RuntimeException(CliStrings.format( + CliStrings.CREATE_REGION__MSG__PARTITION_RESOLVER__CLASS_0_SPECIFIED_FOR_1_IS_NOT_OF_EXPECTED_TYPE, + new Object[] {className, neededFor}), e); + } + } + + private static Object newInstance(Class<?> klass, String neededFor) { + try { + return klass.newInstance(); + } catch (InstantiationException e) { + throw new RuntimeException(CliStrings.format( + CliStrings.CREATE_REGION__MSG__PARTITION_RESOLVER__COULDNOT_INSTANTIATE_CLASS_0_SPECIFIED_FOR_1, + new Object[] {klass, neededFor}), e); + } catch (IllegalAccessException e) { + throw new RuntimeException(CliStrings.format( + CliStrings.CREATE_REGION__MSG__PARTITION_RESOLVER__COULDNOT_ACCESS_CLASS_0_SPECIFIED_FOR_1, + new Object[] {klass, neededFor}), e); + } + } + @Override public String getId() { return ID; http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/95ad1643/geode-core/src/main/java/org/apache/geode/management/internal/cli/functions/RegionFunctionArgs.java ---------------------------------------------------------------------- diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/cli/functions/RegionFunctionArgs.java b/geode-core/src/main/java/org/apache/geode/management/internal/cli/functions/RegionFunctionArgs.java index c1a8d1f..573b82e 100644 --- a/geode-core/src/main/java/org/apache/geode/management/internal/cli/functions/RegionFunctionArgs.java +++ b/geode-core/src/main/java/org/apache/geode/management/internal/cli/functions/RegionFunctionArgs.java @@ -77,6 +77,8 @@ public class RegionFunctionArgs implements Serializable { private Boolean offHeap; private final boolean isSetOffHeap; private RegionAttributes<?, ?> regionAttributes; + private final boolean isPartitionResolver; + private String partitionResolver; public RegionFunctionArgs(String regionPath, RegionShortcut regionShortcut, String useAttributesFrom, boolean skipIfExists, String keyConstraint, String valueConstraint, @@ -90,7 +92,7 @@ public class RegionFunctionArgs implements Serializable { Integer concurrencyLevel, String prColocatedWith, Integer prLocalMaxMemory, Long prRecoveryDelay, Integer prRedundantCopies, Long prStartupRecoveryDelay, Long prTotalMaxMemory, Integer prTotalNumBuckets, Integer evictionMax, String compressor, - Boolean offHeap, Boolean mcastEnabled) { + Boolean offHeap, Boolean mcastEnabled, final String partitionResolver) { this.regionPath = regionPath; this.regionShortcut = regionShortcut; this.useAttributesFrom = useAttributesFrom; @@ -155,8 +157,9 @@ public class RegionFunctionArgs implements Serializable { if (this.isSetConcurrencyLevel) { this.concurrencyLevel = concurrencyLevel; } - this.partitionArgs = new PartitionArgs(prColocatedWith, prLocalMaxMemory, prRecoveryDelay, - prRedundantCopies, prStartupRecoveryDelay, prTotalMaxMemory, prTotalNumBuckets); + this.partitionArgs = + new PartitionArgs(prColocatedWith, prLocalMaxMemory, prRecoveryDelay, prRedundantCopies, + prStartupRecoveryDelay, prTotalMaxMemory, prTotalNumBuckets, partitionResolver); this.isSetCompressor = (compressor != null); if (this.isSetCompressor) { @@ -166,6 +169,10 @@ public class RegionFunctionArgs implements Serializable { if (this.isSetOffHeap) { this.offHeap = offHeap; } + this.isPartitionResolver = (partitionResolver != null); + if (this.isPartitionResolver) { + this.partitionResolver = partitionResolver; + } } // Constructor to be used for supplied region attributes @@ -181,7 +188,7 @@ public class RegionFunctionArgs implements Serializable { Integer concurrencyLevel, String prColocatedWith, Integer prLocalMaxMemory, Long prRecoveryDelay, Integer prRedundantCopies, Long prStartupRecoveryDelay, Long prTotalMaxMemory, Integer prTotalNumBuckets, Boolean offHeap, Boolean mcastEnabled, - RegionAttributes<?, ?> regionAttributes) { + RegionAttributes<?, ?> regionAttributes, final String partitionResolver) { this(regionPath, null, useAttributesFrom, skipIfExists, keyConstraint, valueConstraint, statisticsEnabled, entryExpirationIdleTime, entryExpirationTTL, regionExpirationIdleTime, regionExpirationTTL, diskStore, diskSynchronous, enableAsyncConflation, @@ -189,7 +196,7 @@ public class RegionFunctionArgs implements Serializable { gatewaySenderIds, concurrencyChecksEnabled, cloningEnabled, concurrencyLevel, prColocatedWith, prLocalMaxMemory, prRecoveryDelay, prRedundantCopies, prStartupRecoveryDelay, prTotalMaxMemory, prTotalNumBuckets, null, null, offHeap, - mcastEnabled); + mcastEnabled, partitionResolver); this.regionAttributes = regionAttributes; } @@ -387,6 +394,20 @@ public class RegionFunctionArgs implements Serializable { } /** + * @return the PartitionResolver + */ + public String getPartitionResolver() { + return this.partitionResolver; + } + + /** + * @return True if Partition Resolver is set otherwise False + */ + public Boolean isPartitionResolverSet() { + return this.isPartitionResolver; + } + + /** * @return the concurrencyChecksEnabled */ public Boolean isConcurrencyChecksEnabled() { @@ -590,13 +611,15 @@ public class RegionFunctionArgs implements Serializable { private final boolean isSetPRTotalMaxMemory; private int prTotalNumBuckets; private final boolean isSetPRTotalNumBuckets; + private final boolean isPartitionResolver; + private String partitionResolver; private boolean hasPartitionAttributes; private final Set<String> userSpecifiedPartitionAttributes = new HashSet<String>(); public PartitionArgs(String prColocatedWith, Integer prLocalMaxMemory, Long prRecoveryDelay, Integer prRedundantCopies, Long prStartupRecoveryDelay, Long prTotalMaxMemory, - Integer prTotalNumBuckets) { + Integer prTotalNumBuckets, String partitionResolver) { this.prColocatedWith = prColocatedWith; if (this.prColocatedWith != null) { this.hasPartitionAttributes = true; @@ -638,6 +661,13 @@ public class RegionFunctionArgs implements Serializable { this.hasPartitionAttributes = true; userSpecifiedPartitionAttributes.add(CliStrings.CREATE_REGION__TOTALNUMBUCKETS); } + this.isPartitionResolver = partitionResolver != null; + if (this.isPartitionResolver) { + this.partitionResolver = partitionResolver; + this.hasPartitionAttributes = true; + userSpecifiedPartitionAttributes.add(CliStrings.CREATE_REGION__PARTITION_RESOLVER); + } + } /** http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/95ad1643/geode-core/src/main/java/org/apache/geode/management/internal/cli/i18n/CliStrings.java ---------------------------------------------------------------------- diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/cli/i18n/CliStrings.java b/geode-core/src/main/java/org/apache/geode/management/internal/cli/i18n/CliStrings.java index 3aa6db1..9aaef4d 100644 --- a/geode-core/src/main/java/org/apache/geode/management/internal/cli/i18n/CliStrings.java +++ b/geode-core/src/main/java/org/apache/geode/management/internal/cli/i18n/CliStrings.java @@ -1006,6 +1006,27 @@ public class CliStrings { public static final String CREATE_REGION__OFF_HEAP__HELP = "Causes the values of the region to be stored in off-heap memory. The default is on heap."; + public static final String CREATE_REGION__PARTITION_RESOLVER = "partition-resolver"; + public static final String CREATE_REGION__PARTITION_RESOLVER__HELP = + "The fully-qualified class name of the region's partition resolver"; + public static final String CREATE_REGION__MSG__PARTITION_RESOLVER_ONLY_FOR_REGION_TYPE_PARTITION = + "partition resolver property is only applicable to PARTITION region type"; + + public static final String CREATE_REGION_PARTITION_RESOLVER__MSG__COULDNOT_FIND_CLASS_0_SPECIFIED_FOR_1 = + "Could not find class \"{0}\" specified for \"{1}\"."; + + public static final String CREATE_REGION__MSG__PARTITION_RESOLVER__CLASS_0_SPECIFIED_FOR_1_IS_NOT_OF_EXPECTED_TYPE = + "Class \"{0}\" specified for \"{1}\" is not of an expected type."; + + public static final String CREATE_REGION__MSG__PARTITION_RESOLVER__COULDNOT_INSTANTIATE_CLASS_0_SPECIFIED_FOR_1 = + "Could not instantiate class \"{0}\" specified for \"{1}\"."; + + public static final String CREATE_REGION__MSG__PARTITION_RESOLVER__COULDNOT_ACCESS_CLASS_0_SPECIFIED_FOR_1 = + "Could not access class \"{0}\" specified for \"{1}\"."; + + public static final String CREATE_REGION__MSG__INVALID_PARTITION_RESOLVER = + "{0} is an invalid Partition Resolver."; + /* debug command */ public static final String DEBUG = "debug"; public static final String DEBUG__HELP = "Enable/Disable debugging output in GFSH."; http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/95ad1643/geode-core/src/main/java/org/apache/geode/redis/internal/RegionProvider.java ---------------------------------------------------------------------- diff --git a/geode-core/src/main/java/org/apache/geode/redis/internal/RegionProvider.java b/geode-core/src/main/java/org/apache/geode/redis/internal/RegionProvider.java index 07e313b..5994d7d 100644 --- a/geode-core/src/main/java/org/apache/geode/redis/internal/RegionProvider.java +++ b/geode-core/src/main/java/org/apache/geode/redis/internal/RegionProvider.java @@ -405,7 +405,7 @@ public class RegionProvider implements Closeable { Result result = cliCmds.createRegion(key, defaultRegionType, null, null, true, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, - null); + null, null); r = cache.getRegion(key); if (result.getStatus() == Status.ERROR && r == null) { String err = ""; http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/95ad1643/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/CreateAlterDestroyRegionCommandsDUnitTest.java ---------------------------------------------------------------------- diff --git a/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/CreateAlterDestroyRegionCommandsDUnitTest.java b/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/CreateAlterDestroyRegionCommandsDUnitTest.java index 9e3b804..4896ead 100644 --- a/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/CreateAlterDestroyRegionCommandsDUnitTest.java +++ b/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/CreateAlterDestroyRegionCommandsDUnitTest.java @@ -35,17 +35,12 @@ import javax.management.MBeanServer; import javax.management.MalformedObjectNameException; import javax.management.ObjectName; +import org.apache.geode.cache.*; import org.junit.Ignore; import org.junit.Test; import org.junit.experimental.categories.Category; -import org.apache.geode.cache.Cache; -import org.apache.geode.cache.PartitionAttributesFactory; -import org.apache.geode.cache.Region; -import org.apache.geode.cache.RegionAttributes; -import org.apache.geode.cache.RegionFactory; -import org.apache.geode.cache.RegionShortcut; -import org.apache.geode.cache.Scope; +import org.apache.geode.internal.cache.PartitionedRegion; import org.apache.geode.cache.asyncqueue.AsyncEvent; import org.apache.geode.cache.asyncqueue.AsyncEventListener; import org.apache.geode.cache.wan.GatewaySenderFactory; @@ -1091,6 +1086,126 @@ public class CreateAlterDestroyRegionCommandsDUnitTest extends CliCommandTestBas }); } + + final String PR_STRING = " package com.cadrdunit;" + + " public class TestPartitionResolver implements org.apache.geode.cache.PartitionResolver { " + + " @Override" + " public void close() {" + " }" + " @Override" + + " public Object getRoutingObject(org.apache.geode.cache.EntryOperation opDetails) { " + + " return null; " + " }" + " @Override" + " public String getName() { " + + " return \"TestPartitionResolver\";" + " }" + " }"; + + /** + * Test Description 1. Deploy a JAR with Custom Partition Resolver 2. Create Region with Partition + * Resolver 3. Region should get created with no Errors 4. Verify Region Partition Attributes for + * Partition Resolver + * + * @throws IOException + */ + @Test + public void testCreateRegionWithPartitionResolver() throws IOException { + setUpJmxManagerOnVm0ThenConnect(null); + VM vm = Host.getHost(0).getVM(1); + // Create a cache in vm 1 + vm.invoke(() -> { + assertNotNull(getCache()); + }); + + ClassBuilder classBuilder = new ClassBuilder(); + // classBuilder.addToClassPath("."); + final File prJarFile = new File(new File(".").getAbsolutePath(), "myPartitionResolver.jar"); + this.filesToBeDeleted.add(prJarFile.getAbsolutePath()); + byte[] jarBytes = + classBuilder.createJarFromClassContent("com/cadrdunit/TestPartitionResolver", PR_STRING); + writeJarBytesToFile(prJarFile, jarBytes); + + CommandResult cmdResult = executeCommand("deploy --jar=myPartitionResolver.jar"); + assertEquals(Result.Status.OK, cmdResult.getStatus()); + + + // Create a region with an unrecognized compressor + CommandStringBuilder commandStringBuilder = new CommandStringBuilder(CliStrings.CREATE_REGION); + commandStringBuilder.addOption(CliStrings.CREATE_REGION__REGION, "regionWithPartitionResolver"); + commandStringBuilder.addOption(CliStrings.CREATE_REGION__REGIONSHORTCUT, "PARTITION"); + commandStringBuilder.addOption(CliStrings.CREATE_REGION__PARTITION_RESOLVER, + "com.cadrdunit.TestPartitionResolver"); + CommandResult cmdResult1 = executeCommand(commandStringBuilder.toString()); + assertEquals(Result.Status.OK, cmdResult1.getStatus()); + + // Assert that our region was not created + vm.invoke(() -> { + Region region = getCache().getRegion("regionWithPartitionResolver"); + assertNotNull(region); + + PartitionedRegion pr = (PartitionedRegion) region; + PartitionAttributes partitionAttributes = pr.getPartitionAttributes(); + assertNotNull(partitionAttributes); + PartitionResolver partitionResolver = partitionAttributes.getPartitionResolver(); + assertNotNull(partitionResolver); + assertEquals("TestPartitionResolver", partitionResolver.getName()); + }); + + vm.invoke(() -> { + getCache().getRegion("regionWithPartitionResolver").destroyRegion(); + }); + } + + @Test + public void testCreateRegionWithInvalidPartitionResolver() { + setUpJmxManagerOnVm0ThenConnect(null); + VM vm = Host.getHost(0).getVM(1); + // Create a cache in vm 1 + vm.invoke(() -> { + assertNotNull(getCache()); + }); + + // Create a region with an unrecognized compressor + CommandStringBuilder commandStringBuilder = new CommandStringBuilder(CliStrings.CREATE_REGION); + commandStringBuilder.addOption(CliStrings.CREATE_REGION__REGION, + "testCreateRegionWithInvalidPartitionResolver"); + commandStringBuilder.addOption(CliStrings.CREATE_REGION__REGIONSHORTCUT, "PARTITION"); + commandStringBuilder.addOption(CliStrings.CREATE_REGION__PARTITION_RESOLVER, "a.b.c.d"); + CommandResult cmdResult = executeCommand(commandStringBuilder.toString()); + assertEquals(Result.Status.ERROR, cmdResult.getStatus()); + + // Assert that our region was not created + vm.invoke(() -> { + Region region = getCache().getRegion("testCreateRegionWithInvalidPartitionResolver"); + assertNull(region); + }); + } + + /** + * Test Description Try creating region of type REPLICATED and specify partition resolver Region + * Creation should fail. + */ + @Test + public void testCreateRegionForReplicatedRegionWithParitionResolver() { + setUpJmxManagerOnVm0ThenConnect(null); + VM vm = Host.getHost(0).getVM(1); + // Create a cache in vm 1 + vm.invoke(() -> { + assertNotNull(getCache()); + }); + + // Create a region with an unrecognized compressor + CommandStringBuilder commandStringBuilder = new CommandStringBuilder(CliStrings.CREATE_REGION); + commandStringBuilder.addOption(CliStrings.CREATE_REGION__REGION, + "testCreateRegionForReplicatedRegionWithParitionResolver"); + commandStringBuilder.addOption(CliStrings.CREATE_REGION__REGIONSHORTCUT, "REPLICATE"); + commandStringBuilder.addOption(CliStrings.CREATE_REGION__PARTITION_RESOLVER, "a.b.c.d"); + CommandResult cmdResult = executeCommand(commandStringBuilder.toString()); + System.out.println("Result --> " + cmdResult); + assertEquals(Result.Status.ERROR, cmdResult.getStatus()); + + // Assert that our region was not created + vm.invoke(() -> { + Region region = + getCache().getRegion("testCreateRegionForReplicatedRegionWithParitionResolver"); + assertNull(region); + }); + } + + @Override protected final void preTearDownCliCommandTestBase() throws Exception { for (String path : this.filesToBeDeleted) { http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/95ad1643/geode-core/src/test/resources/org/apache/geode/management/internal/cli/commands/golden-help-offline.properties ---------------------------------------------------------------------- diff --git a/geode-core/src/test/resources/org/apache/geode/management/internal/cli/commands/golden-help-offline.properties b/geode-core/src/test/resources/org/apache/geode/management/internal/cli/commands/golden-help-offline.properties index 7ee735b..f08a257 100644 --- a/geode-core/src/test/resources/org/apache/geode/management/internal/cli/commands/golden-help-offline.properties +++ b/geode-core/src/test/resources/org/apache/geode/management/internal/cli/commands/golden-help-offline.properties @@ -885,10 +885,11 @@ SYNTAX\n\ \ \ \ \ [--entry-idle-time-expiration-action=value] [--entry-time-to-live-expiration=value]\n\ \ \ \ \ [--entry-time-to-live-expiration-action=value] [--gateway-sender-id=value(,value)*]\n\ \ \ \ \ [--key-constraint=value] [--local-max-memory=value] [--off-heap(=value)?]\n\ -\ \ \ \ [--region-idle-time-expiration=value] [--region-idle-time-expiration-action=value]\n\ -\ \ \ \ [--region-time-to-live-expiration=value] [--region-time-to-live-expiration-action=value]\n\ -\ \ \ \ [--recovery-delay=value] [--redundant-copies=value] [--startup-recovery-delay=value]\n\ -\ \ \ \ [--total-max-memory=value] [--total-num-buckets=value] [--value-constraint=value]\n\ +\ \ \ \ [--partition-resolver=value] [--region-idle-time-expiration=value]\n\ +\ \ \ \ [--region-idle-time-expiration-action=value] [--region-time-to-live-expiration=value]\n\ +\ \ \ \ [--region-time-to-live-expiration-action=value] [--recovery-delay=value]\n\ +\ \ \ \ [--redundant-copies=value] [--startup-recovery-delay=value] [--total-max-memory=value]\n\ +\ \ \ \ [--total-num-buckets=value] [--value-constraint=value]\n\ PARAMETERS\n\ \ \ \ \ name\n\ \ \ \ \ \ \ \ \ Name/Path of the region to be created.\n\ @@ -1005,6 +1006,9 @@ PARAMETERS\n\ \ \ \ \ \ \ \ \ Causes the values of the region to be stored in off-heap memory. The default is on heap.\n\ \ \ \ \ \ \ \ \ Required: false\n\ \ \ \ \ \ \ \ \ Default (if the parameter is specified without value): true\n\ +\ \ \ \ partition-resolver\n\ +\ \ \ \ \ \ \ \ The fully-qualified class name of the region's partition resolver\n\ +\ \ \ \ \ \ \ \ Required: false\n\ \ \ \ \ region-idle-time-expiration\n\ \ \ \ \ \ \ \ \ How long the region can remain in the cache without being accessed. The default is no\n\ \ \ \ \ \ \ \ \ expiration of this type.\n\
