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 #546: Sequencer entity
Date Tue, 07 Feb 2017 12:59:53 GMT
Github user aledsage commented on a diff in the pull request:

    https://github.com/apache/brooklyn-server/pull/546#discussion_r99814504
  
    --- Diff: core/src/test/java/org/apache/brooklyn/entity/group/SequenceGroupTest.java ---
    @@ -0,0 +1,165 @@
    +/*
    + * 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.entity.group;
    +
    +import static org.apache.brooklyn.test.Asserts.assertEqualsIgnoringOrder;
    +import static org.apache.brooklyn.test.Asserts.*;
    +import static org.apache.brooklyn.core.entity.EntityAsserts.*;
    +
    +import java.util.Set;
    +
    +import org.apache.brooklyn.api.entity.Entity;
    +import org.apache.brooklyn.api.entity.EntitySpec;
    +import org.apache.brooklyn.api.sensor.AttributeSensor;
    +import org.apache.brooklyn.core.entity.Entities;
    +import org.apache.brooklyn.core.entity.EntityPredicates;
    +import org.apache.brooklyn.core.sensor.Sensors;
    +import org.apache.brooklyn.core.test.BrooklynAppUnitTestSupport;
    +import org.apache.brooklyn.core.test.entity.TestApplication;
    +import org.apache.brooklyn.core.test.entity.TestEntity;
    +import org.testng.annotations.AfterMethod;
    +import org.testng.annotations.BeforeMethod;
    +import org.testng.annotations.Test;
    +
    +import com.google.common.base.Predicates;
    +import com.google.common.collect.ImmutableList;
    +import com.google.common.collect.ImmutableSet;
    +
    +public class SequenceGroupTest extends BrooklynAppUnitTestSupport {
    +
    +    private TestApplication app;
    +    private SequenceGroup group;
    +    private TestEntity e1, e2, e3;
    +
    +    @BeforeMethod(alwaysRun=true)
    +    @Override
    +    public void setUp() throws Exception {
    +        super.setUp();
    +
    +        app = TestApplication.Factory.newManagedInstanceForTests();
    +        group = app.createAndManageChild(EntitySpec.create(SequenceGroup.class)
    +                .configure(SequenceGroup.SEQUENCE_STRING_SENSOR, Sensors.newStringSensor("test.sequence"))
    +                .configure(SequenceGroup.SEQUENCE_FORMAT, "test-%02d"));
    +        e1 = app.createAndManageChild(EntitySpec.create(TestEntity.class));
    +        e2 = app.createAndManageChild(EntitySpec.create(TestEntity.class));
    +        e3 = app.createAndManageChild(EntitySpec.create(TestEntity.class));
    +    }
    +
    +    @AfterMethod(alwaysRun=true)
    +    @Override
    +    public void tearDown() throws Exception {
    +        if (app != null) Entities.destroyAll(app.getManagementContext());
    +
    +        super.tearDown();
    +    }
    +
    +
    +    @Test
    +    public void testGroupDefaults() throws Exception {
    +        assertTrue(group.getMembers().isEmpty());
    +    }
    +
    +    @Test
    +    public void testGroupWithMatchingFilterReturnsOnlyMatchingMembers() throws Exception
{
    +        group.setEntityFilter(EntityPredicates.idEqualTo(e1.getId()));
    +
    +        assertEqualsIgnoringOrder(group.getMembers(), ImmutableList.of(e1));
    +        assertAttributeEquals(e1, SequenceGroup.SEQUENCE_VALUE, 1);
    +        assertAttributeEquals(group, SequenceGroup.SEQUENCE_NEXT, 2);
    +    }
    +
    +    @Test
    +    public void testGroupConfiguration() throws Exception {
    +        group.setEntityFilter(EntityPredicates.idEqualTo(e1.getId()));
    +
    +        assertEqualsIgnoringOrder(group.getMembers(), ImmutableList.of(e1));
    +        assertAttributeEquals(e1, SequenceGroup.SEQUENCE_STRING, null);
    +        assertAttributeEquals(e1, Sensors.newStringSensor("test.sequence"), "test-01");
    +    }
    +
    +    @Test
    +    public void testAlternateGroupConfiguration() throws Exception {
    +        AttributeSensor<Integer> value = Sensors.newIntegerSensor("test.value");
    +        AttributeSensor<String> string = Sensors.newStringSensor("test.string");
    +        group = app.createAndManageChild(EntitySpec.create(SequenceGroup.class)
    +                .configure(SequenceGroup.SEQUENCE_START, 12345)
    +                .configure(SequenceGroup.SEQUENCE_INCREMENT, 678)
    +                .configure(SequenceGroup.SEQUENCE_VALUE_SENSOR, value)
    +                .configure(SequenceGroup.SEQUENCE_STRING_SENSOR, string)
    +                .configure(SequenceGroup.SEQUENCE_FORMAT, "0x%04X"));
    +        group.setEntityFilter(EntityPredicates.hasInterfaceMatching(".*TestEntity"));
    +
    +        assertEqualsIgnoringOrder(group.getMembers(), ImmutableSet.of(e1, e2, e3));
    +        assertAttributeEquals(e1, value, 12345);
    --- End diff --
    
    Can we be sure that `e1`, `e2`, e3` will be the order of the members? Is that because
it is called sequentially with the order that the entities were created?


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