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 #287: Add new member tracking policy with confi...
Date Wed, 10 Aug 2016 18:47:03 GMT
Github user aledsage commented on a diff in the pull request:

    https://github.com/apache/brooklyn-server/pull/287#discussion_r74306037
  
    --- Diff: core/src/test/java/org/apache/brooklyn/entity/group/SshCommandMembershipTrackingPolicyTest.java
---
    @@ -0,0 +1,113 @@
    +/*
    + * 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.testng.Assert.assertEquals;
    +import static org.testng.Assert.assertTrue;
    +
    +import java.util.Map;
    +
    +import org.testng.annotations.AfterMethod;
    +import org.testng.annotations.BeforeMethod;
    +import org.testng.annotations.Test;
    +
    +import com.google.common.collect.ImmutableList;
    +
    +import org.apache.brooklyn.api.entity.EntitySpec;
    +import org.apache.brooklyn.api.location.LocationSpec;
    +import org.apache.brooklyn.api.mgmt.EntityManager;
    +import org.apache.brooklyn.api.policy.PolicySpec;
    +import org.apache.brooklyn.core.entity.trait.Startable;
    +import org.apache.brooklyn.core.location.SimulatedLocation;
    +import org.apache.brooklyn.core.test.BrooklynAppUnitTestSupport;
    +import org.apache.brooklyn.core.test.entity.TestEntity;
    +import org.apache.brooklyn.entity.group.AbstractMembershipTrackingPolicy.EventType;
    +import org.apache.brooklyn.entity.stock.BasicStartable;
    +import org.apache.brooklyn.location.ssh.SshMachineLocation;
    +import org.apache.brooklyn.util.core.internal.ssh.RecordingSshTool;
    +import org.apache.brooklyn.util.time.Duration;
    +
    +public class SshCommandMembershipTrackingPolicyTest extends BrooklynAppUnitTestSupport
{
    +
    +    private SimulatedLocation loc;
    +    private EntityManager entityManager;
    +    private BasicGroup group;
    +    private BasicStartable entity;
    +    private LocationSpec<SshMachineLocation> machine;
    +
    +    @BeforeMethod(alwaysRun=true)
    +    @Override
    +    public void setUp() throws Exception {
    +        super.setUp();
    +
    +        machine = LocationSpec.create(SshMachineLocation.class)
    +                .configure("address", "1.2.3.4")
    +                .configure("sshToolClass", RecordingSshTool.class.getName());
    +        loc = mgmt.getLocationManager().createLocation(LocationSpec.create(SimulatedLocation.class));
    +        entityManager = app.getManagementContext().getEntityManager();
    +
    +        group = app.createAndManageChild(EntitySpec.create(BasicGroup.class)
    +                .configure("childrenAsMembers", true));
    +
    +        entity = app.createAndManageChild(EntitySpec.create(BasicStartable.class).location(machine));
    +        entity.policies().add(PolicySpec.create(SshCommandMembershipTrackingPolicy.class)
    +                .configure("group", group)
    +                .configure("shell.env.TEST", "test")
    +                .configure("update.command", "echo ignored"));
    +
    +        app.start(ImmutableList.of(loc));
    +    }
    +
    +    @AfterMethod(alwaysRun=true)
    +    @Override
    +    public void tearDown() throws Exception {
    +        super.tearDown();
    +        RecordingSshTool.clear();
    +    }
    +
    +    @Test
    +    public void testCommandExecutedWithEnvironment() throws Exception {
    +        TestEntity member = entityManager.createEntity(EntitySpec.create(TestEntity.class).parent(group));
    +        Duration.seconds(1).countdownTimer().waitForExpiry();
    --- End diff --
    
    Why wait for a second? That might well not be long enough on Apache Jenkins for it to
work every time! And it's too long on a normal laptop.
    
    I'd have written:
    
    ```
    protected void assertExecSizeEventually(final int expectedSize) {
        Asserts.succeedsEventually(new Runnable() {
            public void run() {
                assertEquals(RecordingSshTool.getExecCmds().size(), expectedSize);
            }});
    }
    ```
    
    Same below when you wait a second and assert that the size is 2 or 3. (hence why worth
extracting it into a method).


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