brooklyn-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From henev...@apache.org
Subject [01/13] brooklyn-server git commit: Testing override of java MapConfigKey in brooklyn.parameters
Date Tue, 29 Nov 2016 13:40:15 GMT
Repository: brooklyn-server
Updated Branches:
  refs/heads/master 721ced78d -> 56496fa54


Testing override of java MapConfigKey in brooklyn.parameters


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

Branch: refs/heads/master
Commit: e28c4b3916c5e6e35892147a5e0a87f1e11e7d5f
Parents: 92ff820
Author: Aled Sage <aled.sage@gmail.com>
Authored: Thu Nov 17 16:30:15 2016 +0000
Committer: Aled Sage <aled.sage@gmail.com>
Committed: Mon Nov 28 21:11:48 2016 +0000

----------------------------------------------------------------------
 .../camp/brooklyn/ConfigNestedYamlTest.java     |  2 +-
 .../camp/brooklyn/ConfigParametersYamlTest.java | 75 +++++++++++++++++++-
 2 files changed, 74 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/e28c4b39/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/ConfigNestedYamlTest.java
----------------------------------------------------------------------
diff --git a/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/ConfigNestedYamlTest.java
b/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/ConfigNestedYamlTest.java
index 2d6526f..699b02d 100644
--- a/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/ConfigNestedYamlTest.java
+++ b/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/ConfigNestedYamlTest.java
@@ -87,7 +87,7 @@ public class ConfigNestedYamlTest extends AbstractYamlTest {
     @Test
     public void testCatalogParameterFromSuperYamlTypeAsSoftware() throws Exception {
         addCatalogItems( loadYaml("config-nested-test.bom") );
-        Entity ent = doTestWithBlueprint( "services: [ { type: test-map-parameter-software
} ]", true);
+        Entity ent = doTestWithBlueprint( "services: [ { type: test-map-parameter-software
} ]", false);
         Entities.dumpInfo(ent);
     }
 

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/e28c4b39/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/ConfigParametersYamlTest.java
----------------------------------------------------------------------
diff --git a/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/ConfigParametersYamlTest.java
b/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/ConfigParametersYamlTest.java
index 78219c6..2336030 100644
--- a/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/ConfigParametersYamlTest.java
+++ b/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/ConfigParametersYamlTest.java
@@ -140,6 +140,78 @@ public class ConfigParametersYamlTest extends AbstractYamlRebindTest
{
         assertKeyEquals(newEntity, TestEntity.CONF_NAME.getName(), "myDescription", String.class,
"myDefaultYamlVal", "myDefaultYamlVal");
     }
     
+    // See https://issues.apache.org/jira/browse/BROOKLYN-345, and the breakage that 
+    // fix originally caused - discussed in https://github.com/apache/brooklyn-server/pull/440.
+    //
+    // When brooklyn.parameters defines TestEntity.CONF_MAP_THING, it now means that this
redefined
+    // config key is used for lookup. This now has type `BasicConfigKey<Map>` rather
than 
+    // `MapConfigKey`. However, when the data was being written (via `entity.config().set(key,
val)`)
+    // it was using the `MapConfigKey`. Unfortunately the `MapConfigKey` uses a different
structure
+    // for storing its data (flattening out the map). So the subsequent lookup failed.
+    //
+    // There are three parts to fixing this:
+    //  1. [DONE] In `entity.config().set(key, val)`, replace `key` with the entity's own
key  
+    //     (i.e. the same logic that will subsequently be used in the `get`).
+    //  2. [DONE] In `BrooklynComponentTemplateResolver.findAllFlagsAndConfigKeyValues`,
respect  
+    //     the precedence of the config keys - prefer the `brooklyn.parameters` over the
key defined
+    //     in the super-type (e.g. in the java class).
+    //  3. [TODO] Investigate rebind: the entity's ownConfig ends up with the "test.confMapThing.mykey=myval",
+    //     so it has populated it using the MayConfigKey structure rather than the override
config key.
+    //  4. [TODO] Major overhaul of the ConfigKey name versus `SetFromFlag` alias. It is
currently
+    //     confusing in when reading the config values what the precedence is because there
are 
+    //     different names that are only understood by some things.
+    @Test(groups="Broken")
+    public void testConfigParameterOverridingJavaMapConfigKey() throws Exception {
+        runConfigParameterOverridingJavaMapConfigKey(true);
+    }
+    
+    @Test
+    public void testConfigParameterOverridingJavaMapConfigKeyWithoutRebindValueCheck() throws
Exception {
+        // A cut-down test of what is actually working just now (so we can detect any 
+        // further regressions!)
+        runConfigParameterOverridingJavaMapConfigKey(false);
+    }
+    
+    protected void runConfigParameterOverridingJavaMapConfigKey(boolean assertReboundVal)
throws Exception {
+        addCatalogItems(
+                "brooklyn.catalog:",
+                "  itemType: entity",
+                "  items:",
+                "  - id: entity-with-keys",
+                "    item:",
+                "      type: "+TestEntity.class.getName(),
+                "      brooklyn.parameters:",
+                "      - name: " + TestEntity.CONF_MAP_THING.getName(),
+                "        description: myDescription",
+                "        type: java.util.Map",
+                "      brooklyn.config:",
+                "        "+TestEntity.CONF_MAP_THING.getName()+":",
+                "          mykey: myval");
+        
+        String yaml = Joiner.on("\n").join(
+                "services:",
+                "- type: entity-with-keys");
+        
+        Entity app = createStartWaitAndLogApplication(yaml);
+        TestEntity entity = (TestEntity) Iterables.getOnlyElement(app.getChildren());
+
+        // Check config key is listed
+        assertKeyEquals(entity, TestEntity.CONF_MAP_THING.getName(), "myDescription", java.util.Map.class,
null, ImmutableMap.of("mykey", "myval"));
+
+        // Rebind, and then check again that the config key is listed
+        Entity newApp = rebind();
+        TestEntity newEntity = (TestEntity) Iterables.getOnlyElement(newApp.getChildren());
+        if (assertReboundVal) {
+            assertKeyEquals(newEntity, TestEntity.CONF_MAP_THING.getName(), "myDescription",
java.util.Map.class, null, ImmutableMap.of("mykey", "myval"));
+        } else {
+            // TODO delete duplication from `assertKeyEquals`, when the above works!
+            ConfigKey<?> key = newEntity.getEntityType().getConfigKey(TestEntity.CONF_MAP_THING.getName());
+            assertEquals(key.getDescription(), "myDescription");
+            assertEquals(key.getType(), java.util.Map.class);
+            assertEquals(key.getDefaultValue(), null);
+        }
+    }
+    
     @Test
     public void testConfigParametersListedInType() throws Exception {
         addCatalogItems(
@@ -441,9 +513,8 @@ public class ConfigParametersYamlTest extends AbstractYamlRebindTest {
         assertEquals(env.get("TEST"), "myDefaultParamVal", "env="+env);
     }
 
-    // TODO: fails; it presumably gets the config key defined in java, rather than the brooklyn.parameters
key
     // See https://issues.apache.org/jira/browse/BROOKLYN-328
-    @Test(groups={"WIP", "Broken"})
+    @Test
     public void testConfigParameterOverridingJavaConfig() throws Exception {
         String confName = TestEntity.CONF_OBJECT.getName();
         addCatalogItems(


Mime
View raw message