brooklyn-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From neykov <...@git.apache.org>
Subject [GitHub] brooklyn-server pull request #419: Fix key lookup
Date Wed, 09 Nov 2016 15:32:27 GMT
Github user neykov commented on a diff in the pull request:

    https://github.com/apache/brooklyn-server/pull/419#discussion_r87214325
  
    --- Diff: camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/ConfigNestedYamlTest.java
---
    @@ -0,0 +1,148 @@
    +/*
    + * 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.brooklyn.camp.brooklyn;
    +
    +import java.util.Map;
    +
    +import org.apache.brooklyn.api.entity.Entity;
    +import org.apache.brooklyn.core.config.ConfigKeys;
    +import org.apache.brooklyn.core.entity.Entities;
    +import org.apache.brooklyn.core.entity.EntityInternal;
    +import org.apache.brooklyn.entity.group.DynamicCluster;
    +import org.apache.brooklyn.entity.software.base.SoftwareProcess;
    +import org.apache.brooklyn.util.collections.MutableMap;
    +import org.apache.brooklyn.util.core.text.TemplateProcessor;
    +import org.slf4j.Logger;
    +import org.slf4j.LoggerFactory;
    +import org.testng.Assert;
    +import org.testng.annotations.Test;
    +
    +import com.google.common.collect.Iterables;
    +
    +public class ConfigNestedYamlTest extends AbstractYamlTest {
    +    private static final Logger log = LoggerFactory.getLogger(ConfigNestedYamlTest.class);
    +    
    +    @Test
    +    public void testSimpleYamlBlueprint() throws Exception {
    +        doTestWithBlueprint( loadYaml("config-nested-test.yaml"), false );
    +    }
    +
    +    @Test
    +    public void testCatalogNoParameter() throws Exception {
    +        addCatalogItems( loadYaml("config-nested-test.bom") );
    +        doTestWithBlueprint( "services: [ { type: test-no-parameter } ]", false);
    +    }
    +
    +    @Test
    +    public void testCatalogParameterFromSuperYamlType() throws Exception {
    +        addCatalogItems( loadYaml("config-nested-test.bom") );
    +        Entity ent = doTestWithBlueprint( "services: [ { type: test-map-parameter } ]",
false);
    +        Entities.dumpInfo(ent);
    +    }
    +
    +    @Test
    +    public void testCatalogParameterFromSuperYamlTypeAfterTemplateAccess() throws Exception
{
    +        addCatalogItems( loadYaml("config-nested-test.bom") );
    +        Entity ent = makeBlueprint( "services: [ { type: test-map-parameter } ]");
    +        
    +        checkEntity(ent, false);
    +    }
    +
    +    protected void checkTemplates(EntityInternal ent) {
    +        Map<String, Object> substitutions = MutableMap.copyOf(ent.config().get(SoftwareProcess.TEMPLATE_SUBSTITUTIONS)).asUnmodifiable();
    +        String out0 = TemplateProcessor.processTemplateContents("hello "+"${field}",
substitutions);
    +        Assert.assertEquals(out0, "hello val");
    +        
    +        String out1 = TemplateProcessor.processTemplateContents("hello "+"${config['template.substitutions']['field']}",
ent, substitutions);
    +        Assert.assertEquals(out1, "hello val");
    +    }
    +
    +    @Test
    +    public void testCatalogParameterFromSuperYamlTypeInCluster() throws Exception {
    +        addCatalogItems( loadYaml("config-nested-test.bom") );
    +        Entity cluster = makeBlueprint("services: [ { type: test-cluster-with-map-parameter
} ]");
    +        Entities.dumpInfo(cluster.getApplication());
    +        Entity parentInCluster = Iterables.getOnlyElement( ((DynamicCluster)cluster).getMembers()
);
    +        Entity target = Iterables.getOnlyElement(parentInCluster.getChildren());
    +        checkEntity( target, false );
    +    }
    +    
    +
    +    @Test
    +    public void testCatalogParameterFromSuperYamlTypeAsSoftware() throws Exception {
    +        addCatalogItems( loadYaml("config-nested-test.bom") );
    +        Entity ent = doTestWithBlueprint( "services: [ { type: test-map-parameter-software
} ]", true);
    +        Entities.dumpInfo(ent);
    +    }
    +
    +    @Test
    +    public void testCatalogNoParameterAsSoftware() throws Exception {
    +        addCatalogItems( loadYaml("config-nested-test.bom") );
    +        doTestWithBlueprint( "services: [ { type: test-no-parameter-software } ]", true);
    +    }
    +
    +    protected Entity doTestWithBlueprint(String bp, boolean expectDotSyntaxToWork) throws
Exception {
    +        return checkEntity(makeBlueprint(bp), expectDotSyntaxToWork);
    +    }
    +    
    +    protected Entity makeBlueprint(String bp) throws Exception {
    +        Entity app = createAndStartApplication( bp );
    +        waitForApplicationTasks(app);
    +        return Iterables.getOnlyElement( app.getChildren() );
    +    }
    +    
    +    protected Entity checkEntity(Entity ent, boolean expectDotSyntaxToWork) throws Exception
{
    +        String dotSyntax = ent.getConfig( ConfigKeys.newStringConfigKey("template.substitutions.field")
);
    +        Assert.assertEquals(dotSyntax, expectDotSyntaxToWork ? "val" : null, "wrong value
for dot syntax: "+dotSyntax);
    +        // observed in some situations we get the dot syntax instead!
    +        // Assert.assertEquals(dotSyntax, "val", "wrong value for dot syntax: "+dotSyntax);
    --- End diff --
    
    I'd have expected this to always be the case, for any `Map` value, not just for `MapConfigKey`.
The logic doing the lookup (if I remember correctly) is trying to get for increasingly longer
parts of the full key until it has a hit.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

Mime
View raw message