brooklyn-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aledsage <...@git.apache.org>
Subject [GitHub] brooklyn-server pull request #612: BROOKLYN-460: Brooklyn Camp syntax for ad...
Date Wed, 05 Apr 2017 09:44:32 GMT
Github user aledsage commented on a diff in the pull request:

    https://github.com/apache/brooklyn-server/pull/612#discussion_r109871250
  
    --- Diff: camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/spi/dsl/TagsYamlTest.java
---
    @@ -0,0 +1,171 @@
    +/*
    + * Copyright 2016 The Apache Software Foundation.
    + *
    + * Licensed 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.spi.dsl;
    +
    +import com.google.common.base.Predicate;
    +import com.google.common.collect.Iterables;
    +import org.apache.brooklyn.api.entity.Entity;
    +import org.apache.brooklyn.api.mgmt.Task;
    +import org.apache.brooklyn.camp.brooklyn.AbstractYamlTest;
    +import org.apache.brooklyn.core.entity.EntityInternal;
    +import org.apache.brooklyn.core.mgmt.BrooklynTags;
    +import org.apache.brooklyn.entity.stock.BasicApplication;
    +import org.apache.brooklyn.test.Asserts;
    +import org.apache.brooklyn.util.exceptions.CompoundRuntimeException;
    +import org.apache.brooklyn.util.exceptions.Exceptions;
    +import org.testng.annotations.Test;
    +
    +import javax.annotation.Nullable;
    +import java.io.Serializable;
    +import java.util.Set;
    +import java.util.concurrent.Callable;
    +
    +import static org.testng.Assert.assertTrue;
    +import static org.testng.Assert.fail;
    +
    +public class TagsYamlTest extends AbstractYamlTest {
    +    @Test
    +    public void testBrooklynCampSingleTag() throws Exception {
    +        final Entity app = createAndStartApplication(
    +                "services:",
    +                "- type: " + BasicApplication.class.getName(),
    +                "  brooklyn.tags:",
    +                "    - hi");
    +        assertTrue(getTagsEventually(app).contains(BrooklynTags.newCampBrooklynTag("hi")));
    +    }
    +
    +    @Test
    +    public void testBrooklynCampMultipleTags() throws Exception {
    +        final Entity app = createAndStartApplication(
    +                "services:",
    +                "- type: " + BasicApplication.class.getName(),
    +                "  brooklyn.tags:",
    +                "  - tag1",
    +                "  - \"2\"",
    +                "  - \"- 3\"");
    +        assertTrue(getTagsEventually(app).contains(BrooklynTags.newCampBrooklynTag("tag1")));
    +        assertTrue(getTagsEventually(app).contains(BrooklynTags.newCampBrooklynTag("2")));
    +        assertTrue(getTagsEventually(app).contains(BrooklynTags.newCampBrooklynTag("-
3")));
    +    }
    +
    +    @Test
    +    public void testBrooklynCampTagsFailNonList() throws Exception {
    +        try {
    +            final Entity app = createAndStartApplication(
    +                    "services:",
    +                    "- type: " + BasicApplication.class.getName(),
    +                    "  brooklyn.tags:",
    +                    "    tag1: true",
    +                    "    tag2: 2");
    +            fail("Should throw IllegalArgumentException exception.");
    +        } catch (CompoundRuntimeException e) {
    +            Asserts.assertStringContainsAtLeastOne(Exceptions.getFirstInteresting(e).getMessage(),"brooklyn.tags
must be a list, is: ");
    +        }
    +    }
    +
    +    @Test
    +    public void testBrooklynCampKnowsIntegerTags() throws Exception {
    +        final Entity app = createAndStartApplication(
    +                "services:",
    +                "- type: " + BasicApplication.class.getName(),
    +                "  brooklyn.tags:",
    +                "  - tag1",
    +                "  - 3");
    +        assertTrue(getTagsEventually(app).contains(BrooklynTags.newCampBrooklynTag(3)));
    +        assertTrue(getTagsEventually(app).contains(BrooklynTags.newCampBrooklynTag("tag1")));
    +    }
    +
    +    @Test
    +    public void testBrooklynCampObjectTags() throws Exception {
    +        final Entity app = createAndStartApplication(
    +                "services:",
    +                "- type: " + BasicApplication.class.getName(),
    +                "  brooklyn.tags:",
    +                "  - tag1",
    +                "  - $brooklyn:object:",
    +                "      type: " + TagsTestSerializableObject.class.getName());
    +        assertTrue(Iterables.any(getTagsEventually(app), new Predicate<Object>()
{
    +            @Override
    +            public boolean apply(@Nullable Object input) {
    +                return input instanceof BrooklynTags.CampBrooklynTag && ((BrooklynTags.CampBrooklynTag)input).getContents()
instanceof TagsTestSerializableObject;
    +            }
    +        }));
    +        assertTrue(getTagsEventually(app).contains(BrooklynTags.newCampBrooklynTag("tag1")));
    +    }
    +
    +    @Test
    +    public void testBrooklynCampFailDslTags() throws Exception {
    +        try {
    +            final Entity app = createAndStartApplication(
    +                    "services:",
    +                    "- type: " + BasicApplication.class.getName(),
    +                    "  brooklyn.tags:",
    +                    "  - tag1",
    +                    "  - $brooklyn:object:",
    +                    "      type: "+TagsTestSerializableObject.class.getName(),
    +                    "      constructor.args:",
    +                    "      - $brooklyn:attributeWhenReady(\"host.name\")");
    +            fail("Should throw IllegalArgumentException exception.");
    +        } catch (CompoundRuntimeException e) {
    +            Asserts.assertStringContainsAtLeastOne(Exceptions.getFirstInteresting(e).getMessage(),"brooklyn.tags
should not contain DeferredSupplier objects, such example is using $brooklyn:attributeWhenReady");
    +        }
    +    }
    +
    +    @Test
    +    public void testBrooklynCampFailNonSerializableDslTags() throws Exception {
    +        try {
    +            final Entity app = createAndStartApplication(
    +                    "services:",
    +                    "- type: " + BasicApplication.class.getName(),
    +                    "  brooklyn.tags:",
    +                    "  - tag1",
    +                    "  - $brooklyn:object:",
    +                    "      type: "+NonSerializable.class.getName());
    +            fail("Should throw IllegalArgumentException exception.");
    +        } catch (CompoundRuntimeException e) {
    +            Asserts.assertStringContainsAtLeastOne(Exceptions.getFirstInteresting(e).getMessage(),"brooklyn.tags
should not contain DeferredSupplier objects, such example is using $brooklyn:attributeWhenReady");
    +        }
    +    }
    +
    +    public static class NonSerializable {}
    +
    +    @Test
    +    public void testTagWithDslValue() throws Exception {
    +        Entity app = createAndStartApplication(
    +                "services:",
    +                "- type: " + BasicApplication.class.getName(),
    +                "  brooklyn.tags:",
    +                "  - $brooklyn:literal(\"myval\")");
    +        assertTrue(getTagsEventually(app).contains(BrooklynTags.newCampBrooklynTag("myval")));
    +    }
    +
    +    public static class TagsTestSerializableObject implements Serializable {
    +        private static final long serialVersionUID = -5150802977330637460L;
    +
    +        public TagsTestSerializableObject() {}
    +        public TagsTestSerializableObject(Object arg1) {}
    +    }
    +
    +    private static Set<Object> getTagsEventually(final Entity entity) throws Exception
{
    +        Task<Set<Object>> result = ((EntityInternal)entity).getExecutionContext().submit(new
Callable<Set<Object>>() {
    +            @Override
    +            public Set<Object> call() throws Exception {
    +                return entity.tags().getTags();
    --- End diff --
    
    Why do we need to call this inside a task? Does it fail without that? Under what circumstances
would `entity.tags().getTags()` block, and timeout?
    
    Why do we need "eventually" - is the tag potentially not there initially?


---
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