Github user neykov commented on a diff in the pull request:

    https://github.com/apache/brooklyn-server/pull/175#discussion_r65503236
  
    --- Diff: 
camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/ConfigInheritanceYamlTest.java
 ---
    @@ -0,0 +1,316 @@
    +/*
    + * 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 static org.testng.Assert.assertEquals;
    +
    +import java.io.StringReader;
    +import java.nio.file.Files;
    +import java.nio.file.Path;
    +import java.util.List;
    +import java.util.Map;
    +import java.util.concurrent.Callable;
    +import java.util.concurrent.ExecutorService;
    +import java.util.concurrent.Executors;
    +
    +import org.apache.brooklyn.api.entity.Entity;
    +import org.apache.brooklyn.config.ConfigKey;
    +import org.apache.brooklyn.core.entity.EntityAsserts;
    +import org.apache.brooklyn.core.sensor.Sensors;
    +import org.apache.brooklyn.core.test.entity.TestEntity;
    +import org.apache.brooklyn.entity.software.base.EmptySoftwareProcess;
    +import org.apache.brooklyn.util.collections.MutableMap;
    +import org.apache.brooklyn.util.core.internal.ssh.RecordingSshTool;
    +import org.slf4j.Logger;
    +import org.slf4j.LoggerFactory;
    +import org.testng.annotations.AfterMethod;
    +import org.testng.annotations.BeforeMethod;
    +import org.testng.annotations.Test;
    +
    +import com.google.api.client.repackaged.com.google.common.base.Joiner;
    +import com.google.common.collect.ImmutableList;
    +import com.google.common.collect.ImmutableMap;
    +import com.google.common.collect.Iterables;
    +
    +public class ConfigInheritanceYamlTest extends AbstractYamlTest {
    +    
    +    // TOOD Add tests similar to testEntityTypeInheritanceOptions, for 
locations, policies and enrichers.
    +    
    +    @SuppressWarnings("unused")
    +    private static final Logger LOG = 
LoggerFactory.getLogger(ConfigInheritanceYamlTest.class);
    +
    +    private Path emptyFile;
    +    private Path emptyFile2;
    +    
    +    private ExecutorService executor;
    +
    +    @BeforeMethod(alwaysRun = true)
    +    @Override
    +    public void setUp() throws Exception {
    +        super.setUp();
    +        
    +        executor = Executors.newCachedThreadPool();
    +        
    +        emptyFile = Files.createTempFile("ConfigInheritanceYamlTest", 
".txt");
    +        emptyFile2 = Files.createTempFile("ConfigInheritanceYamlTest2", 
".txt");
    +        
    +        addCatalogItems(
    +                "brooklyn.catalog:",
    +                "  id: EmptySoftwareProcess-with-conf",
    +                "  itemType: entity",
    +                "  item:",
    +                "    type: 
org.apache.brooklyn.entity.software.base.EmptySoftwareProcess",
    +                "    brooklyn.config:",
    +                "      shell.env:",
    +                "        ENV1: myEnv1",
    +                "      templates.preinstall:",
    +                "        "+emptyFile.toUri()+": myfile",
    +                "      files.preinstall:",
    +                "        "+emptyFile.toUri()+": myfile",
    +                "      templates.install:",
    +                "        "+emptyFile.toUri()+": myfile",
    +                "      files.install:",
    +                "        "+emptyFile.toUri()+": myfile",
    +                "      templates.runtime:",
    +                "        "+emptyFile.toUri()+": myfile",
    +                "      files.runtime:",
    +                "        "+emptyFile.toUri()+": myfile",
    +                "      provisioning.properties:",
    +                "        mykey: myval",
    +                "        templateOptions:",
    +                "          myOptionsKey: myOptionsVal");
    +        
    +        addCatalogItems(
    +                "brooklyn.catalog:",
    +                "  id: localhost-stub",
    +                "  name: Localhost (stubbed-SSH)",
    +                "  itemType: location",
    +                "  item:",
    +                "    type: localhost",
    +                "    brooklyn.config:",
    +                "      sshToolClass: "+RecordingSshTool.class.getName());
    +    }
    +
    +    @AfterMethod(alwaysRun = true)
    +    @Override
    +    public void tearDown() throws Exception {
    +        super.tearDown();
    +        if (executor != null) executor.shutdownNow();
    +        if (emptyFile != null) Files.delete(emptyFile);
    +        if (emptyFile2 != null) Files.delete(emptyFile2);
    +    }
    +    
    +    @Test
    +    public void testInheritsSuperTypeConfig() throws Exception {
    +        String yaml = Joiner.on("\n").join(
    +                "location: localhost-stub",
    +                "services:",
    +                "- type: EmptySoftwareProcess-with-conf");
    +        
    +        Entity app = createStartWaitAndLogApplication(new 
StringReader(yaml));
    +        Entity entity = Iterables.getOnlyElement(app.getChildren());
    +        
    +        assertEmptySoftwareProcessConfig(
    +                entity,
    +                ImmutableMap.of("ENV1", "myEnv1"),
    +                ImmutableMap.of(emptyFile.toUri().toString(), "myfile"),
    +                ImmutableMap.of("mykey", "myval", "templateOptions", 
ImmutableMap.of("myOptionsKey", "myOptionsVal")));
    +    }
    +    
    +    @Test
    +    public void testInheritsParentConfig() throws Exception {
    +        String yaml = Joiner.on("\n").join(
    +                "location: localhost-stub",
    +                "services:",
    +                "- type: 
org.apache.brooklyn.entity.stock.BasicApplication",
    +                "  brooklyn.config:",
    +                "    shell.env:",
    +                "      ENV1: myEnv1",
    +                "    templates.preinstall:",
    +                "      "+emptyFile.toUri()+": myfile",
    +                "    files.preinstall:",
    +                "      "+emptyFile.toUri()+": myfile",
    +                "    templates.install:",
    +                "      "+emptyFile.toUri()+": myfile",
    +                "    files.install:",
    +                "      "+emptyFile.toUri()+": myfile",
    +                "    templates.runtime:",
    +                "      "+emptyFile.toUri()+": myfile",
    +                "    files.runtime:",
    +                "      "+emptyFile.toUri()+": myfile",
    +                "    provisioning.properties:",
    +                "      mykey: myval",
    +                "      templateOptions:",
    +                "        myOptionsKey: myOptionsVal", 
    +                "  brooklyn.children:",
    +                "  - type: 
org.apache.brooklyn.entity.software.base.EmptySoftwareProcess");
    +
    +        Entity app = createStartWaitAndLogApplication(new 
StringReader(yaml));
    +        Entity entity = Iterables.getOnlyElement(app.getChildren());
    +        
    +        assertEmptySoftwareProcessConfig(
    +                entity,
    +                ImmutableMap.of("ENV1", "myEnv1"),
    +                ImmutableMap.of(emptyFile.toUri().toString(), "myfile"),
    +                ImmutableMap.of("mykey", "myval", "templateOptions", 
ImmutableMap.of("myOptionsKey", "myOptionsVal")));
    +    }
    +    
    +    /**
    +     * TODO This hangs because the attributeWhenReady self-reference is 
resolved against the entity
    +     * looking up the config value (i.e. the child). Therefore it waits 
for the TestEntity to have
    +     * a value for that sensor, but this never happens. The way to avoid 
this is to explicitly set
    +     * the component that the attributeWhenReady should apply to (e.g. see 
{@link #testInheritsParentConfigTask()}.
    +     * 
    +     * Do we want to just exclude this test? Or do we want to "fix" it? 
Which entity should the
    +     * attributeWhenReady apply to?
    --- End diff --
    
    +1 for fixing it. We have a similar problem with resource references where 
they will be resolved against the libraries of the catalog item using the 
resource, not the one that's declaring it. Need to tag config with the place 
where it was declared.


---
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 [email protected] or file a JIRA ticket
with INFRA.
---

Reply via email to