You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@geode.apache.org by mm...@apache.org on 2018/11/29 23:30:15 UTC

[geode] 02/03: wip - checks that eviction attributes are not persisted when empty

This is an automated email from the ASF dual-hosted git repository.

mmartell pushed a commit to branch geode-5971-createregion
in repository https://gitbox.apache.org/repos/asf/geode.git

commit 8e50565b74586944e9fcee1e4fdeec8c8ef7e033
Author: Aditya Anchuri <aa...@pivotal.io>
AuthorDate: Wed Nov 28 14:46:11 2018 -0800

    wip - checks that eviction attributes are not persisted when empty
    
    Signed-off-by: Peter Tran <pt...@pivotal.io>
---
 ...egionCommandPersistsConfigurationDUnitTest.java | 33 ++++++++++++++++++++++
 .../org/apache/geode/cache/EvictionAttributes.java |  4 +++
 .../cache/configuration/RegionConfigFactory.java   |  4 ++-
 3 files changed, 40 insertions(+), 1 deletion(-)

diff --git a/geode-core/src/distributedTest/java/org/apache/geode/management/internal/cli/commands/CreateRegionCommandPersistsConfigurationDUnitTest.java b/geode-core/src/distributedTest/java/org/apache/geode/management/internal/cli/commands/CreateRegionCommandPersistsConfigurationDUnitTest.java
index f4ea2ce..0a0dbcc 100644
--- a/geode-core/src/distributedTest/java/org/apache/geode/management/internal/cli/commands/CreateRegionCommandPersistsConfigurationDUnitTest.java
+++ b/geode-core/src/distributedTest/java/org/apache/geode/management/internal/cli/commands/CreateRegionCommandPersistsConfigurationDUnitTest.java
@@ -379,6 +379,39 @@ public class CreateRegionCommandPersistsConfigurationDUnitTest {
   }
 
   @Test
+  public void createRegionDoesNotPersistEmptyEvictionAttributes() {
+    String regionName = testName.getMethodName();
+    gfsh.executeAndAssertThat("create region"
+        + " --name=" + regionName
+        + " --type=REPLICATE").statusIsSuccess();
+
+    locator.invoke(() -> {
+      InternalConfigurationPersistenceService cc =
+          ClusterStartupRule.getLocator().getConfigurationPersistenceService();
+      CacheConfig config = cc.getCacheConfig("cluster");
+
+      List<RegionConfig> regions = config.getRegions();
+      assertThat(regions).isNotEmpty();
+      assertThat(regions).hasSize(1);
+
+      List<String> regionNames = Arrays.asList(regionName);
+      regionNames.forEach(name -> {
+        RegionConfig regionConfig = CacheElement.findElement(config.getRegions(), name);
+        assertThat(regionConfig).isNotNull();
+        assertThat(regionConfig.getName()).isEqualTo(name);
+        assertThat(regionConfig.getRegionAttributes())
+            .describedAs("Expecting region attributes to exist")
+            .hasSize(1);
+
+        RegionAttributesType attr = regionConfig.getRegionAttributes().get(0);
+        assertThat(attr.getEvictionAttributes())
+            .describedAs("Eviction attributes should be null for " + name)
+            .isNull();
+      });
+    });
+  }
+
+  @Test
   public void placeholderAEQ() {}
 
   @Test
diff --git a/geode-core/src/main/java/org/apache/geode/cache/EvictionAttributes.java b/geode-core/src/main/java/org/apache/geode/cache/EvictionAttributes.java
index bc23920..b333b2e 100644
--- a/geode-core/src/main/java/org/apache/geode/cache/EvictionAttributes.java
+++ b/geode-core/src/main/java/org/apache/geode/cache/EvictionAttributes.java
@@ -540,4 +540,8 @@ public abstract class EvictionAttributes implements DataSerializable {
     return configAttributes;
   }
 
+  public boolean isEmpty() {
+    return getAction() == EvictionAction.NONE && getAlgorithm() == EvictionAlgorithm.NONE;
+  }
+
 }
diff --git a/geode-core/src/main/java/org/apache/geode/internal/cache/configuration/RegionConfigFactory.java b/geode-core/src/main/java/org/apache/geode/internal/cache/configuration/RegionConfigFactory.java
index 8aa98f7..c78f68b 100644
--- a/geode-core/src/main/java/org/apache/geode/internal/cache/configuration/RegionConfigFactory.java
+++ b/geode-core/src/main/java/org/apache/geode/internal/cache/configuration/RegionConfigFactory.java
@@ -226,7 +226,9 @@ public class RegionConfigFactory {
     if (args.getEvictionAttributes() != null) {
       addAttribute(regionConfig, a -> a.setEvictionAttributes(
           args.getEvictionAttributes().convertToConfigEvictionAttributes()));
-    } else if (regionAttributes != null && regionAttributes.getEvictionAttributes() != null) {
+    } else if (regionAttributes != null &&
+        regionAttributes.getEvictionAttributes() != null &&
+        !regionAttributes.getEvictionAttributes().isEmpty()) {
       addAttribute(regionConfig, a -> a.setEvictionAttributes(
           regionAttributes.getEvictionAttributes().convertToConfigEvictionAttributes()));
     }