You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@brooklyn.apache.org by he...@apache.org on 2017/02/15 18:31:02 UTC

[09/28] brooklyn-server git commit: PR comments on config defaults

PR comments on config defaults


Project: http://git-wip-us.apache.org/repos/asf/brooklyn-server/repo
Commit: http://git-wip-us.apache.org/repos/asf/brooklyn-server/commit/13648d8c
Tree: http://git-wip-us.apache.org/repos/asf/brooklyn-server/tree/13648d8c
Diff: http://git-wip-us.apache.org/repos/asf/brooklyn-server/diff/13648d8c

Branch: refs/heads/master
Commit: 13648d8c7e5c453c62f7d6de67a3681616c4b930
Parents: 536fb1a
Author: Alex Heneveld <al...@Alexs-MacBook-Pro.local>
Authored: Fri Dec 2 00:46:03 2016 +0000
Committer: Alex Heneveld <al...@Alexs-MacBook-Pro.local>
Committed: Tue Dec 6 10:05:21 2016 +0000

----------------------------------------------------------------------
 .../core/config/BasicConfigInheritance.java     | 30 +++++++++++++-------
 .../mgmt/persist/XmlMementoSerializerTest.java  | 13 ++++++++-
 2 files changed, 31 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/13648d8c/core/src/main/java/org/apache/brooklyn/core/config/BasicConfigInheritance.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/core/config/BasicConfigInheritance.java b/core/src/main/java/org/apache/brooklyn/core/config/BasicConfigInheritance.java
index 77de6ec..d064eb9 100644
--- a/core/src/main/java/org/apache/brooklyn/core/config/BasicConfigInheritance.java
+++ b/core/src/main/java/org/apache/brooklyn/core/config/BasicConfigInheritance.java
@@ -68,8 +68,25 @@ public class BasicConfigInheritance implements ConfigInheritance {
         public boolean equals(Object obj) {
             return super.equals(obj) || getDelegate().equals(obj);
         }
+        
+        // standard deserialization method
+        protected ConfigInheritance readResolve() {
+            return returnEquivalentConstant(this);
+        }
     }
 
+    private static ConfigInheritance returnEquivalentConstant(ConfigInheritance candidate) {
+        for (ConfigInheritance knownMode: Arrays.asList(
+                NOT_REINHERITED, NOT_REINHERITED_ELSE_DEEP_MERGE, NEVER_INHERITED, OVERWRITE, BasicConfigInheritance.DEEP_MERGE)) {
+            if (candidate.equals(knownMode)) return knownMode;
+        }
+        if (candidate.equals(new BasicConfigInheritance(false, CONFLICT_RESOLUTION_STRATEGY_OVERWRITE, true, true))) {
+            // ignore the ancestor flag for this mode
+            return NEVER_INHERITED;
+        }
+        return candidate;
+    }
+    
     /*
      * use of delegate is so that stateless classes can be defined to make the serialization nice,
      * both the name and hiding the implementation detail (also making it easier for that detail to change);
@@ -359,17 +376,8 @@ public class BasicConfigInheritance implements ConfigInheritance {
         } catch (Exception e) {
             throw Exceptions.propagate(e);
         }
-        
-        for (ConfigInheritance knownMode: Arrays.asList(
-                NOT_REINHERITED, NOT_REINHERITED_ELSE_DEEP_MERGE, NEVER_INHERITED, OVERWRITE, DEEP_MERGE)) {
-            if (equals(knownMode)) return knownMode;
-        }
-        if (equals(new BasicConfigInheritance(false, CONFLICT_RESOLUTION_STRATEGY_OVERWRITE, true, true))) {
-            // ignore the ancestor flag for this mode
-            return NEVER_INHERITED;
-        }
-        
-        return this;
+                
+        return returnEquivalentConstant(this);
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/13648d8c/core/src/test/java/org/apache/brooklyn/core/mgmt/persist/XmlMementoSerializerTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/brooklyn/core/mgmt/persist/XmlMementoSerializerTest.java b/core/src/test/java/org/apache/brooklyn/core/mgmt/persist/XmlMementoSerializerTest.java
index b708eb7..68aa938 100644
--- a/core/src/test/java/org/apache/brooklyn/core/mgmt/persist/XmlMementoSerializerTest.java
+++ b/core/src/test/java/org/apache/brooklyn/core/mgmt/persist/XmlMementoSerializerTest.java
@@ -48,8 +48,10 @@ import org.apache.brooklyn.api.sensor.AttributeSensor;
 import org.apache.brooklyn.api.sensor.Enricher;
 import org.apache.brooklyn.api.sensor.Feed;
 import org.apache.brooklyn.api.typereg.RegisteredType;
+import org.apache.brooklyn.config.ConfigInheritance;
 import org.apache.brooklyn.core.catalog.internal.CatalogItemBuilder;
 import org.apache.brooklyn.core.catalog.internal.CatalogItemDtoAbstract;
+import org.apache.brooklyn.core.config.BasicConfigInheritance;
 import org.apache.brooklyn.core.entity.Attributes;
 import org.apache.brooklyn.core.entity.Entities;
 import org.apache.brooklyn.core.location.SimulatedLocation;
@@ -57,7 +59,6 @@ import org.apache.brooklyn.core.mgmt.ha.OsgiManager;
 import org.apache.brooklyn.core.mgmt.internal.ManagementContextInternal;
 import org.apache.brooklyn.core.mgmt.osgi.OsgiStandaloneTest;
 import org.apache.brooklyn.core.mgmt.osgi.OsgiVersionMoreEntityTest;
-import org.apache.brooklyn.core.mgmt.rebind.RebindEntityTest.ReffingEntity;
 import org.apache.brooklyn.core.test.entity.LocalManagementContextForTests;
 import org.apache.brooklyn.core.test.entity.TestApplication;
 import org.apache.brooklyn.core.test.entity.TestEntity;
@@ -78,6 +79,7 @@ import org.osgi.framework.Bundle;
 import org.osgi.framework.launch.Framework;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
+import org.testng.Assert;
 import org.testng.annotations.AfterMethod;
 import org.testng.annotations.BeforeMethod;
 import org.testng.annotations.Test;
@@ -792,4 +794,13 @@ public class XmlMementoSerializerTest {
         Framework framework = osgiManager.getFramework();
         return Osgis.install(framework, bundleUrl);
     }
+    
+    @Test
+    public void testConfigInheritanceVals() throws Exception {
+        ConfigInheritance val = BasicConfigInheritance.NEVER_INHERITED;
+
+        ConfigInheritance newVal = assertSerializeAndDeserialize(val); // TODO this line fails
+        Assert.assertSame(val, newVal);
+    }
+    
 }
\ No newline at end of file