[
https://issues.apache.org/jira/browse/GEODE-1897?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16225857#comment-16225857
]
ASF GitHub Bot commented on GEODE-1897:
---------------------------------------
jdeppe-pivotal closed pull request #969: GEODE-1897: Add eviction option to
create region
URL: https://github.com/apache/geode/pull/969
This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:
As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):
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 0555ad5fa9..ca79cf16c8 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.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 Result createRegion(
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 Result createRegion(
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 Result preExecution(GfshParseResult parseResult) {
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 d3eb5e94bc..e524c2de50 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.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 @@ private CliFunctionResult handleException(final String
memberNameOrId, final Str
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 5b278e76b2..cec4cba74f 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.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 @@
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 void setRegionExpirationTTL(Integer timeout, String
action) {
}
}
+ 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 String getCompressor() {
return this.compressor;
}
+ public EvictionAttributes getEvictionAttributes() {
+ return evictionAttributes != null ?
evictionAttributes.convertToEvictionAttributes() : null;
+ }
+
/**
* @return the regionAttributes
*/
@@ -515,6 +533,66 @@ private static ExpirationAction getExpirationAction(String
action) {
}
}
+ 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 72ef5fa0d1..69dfc31e85 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 @@
"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 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 d41588e234..2b6f86b43a 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 @@ private void doInitializeList(ByteArrayWrapper key, Region
r) {
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 86398d5ecf..58f971ae33 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 void testCompletWithRegionTypeWithNoSpace() throws
Exception {
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 eb49db0a03..5afd11298d 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 @@
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.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 13a4b89c1a..d4e9ab55d8 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.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 void
validateTemplateRegionAttributesForPartitionRedundant() throws Excep
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 4bf1532324..afb9c5e0f4 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 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 void haveBothTypeAndUseAttributeFrom() throws
Exception {
.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 void invalidEvictionAttributes() throws Exception {
.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 void missingEvictionAction() throws Exception {
}
@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 0000000000..292f51df36
--- /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 fcf70207e4..a8b2284158 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 void defaultRegionFunctionArgs() throws Exception {
assertThat(args.getConcurrencyLevel()).isNull();
assertThat(args.getPartitionArgs()).isNotNull();
assertThat(args.getPartitionArgs().hasPartitionAttributes()).isFalse();
+ assertThat(args.getEvictionAttributes()).isNull();
}
@Test
@@ -56,4 +61,36 @@ public void defaultPartitionArgs() throws Exception {
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 1c8e6674b1..8ea1efc3a8 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/lang/Boolean,entryExpirationIdleTime:org/apache/geode/management/internal/cli/functions/RegionFunctionArgs$ExpirationAttrs,entryExpirationTTL:org/apache/geode/management/internal/cli/functions/RegionFunctionArgs$ExpirationAttrs,evictionMax:java/lang/Integer,gatewaySenderIds:java/util/Set,keyConstraint:java/lang/String,mcastEnabled:java/lang/Boolean,offHeap:java/lang/Boolean,partitionArgs:org/apache/geode/management/internal/cli/functions/RegionFunctionArgs$PartitionArgs,regionAttributes:org/apache/geode/cache/RegionAttributes,regionExpirationIdleTime:org/apache/geode/management/internal/cli/functions/RegionFunctionArgs$ExpirationAttrs,regionExpirationTTL:org/apache/geode/management/internal/cli/functions/RegionFunctionArgs$ExpirationAttrs,regionPath:java/lang/String,regionShortcut:org/apache/geode/cache/RegionShortcut,skipIfExists:boolean,statisticsEnabled:java/lang/Boolean,templateRegion:java/lang/String,valueConstraint:java/lang/String
+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/lang/Boolean,entryExpirationIdleTime:org/apache/geode/management/internal/cli/functions/RegionFunctionArgs$ExpirationAttrs,entryExpirationTTL:org/apache/geode/management/internal/cli/functions/RegionFunctionArgs$ExpirationAttrs,evictionAttributes:org/apache/geode/management/internal/cli/functions/RegionFunctionArgs$EvictionAttrs,evictionMax:java/lang/Integer,gatewaySenderIds:java/util/Set,keyConstraint:java/lang/String,mcastEnabled:java/lang/Boolean,offHeap:java/lang/Boolean,partitionArgs:org/apache/geode/management/internal/cli/functions/RegionFunctionArgs$PartitionArgs,regionAttributes:org/apache/geode/cache/RegionAttributes,regionExpirationIdleTime:org/apache/geode/management/internal/cli/functions/RegionFunctionArgs$ExpirationAttrs,regionExpirationTTL:org/apache/geode/management/internal/cli/functions/RegionFunctionArgs$ExpirationAttrs,regionPath:java/lang/String,regionShortcut:org/apache/geode/cache/RegionShortcut,skipIfExists:boolean,statisticsEnabled:java/lang/Boolean,templateRegion:java/lang/String,valueConstraint:java/lang/String
+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
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
> Users should be able to configure eviction through gfsh
> -------------------------------------------------------
>
> Key: GEODE-1897
> URL: https://issues.apache.org/jira/browse/GEODE-1897
> Project: Geode
> Issue Type: Sub-task
> Components: docs, gfsh
> Reporter: Swapnil Bawaskar
> Assignee: Jens Deppe
>
> While creating a region in gfsh, users should be able to configure eviction
> for that region.
> All three modes of eviction should be supported:
> 1. Eviction driven by the resource manager:
> {noformat}
> gfsh>create region --name=myRegion --type=REPLICATE --eviction-enabled
> {noformat}
> 2. eviction driven by entry count in the region:
> {noformat}
> gfsh>create region --name=myRegion --type=REPLICATE
> --eviction-entry-count=1000
> {noformat}
> 3. eviction driven by bytes used:
> {noformat}
> gfsh>create region --name=myRegion --type=REPLICATE --eviction-max-memory=100m
> {noformat}
> And also specify the eviction action as
> {noformat}
> --eviction-action=overflow-to-disk or
> --eviction-action=destroy
> {noformat}
--
This message was sent by Atlassian JIRA
(v6.4.14#64029)