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 4e5833b GEODE-1897: Add eviction option to create region (#969)
4e5833b is described below
commit 4e5833b7ed698fd90b98d5de9d21f82ae8e3fec9
Author: Jens Deppe <[email protected]>
AuthorDate: Mon Oct 30 15:29:26 2017 -0700
GEODE-1897: Add eviction option to create region (#969)
* GEODE-1897: Add eviction option to create region
* GEODE-1897: Add object sizer capability to region creation
---
.../internal/cli/commands/CreateRegionCommand.java | 47 +++++++++++++
.../cli/functions/RegionCreateFunction.java | 6 ++
.../internal/cli/functions/RegionFunctionArgs.java | 78 ++++++++++++++++++++++
.../management/internal/cli/i18n/CliStrings.java | 27 ++++++++
.../geode/redis/internal/RegionProvider.java | 4 +-
.../internal/cli/GfshParserAutoCompletionTest.java | 2 +-
.../cli/commands/CreateRegionCommandDUnitTest.java | 26 ++++----
.../CreateRegionCommandIntegrationTest.java | 64 ++++++++++++++++++
.../cli/commands/CreateRegionCommandTest.java | 25 +++++--
.../internal/cli/commands/TestObjectSizer.java | 26 ++++++++
.../cli/functions/RegionFunctionArgsTest.java | 37 ++++++++++
.../geode/codeAnalysis/sanctionedSerializables.txt | 3 +-
12 files changed, 323 insertions(+), 22 deletions(-)
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 0555ad5..ca79cf1 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
@@ -27,6 +27,7 @@ import org.springframework.shell.core.annotation.CliCommand;
import org.springframework.shell.core.annotation.CliOption;
import org.apache.geode.cache.DataPolicy;
+import org.apache.geode.cache.EvictionAction;
import org.apache.geode.cache.Region;
import org.apache.geode.cache.RegionAttributes;
import org.apache.geode.cache.RegionShortcut;
@@ -125,6 +126,14 @@ public class CreateRegionCommand implements GfshCommand {
help = CliStrings.CREATE_REGION__ENTRYEXPIRATIONTIMETOLIVE__HELP)
Integer entryExpirationTTL,
@CliOption(key = CliStrings.CREATE_REGION__ENTRYEXPIRATIONTTLACTION,
help = CliStrings.CREATE_REGION__ENTRYEXPIRATIONTTLACTION__HELP)
String entryExpirationTTLAction,
+ @CliOption(key = CliStrings.CREATE_REGION__EVICTION_ACTION,
+ help = CliStrings.CREATE_REGION__EVICTION_ACTION__HELP) String
evictionAction,
+ @CliOption(key = CliStrings.CREATE_REGION__EVICTION_ENTRY_COUNT,
+ help = CliStrings.CREATE_REGION__EVICTION_ENTRY_COUNT__HELP) Integer
evictionEntryCount,
+ @CliOption(key = CliStrings.CREATE_REGION__EVICTION_MAX_MEMORY,
+ help = CliStrings.CREATE_REGION__EVICTION_MAX_MEMORY__HELP) Integer
evictionMaxMemory,
+ @CliOption(key = CliStrings.CREATE_REGION__EVICTION_OBJECT_SIZER,
+ help = CliStrings.CREATE_REGION__EVICTION_OBJECT_SIZER__HELP) String
evictionObjectSizer,
@CliOption(key = CliStrings.CREATE_REGION__GATEWAYSENDERID,
help = CliStrings.CREATE_REGION__GATEWAYSENDERID__HELP) String[]
gatewaySenderIds,
@CliOption(key = CliStrings.CREATE_REGION__KEYCONSTRAINT,
@@ -195,6 +204,8 @@ public class CreateRegionCommand implements GfshCommand {
functionArgs.setRegionExpirationIdleTime(regionExpirationIdleTime,
regionExpirationIdleTimeAction);
functionArgs.setRegionExpirationTTL(regionExpirationTTL,
regionExpirationTTLAction);
+ functionArgs.setEvictionAttributes(evictionAction, evictionMaxMemory,
evictionEntryCount,
+ evictionObjectSizer);
functionArgs.setDiskStore(diskStore);
functionArgs.setDiskSynchronous(diskSynchronous);
functionArgs.setEnableAsyncConflation(enableAsyncConflation);
@@ -649,6 +660,42 @@ public class CreateRegionCommand implements GfshCommand {
return ResultBuilder.createUserErrorResult(message + ".");
}
}
+
+ String maxMemory =
+
parseResult.getParamValueAsString(CliStrings.CREATE_REGION__EVICTION_MAX_MEMORY);
+ String maxEntry =
+
parseResult.getParamValueAsString(CliStrings.CREATE_REGION__EVICTION_ENTRY_COUNT);
+ String evictionAction =
+
parseResult.getParamValueAsString(CliStrings.CREATE_REGION__EVICTION_ACTION);
+ String evictionSizer =
+
parseResult.getParamValueAsString(CliStrings.CREATE_REGION__EVICTION_OBJECT_SIZER);
+ if (maxEntry != null && maxMemory != null) {
+ return ResultBuilder
+
.createUserErrorResult(CliStrings.CREATE_REGION__MSG__BOTH_EVICTION_VALUES);
+ }
+
+ if ((maxEntry != null || maxMemory != null) && evictionAction == null) {
+ return ResultBuilder
+
.createUserErrorResult(CliStrings.CREATE_REGION__MSG__MISSING_EVICTION_ACTION);
+ }
+
+ if (evictionSizer != null) {
+ if (maxEntry != null) {
+ return ResultBuilder.createUserErrorResult(
+
CliStrings.CREATE_REGION__MSG__INVALID_EVICTION_OBJECT_SIZER_AND_ENTRY_COUNT);
+ }
+ if (maxMemory == null) {
+ return ResultBuilder.createUserErrorResult(
+
CliStrings.CREATE_REGION__MSG__INVALID_EVICTION_OBJECT_SIZER_WITHOUT_MAX_MEMORY);
+ }
+ }
+
+ if (evictionAction != null
+ && EvictionAction.parseAction(evictionAction) ==
EvictionAction.NONE) {
+ return ResultBuilder
+
.createUserErrorResult(CliStrings.CREATE_REGION__MSG__INVALID_EVICTION_ACTION);
+ }
+
return ResultBuilder.createInfoResult("");
}
}
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 d3eb5e9..e524c2d 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
@@ -24,6 +24,7 @@ import org.apache.geode.cache.CacheListener;
import org.apache.geode.cache.CacheLoader;
import org.apache.geode.cache.CacheWriter;
import org.apache.geode.cache.DataPolicy;
+import org.apache.geode.cache.EvictionAttributes;
import org.apache.geode.cache.PartitionAttributes;
import org.apache.geode.cache.PartitionAttributesFactory;
import org.apache.geode.cache.PartitionResolver;
@@ -200,6 +201,11 @@ public class RegionCreateFunction implements Function,
InternalEntity {
factory.setRegionTimeToLive(regionExpirationTTL.convertToExpirationAttributes());
}
+ EvictionAttributes evictionAttributes =
regionCreateArgs.getEvictionAttributes();
+ if (evictionAttributes != null) {
+ factory.setEvictionAttributes(evictionAttributes);
+ }
+
// Associate a Disk Store
final String diskStore = regionCreateArgs.getDiskStore();
if (diskStore != null && !diskStore.isEmpty()) {
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 5b278e7..cec4cba 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
@@ -22,10 +22,14 @@ import java.util.HashSet;
import java.util.Set;
import java.util.stream.Collectors;
+import org.apache.geode.cache.EvictionAction;
+import org.apache.geode.cache.EvictionAttributes;
import org.apache.geode.cache.ExpirationAction;
import org.apache.geode.cache.ExpirationAttributes;
import org.apache.geode.cache.RegionAttributes;
import org.apache.geode.cache.RegionShortcut;
+import org.apache.geode.cache.util.ObjectSizer;
+import org.apache.geode.internal.ClassPathLoader;
import org.apache.geode.management.internal.cli.i18n.CliStrings;
/**
@@ -48,6 +52,7 @@ public class RegionFunctionArgs implements Serializable {
private RegionFunctionArgs.ExpirationAttrs entryExpirationTTL;
private RegionFunctionArgs.ExpirationAttrs regionExpirationIdleTime;
private RegionFunctionArgs.ExpirationAttrs regionExpirationTTL;
+ private RegionFunctionArgs.EvictionAttrs evictionAttributes;
private String diskStore;
private Boolean diskSynchronous;
private Boolean enableAsyncConflation;
@@ -128,6 +133,15 @@ public class RegionFunctionArgs implements Serializable {
}
}
+ public void setEvictionAttributes(String action, Integer maxMemory, Integer
maxEntryCount,
+ String objectSizer) {
+ if (action == null) {
+ return;
+ }
+
+ this.evictionAttributes = new EvictionAttrs(action, maxEntryCount,
maxMemory, objectSizer);
+ }
+
public void setDiskStore(String diskStore) {
this.diskStore = diskStore;
}
@@ -429,6 +443,10 @@ public class RegionFunctionArgs implements Serializable {
return this.compressor;
}
+ public EvictionAttributes getEvictionAttributes() {
+ return evictionAttributes != null ?
evictionAttributes.convertToEvictionAttributes() : null;
+ }
+
/**
* @return the regionAttributes
*/
@@ -515,6 +533,66 @@ public class RegionFunctionArgs implements Serializable {
}
}
+ public static class EvictionAttrs implements Serializable {
+ private static final long serialVersionUID = 9015454906371076014L;
+
+ private String evictionAction;
+ private Integer maxEntryCount;
+ private Integer maxMemory;
+ private String objectSizer;
+
+ public EvictionAttrs(String evictionAction, Integer maxEntryCount, Integer
maxMemory,
+ String objectSizer) {
+ this.evictionAction = evictionAction;
+ this.maxEntryCount = maxEntryCount;
+ this.maxMemory = maxMemory;
+ this.objectSizer = objectSizer;
+ }
+
+ public String getEvictionAction() {
+ return evictionAction;
+ }
+
+ public Integer getMaxEntryCount() {
+ return maxEntryCount;
+ }
+
+ public Integer getMaxMemory() {
+ return maxMemory;
+ }
+
+ public String getObjectSizer() {
+ return objectSizer;
+ }
+
+ public EvictionAttributes convertToEvictionAttributes() {
+ EvictionAction action = EvictionAction.parseAction(evictionAction);
+
+ ObjectSizer sizer;
+ if (objectSizer != null) {
+ try {
+ Class<ObjectSizer> sizerClass =
+ (Class<ObjectSizer>)
ClassPathLoader.getLatest().forName(objectSizer);
+ sizer = sizerClass.newInstance();
+ } catch (ClassNotFoundException | InstantiationException |
IllegalAccessException e) {
+ throw new IllegalArgumentException(
+ "Unable to instantiate class " + objectSizer + " - " +
e.toString());
+ }
+ } else {
+ sizer = ObjectSizer.DEFAULT;
+ }
+
+ if (maxMemory == null && maxEntryCount == null) {
+ return EvictionAttributes.createLRUHeapAttributes(sizer, action);
+ } else if (maxMemory != null) {
+ return EvictionAttributes.createLRUMemoryAttributes(maxMemory, sizer,
action);
+ } else {
+ return EvictionAttributes.createLRUEntryAttributes(maxEntryCount,
action);
+ }
+ }
+ }
+
+
public static class PartitionArgs implements Serializable {
private static final long serialVersionUID = 5907052187323280919L;
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 72ef5fa..69dfc31 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
@@ -861,6 +861,18 @@ public class CliStrings {
"region-time-to-live-expiration-action";
public static final String CREATE_REGION__REGIONEXPIRATIONTTLACTION__HELP =
"Action to be taken on a region that has exceeded the TTL expiration.";
+ public static final String CREATE_REGION__EVICTION_ACTION =
"eviction-action";
+ public static final String CREATE_REGION__EVICTION_ACTION__HELP =
+ "The eviction action to apply. Must be either 'local-destroy' or
'overflow-to-disk'";
+ public static final String CREATE_REGION__EVICTION_MAX_MEMORY =
"eviction-max-memory";
+ public static final String CREATE_REGION__EVICTION_MAX_MEMORY__HELP =
+ "Activates LRU eviction based on the region's memory usage specified by
this value.";
+ public static final String CREATE_REGION__EVICTION_ENTRY_COUNT =
"eviction-entry-count";
+ public static final String CREATE_REGION__EVICTION_ENTRY_COUNT__HELP =
+ "Activates LRU eviction based on the region's entry count specified by
this value.";
+ public static final String CREATE_REGION__EVICTION_OBJECT_SIZER =
"eviction-object-sizer";
+ public static final String CREATE_REGION__EVICTION_OBJECT_SIZER__HELP =
+ "A custom class which implements ObjectSizer in order to perform max
memory eviction.";
public static final String CREATE_REGION__DISKSTORE = "disk-store";
public static final String CREATE_REGION__DISKSTORE__HELP =
"Disk Store to be used by this region. \"list disk-store\" can be used
to display existing disk stores.";
@@ -1041,6 +1053,21 @@ public class CliStrings {
public static final String CREATE_REGION__MSG__INVALID_PARTITION_RESOLVER =
"{0} is an invalid Partition Resolver.";
+ public static final String CREATE_REGION__MSG__BOTH_EVICTION_VALUES =
+ "eviction-max-memory and eviction-entry-count cannot both be specified.";
+
+ public static final String CREATE_REGION__MSG__MISSING_EVICTION_ACTION =
+ "eviction-action must be specified.";
+
+ public static final String CREATE_REGION__MSG__INVALID_EVICTION_ACTION =
+ "eviction-action must be 'local-destroy' or 'overflow-to-disk'";
+
+ public static final String
CREATE_REGION__MSG__INVALID_EVICTION_OBJECT_SIZER_AND_ENTRY_COUNT =
+ "eviction-object-sizer cannot be specified with eviction-entry-count";
+
+ public static final String
CREATE_REGION__MSG__INVALID_EVICTION_OBJECT_SIZER_WITHOUT_MAX_MEMORY =
+ "eviction-object-sizer cannot be specified without eviction-max-memory";
+
/* debug command */
public static final String DEBUG = "debug";
public static final String DEBUG__HELP = "Enable/Disable debugging output in
GFSH.";
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 d41588e..2b6f86b 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
@@ -401,8 +401,8 @@ public class RegionProvider implements Closeable {
do {
Result result = createRegionCmd.createRegion(key, defaultRegionType,
null, null, true, null,
null, null, null, null, null, null, null, false, false, true, false,
false, false, true,
- null, null, null, null, null, null, null, false, null, null, null,
null, null, null, null,
- null, null, null, null);
+ null, null, null, null, null, null, null, null, null, null, null,
false, null, null, null,
+ null, null, null, null, null, null, null, null);
r = cache.getRegion(key);
if (result.getStatus() == Status.ERROR && r == null) {
diff --git
a/geode-core/src/test/java/org/apache/geode/management/internal/cli/GfshParserAutoCompletionTest.java
b/geode-core/src/test/java/org/apache/geode/management/internal/cli/GfshParserAutoCompletionTest.java
index 86398d5..58f971a 100644
---
a/geode-core/src/test/java/org/apache/geode/management/internal/cli/GfshParserAutoCompletionTest.java
+++
b/geode-core/src/test/java/org/apache/geode/management/internal/cli/GfshParserAutoCompletionTest.java
@@ -246,7 +246,7 @@ public class GfshParserAutoCompletionTest {
public void testCompletWithRegionTypeWithSpace() throws Exception {
buffer = "create region --name=test --type=REPLICATE ";
candidate = parser.complete(buffer);
- assertThat(candidate.size()).isEqualTo(38);
+ assertThat(candidate.size()).isEqualTo(42);
assertThat(candidate.getFirstCandidate()).isEqualTo(buffer +
"--async-event-queue-id");
}
diff --git
a/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/CreateRegionCommandDUnitTest.java
b/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/CreateRegionCommandDUnitTest.java
index eb49db0..5afd112 100644
---
a/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/CreateRegionCommandDUnitTest.java
+++
b/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/CreateRegionCommandDUnitTest.java
@@ -17,6 +17,19 @@ package org.apache.geode.management.internal.cli.commands;
import static org.assertj.core.api.Assertions.assertThat;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.OutputStream;
+
+import org.json.JSONArray;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+import org.junit.rules.TemporaryFolder;
+import org.junit.rules.TestName;
+
import org.apache.geode.cache.Cache;
import org.apache.geode.cache.PartitionResolver;
import org.apache.geode.cache.Region;
@@ -31,19 +44,6 @@ import
org.apache.geode.test.junit.categories.DistributedTest;
import org.apache.geode.test.junit.rules.GfshShellConnectionRule;
import org.apache.geode.test.junit.rules.serializable.SerializableTestName;
-import org.json.JSONArray;
-import org.junit.Before;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
-import org.junit.rules.TemporaryFolder;
-import org.junit.rules.TestName;
-
-import java.io.File;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.OutputStream;
-
@Category(DistributedTest.class)
public class CreateRegionCommandDUnitTest {
diff --git
a/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/CreateRegionCommandIntegrationTest.java
b/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/CreateRegionCommandIntegrationTest.java
index 13a4b89..d4e9ab5 100644
---
a/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/CreateRegionCommandIntegrationTest.java
+++
b/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/CreateRegionCommandIntegrationTest.java
@@ -26,6 +26,9 @@ import org.junit.Rule;
import org.junit.Test;
import org.junit.experimental.categories.Category;
+import org.apache.geode.cache.EvictionAction;
+import org.apache.geode.cache.EvictionAlgorithm;
+import org.apache.geode.cache.EvictionAttributes;
import org.apache.geode.cache.ExpirationAction;
import org.apache.geode.cache.ExpirationAttributes;
import org.apache.geode.cache.Region;
@@ -490,4 +493,65 @@ public class CreateRegionCommandIntegrationTest {
gfsh.executeAndAssertThat("destroy region --name=/COPY").statusIsSuccess();
gfsh.executeAndAssertThat("destroy region
--name=/TEMPLATE").statusIsSuccess();
}
+
+ @Test
+ public void testEvictionAttributesForLRUHeap() throws Exception {
+ gfsh.executeAndVerifyCommand(
+ "create region --name=FOO --type=REPLICATE
--eviction-action=local-destroy");
+
+ Region foo = server.getCache().getRegion("/FOO");
+ assertThat(foo.getAttributes().getEvictionAttributes().getAction())
+ .isEqualTo(EvictionAction.LOCAL_DESTROY);
+ assertThat(foo.getAttributes().getEvictionAttributes().getAlgorithm())
+ .isEqualTo(EvictionAlgorithm.LRU_HEAP);
+
+ gfsh.executeAndVerifyCommand("destroy region --name=/FOO");
+ }
+
+ @Test
+ public void testEvictionAttributesForLRUEntry() throws Exception {
+ gfsh.executeAndVerifyCommand(
+ "create region --name=FOO --type=REPLICATE --eviction-entry-count=1001
--eviction-action=overflow-to-disk");
+
+ Region foo = server.getCache().getRegion("/FOO");
+ assertThat(foo.getAttributes().getEvictionAttributes().getAction())
+ .isEqualTo(EvictionAction.OVERFLOW_TO_DISK);
+ assertThat(foo.getAttributes().getEvictionAttributes().getAlgorithm())
+ .isEqualTo(EvictionAlgorithm.LRU_ENTRY);
+
assertThat(foo.getAttributes().getEvictionAttributes().getMaximum()).isEqualTo(1001);
+
+ gfsh.executeAndVerifyCommand("destroy region --name=/FOO");
+ }
+
+ @Test
+ public void testEvictionAttributesForLRUMemory() throws Exception {
+ gfsh.executeAndVerifyCommand(
+ "create region --name=FOO --type=REPLICATE --eviction-max-memory=1001
--eviction-action=overflow-to-disk");
+
+ Region foo = server.getCache().getRegion("/FOO");
+ assertThat(foo.getAttributes().getEvictionAttributes().getAction())
+ .isEqualTo(EvictionAction.OVERFLOW_TO_DISK);
+ assertThat(foo.getAttributes().getEvictionAttributes().getAlgorithm())
+ .isEqualTo(EvictionAlgorithm.LRU_MEMORY);
+
assertThat(foo.getAttributes().getEvictionAttributes().getMaximum()).isEqualTo(1001);
+
+ gfsh.executeAndVerifyCommand("destroy region --name=/FOO");
+ }
+
+ @Test
+ public void testEvictionAttributesForSizer() throws Exception {
+ gfsh.executeAndVerifyCommand(
+ "create region --name=FOO --type=REPLICATE --eviction-max-memory=1001
--eviction-action=overflow-to-disk --eviction-object-sizer="
+ + TestObjectSizer.class.getName());
+
+ Region foo = server.getCache().getRegion("/FOO");
+ EvictionAttributes attrs = foo.getAttributes().getEvictionAttributes();
+ assertThat(attrs.getAction()).isEqualTo(EvictionAction.OVERFLOW_TO_DISK);
+ assertThat(attrs.getAlgorithm()).isEqualTo(EvictionAlgorithm.LRU_MEMORY);
+ assertThat(attrs.getMaximum()).isEqualTo(1001);
+ assertThat(attrs.getObjectSizer().getClass().getName())
+ .isEqualTo(TestObjectSizer.class.getName());
+
+ gfsh.executeAndVerifyCommand("destroy region --name=/FOO");
+ }
}
diff --git
a/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/CreateRegionCommandTest.java
b/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/CreateRegionCommandTest.java
index 4bf1532..afb9c5e 100644
---
a/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/CreateRegionCommandTest.java
+++
b/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/CreateRegionCommandTest.java
@@ -27,7 +27,6 @@ import static org.mockito.Mockito.when;
import java.util.Collections;
import org.junit.Before;
-import org.junit.Ignore;
import org.junit.Rule;
import org.junit.Test;
import org.junit.experimental.categories.Category;
@@ -89,16 +88,15 @@ public class CreateRegionCommandTest {
.contains("Only one of type & template-region can be specified.");
}
- @Ignore("Eviction is not configurable yet")
@Test
public void invalidEvictionAction() throws Exception {
CommandResult result = parser.executeCommandWithInstance(command,
"create region --name=region --type=REPLICATE
--eviction-action=invalidAction");
assertThat(result.getStatus()).isEqualTo(Result.Status.ERROR);
- assertThat(result.getContent().toString()).contains("Invalid command");
+ assertThat(result.getContent().toString())
+ .contains("eviction-action must be 'local-destroy' or
'overflow-to-disk'");
}
- @Ignore("Eviction is not configurable yet")
@Test
public void invalidEvictionAttributes() throws Exception {
CommandResult result = parser.executeCommandWithInstance(command,
@@ -108,7 +106,6 @@ public class CreateRegionCommandTest {
.contains("eviction-max-memory and eviction-entry-count cannot both be
specified.");
}
- @Ignore("Eviction is not configurable yet")
@Test
public void missingEvictionAction() throws Exception {
CommandResult result = parser.executeCommandWithInstance(command,
@@ -118,6 +115,24 @@ public class CreateRegionCommandTest {
}
@Test
+ public void invalidEvictionSizerAndCount() throws Exception {
+ CommandResult result = parser.executeCommandWithInstance(command,
+ "create region --name=region --type=REPLICATE --eviction-entry-count=1
--eviction-object-sizer=abc --eviction-action=local-destroy");
+ assertThat(result.getStatus()).isEqualTo(Result.Status.ERROR);
+ assertThat(result.getContent().toString())
+ .contains("eviction-object-sizer cannot be specified with
eviction-entry-count");
+ }
+
+ @Test
+ public void invalidEvictionSizerWithoutMemory() throws Exception {
+ CommandResult result = parser.executeCommandWithInstance(command,
+ "create region --name=region --type=REPLICATE
--eviction-object-sizer=abc --eviction-action=local-destroy");
+ assertThat(result.getStatus()).isEqualTo(Result.Status.ERROR);
+ assertThat(result.getContent().toString())
+ .contains("eviction-object-sizer cannot be specified without
eviction-max-memory");
+ }
+
+ @Test
public void templateRegionAttributesNotAvailable() throws Exception {
doReturn(null).when(command).getRegionAttributes(eq(cache), any());
doReturn(Collections.emptySet()).when(command).findMembers(any(), any());
diff --git
a/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/TestObjectSizer.java
b/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/TestObjectSizer.java
new file mode 100644
index 0000000..292f51d
--- /dev/null
+++
b/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/TestObjectSizer.java
@@ -0,0 +1,26 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
contributor license
+ * agreements. See the NOTICE file distributed with this work for additional
information regarding
+ * copyright ownership. The ASF licenses this file to You under the Apache
License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
License. You may obtain a
+ * copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
distributed under the License
+ * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express
+ * or implied. See the License for the specific language governing permissions
and limitations under
+ * the License.
+ */
+
+package org.apache.geode.management.internal.cli.commands;
+
+import org.apache.geode.cache.Declarable;
+import org.apache.geode.cache.util.ObjectSizer;
+
+public class TestObjectSizer implements ObjectSizer, Declarable {
+ @Override
+ public int sizeof(Object o) {
+ return 77;
+ }
+}
diff --git
a/geode-core/src/test/java/org/apache/geode/management/internal/cli/functions/RegionFunctionArgsTest.java
b/geode-core/src/test/java/org/apache/geode/management/internal/cli/functions/RegionFunctionArgsTest.java
index fcf7020..a8b2284 100644
---
a/geode-core/src/test/java/org/apache/geode/management/internal/cli/functions/RegionFunctionArgsTest.java
+++
b/geode-core/src/test/java/org/apache/geode/management/internal/cli/functions/RegionFunctionArgsTest.java
@@ -16,11 +16,15 @@
package org.apache.geode.management.internal.cli.functions;
import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
import org.junit.Before;
import org.junit.Test;
import org.junit.experimental.categories.Category;
+import org.apache.geode.cache.EvictionAction;
+import org.apache.geode.cache.EvictionAlgorithm;
+import org.apache.geode.cache.EvictionAttributes;
import org.apache.geode.test.junit.categories.UnitTest;
@Category(UnitTest.class)
@@ -43,6 +47,7 @@ public class RegionFunctionArgsTest {
assertThat(args.getConcurrencyLevel()).isNull();
assertThat(args.getPartitionArgs()).isNotNull();
assertThat(args.getPartitionArgs().hasPartitionAttributes()).isFalse();
+ assertThat(args.getEvictionAttributes()).isNull();
}
@Test
@@ -56,4 +61,36 @@ public class RegionFunctionArgsTest {
assertThat(partitionArgs.getPrTotalNumBuckets()).isEqualTo(10);
assertThat(partitionArgs.hasPartitionAttributes()).isTrue();
}
+
+ @Test
+ public void evictionAttributes() throws Exception {
+ args.setEvictionAttributes(null, 0, 0, null);
+ assertThat(args.getEvictionAttributes()).isNull();
+
+ args.setEvictionAttributes("local-destroy", null, null, null);
+ EvictionAttributes attributes = args.getEvictionAttributes();
+
assertThat(attributes.getAlgorithm()).isEqualTo(EvictionAlgorithm.LRU_HEAP);
+ assertThat(attributes.getAction()).isEqualTo(EvictionAction.LOCAL_DESTROY);
+ assertThatThrownBy(() -> attributes.getMaximum())
+ .hasMessageContaining("LRUHeap does not support a maximum");
+
+ args.setEvictionAttributes("overflow-to-disk", 1000, null, null);
+ EvictionAttributes attributes1 = args.getEvictionAttributes();
+
assertThat(attributes1.getAlgorithm()).isEqualTo(EvictionAlgorithm.LRU_MEMORY);
+
assertThat(attributes1.getAction()).isEqualTo(EvictionAction.OVERFLOW_TO_DISK);
+ assertThat(attributes1.getMaximum()).isEqualTo(1000);
+
+ args.setEvictionAttributes("local-destroy", null, 1000, null);
+ EvictionAttributes attributes2 = args.getEvictionAttributes();
+
assertThat(attributes2.getAlgorithm()).isEqualTo(EvictionAlgorithm.LRU_ENTRY);
+
assertThat(attributes2.getAction()).isEqualTo(EvictionAction.LOCAL_DESTROY);
+ assertThat(attributes2.getMaximum()).isEqualTo(1000);
+ }
+
+ @Test
+ public void evictionAttributesWithNullAction() throws Exception {
+ args.setEvictionAttributes(null, null, 1000, null);
+ EvictionAttributes attributes3 = args.getEvictionAttributes();
+ assertThat(attributes3).isNull();
+ }
}
diff --git
a/geode-core/src/test/resources/org/apache/geode/codeAnalysis/sanctionedSerializables.txt
b/geode-core/src/test/resources/org/apache/geode/codeAnalysis/sanctionedSerializables.txt
index 1c8e667..8ea1efc 100755
---
a/geode-core/src/test/resources/org/apache/geode/codeAnalysis/sanctionedSerializables.txt
+++
b/geode-core/src/test/resources/org/apache/geode/codeAnalysis/sanctionedSerializables.txt
@@ -545,7 +545,8 @@
org/apache/geode/management/internal/cli/functions/RebalanceFunction,true,1
org/apache/geode/management/internal/cli/functions/RegionAlterFunction,true,-4846425364943216425
org/apache/geode/management/internal/cli/functions/RegionCreateFunction,true,8746830191680509335
org/apache/geode/management/internal/cli/functions/RegionDestroyFunction,true,9172773671865750685
-org/apache/geode/management/internal/cli/functions/RegionFunctionArgs,true,2204943186081037301,asyncEventQueueIds:java/util/Set,cacheListeners:java/util/Set,cacheLoader:java/lang/String,cacheWriter:java/lang/String,cloningEnabled:java/lang/Boolean,compressor:java/lang/String,concurrencyChecksEnabled:java/lang/Boolean,concurrencyLevel:java/lang/Integer,diskStore:java/lang/String,diskSynchronous:java/lang/Boolean,enableAsyncConflation:java/lang/Boolean,enableSubscriptionConflation:java/lan
[...]
+org/apache/geode/management/internal/cli/functions/RegionFunctionArgs,true,2204943186081037301,asyncEventQueueIds:java/util/Set,cacheListeners:java/util/Set,cacheLoader:java/lang/String,cacheWriter:java/lang/String,cloningEnabled:java/lang/Boolean,compressor:java/lang/String,concurrencyChecksEnabled:java/lang/Boolean,concurrencyLevel:java/lang/Integer,diskStore:java/lang/String,diskSynchronous:java/lang/Boolean,enableAsyncConflation:java/lang/Boolean,enableSubscriptionConflation:java/lan
[...]
+org/apache/geode/management/internal/cli/functions/RegionFunctionArgs$EvictionAttrs,true,9015454906371076014,evictionAction:java/lang/String,maxEntryCount:java/lang/Integer,maxMemory:java/lang/Integer,objectSizer:java/lang/String
org/apache/geode/management/internal/cli/functions/RegionFunctionArgs$ExpirationAttrs,true,1474255033398008062,timeAndAction:org/apache/geode/cache/ExpirationAttributes,type:org/apache/geode/management/internal/cli/functions/RegionFunctionArgs$ExpirationAttrs$ExpirationFor
org/apache/geode/management/internal/cli/functions/RegionFunctionArgs$ExpirationAttrs$ExpirationFor,false
org/apache/geode/management/internal/cli/functions/RegionFunctionArgs$PartitionArgs,true,5907052187323280919,partitionResolver:java/lang/String,prColocatedWith:java/lang/String,prLocalMaxMemory:java/lang/Integer,prRecoveryDelay:java/lang/Long,prRedundantCopies:java/lang/Integer,prStartupRecoveryDelay:java/lang/Long,prTotalMaxMemory:java/lang/Long,prTotalNumBuckets:java/lang/Integer
--
To stop receiving notification emails like this one, please contact
['"[email protected]" <[email protected]>'].