brooklyn-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aledsage <...@git.apache.org>
Subject [GitHub] incubator-brooklyn pull request: Fix various integration tests
Date Thu, 30 Oct 2014 21:13:25 GMT
Github user aledsage commented on a diff in the pull request:

    https://github.com/apache/incubator-brooklyn/pull/281#discussion_r19636752
  
    --- Diff: software/webapp/src/test/java/brooklyn/entity/webapp/nodejs/NodeJsWebAppFixtureIntegrationTest.java
---
    @@ -18,41 +18,188 @@
      */
     package brooklyn.entity.webapp.nodejs;
     
    -import org.testng.annotations.DataProvider;
    +import static org.testng.Assert.assertFalse;
    +import static org.testng.Assert.assertTrue;
     
    +import java.io.File;
    +import java.util.concurrent.TimeUnit;
    +
    +import org.slf4j.Logger;
    +import org.slf4j.LoggerFactory;
    +import org.testng.annotations.AfterMethod;
    +import org.testng.annotations.BeforeMethod;
    +import org.testng.annotations.Test;
    +
    +import brooklyn.entity.Entity;
    +import brooklyn.entity.basic.Entities;
    +import brooklyn.entity.basic.EntityInternal;
     import brooklyn.entity.basic.SoftwareProcess;
     import brooklyn.entity.proxying.EntitySpec;
    -import brooklyn.entity.webapp.AbstractWebAppFixtureIntegrationTest;
    +import brooklyn.entity.rebind.PersistenceExceptionHandlerImpl;
    +import brooklyn.entity.rebind.dto.MementosGenerators;
    +import brooklyn.entity.rebind.persister.BrooklynMementoPersisterToMultiFile;
    +import brooklyn.entity.trait.Startable;
     import brooklyn.entity.webapp.WebAppService;
    +import brooklyn.location.Location;
     import brooklyn.location.basic.PortRanges;
    +import brooklyn.management.ManagementContext;
    +import brooklyn.management.ha.ManagementNodeState;
    +import brooklyn.management.internal.ManagementContextInternal;
    +import brooklyn.mementos.BrooklynMemento;
    +import brooklyn.test.Asserts;
    +import brooklyn.test.EntityTestUtils;
    +import brooklyn.test.HttpTestUtils;
    +import brooklyn.test.entity.LocalManagementContextForTests;
     import brooklyn.test.entity.TestApplication;
    +import brooklyn.util.collections.MutableMap;
    +import brooklyn.util.net.Urls;
    +import brooklyn.util.os.Os;
    +import brooklyn.util.time.Time;
    +
    +import com.google.common.collect.ImmutableList;
    +
    +/**
    + * Integration tests for NodeJS.
    + * 
    + * Only works on Linux (including Ubuntu and CentOS); not on OS X
    + */
    +public class NodeJsWebAppFixtureIntegrationTest {
     
    -public class NodeJsWebAppFixtureIntegrationTest extends AbstractWebAppFixtureIntegrationTest
{
    +    // TODO Remove duplication from AbstractWebAppFixtureIntegrationTest. Those tests
are geared towards Java-based
    +    // tests (e.g. deploying WAR), so not extending it.
     
    +    // TODO Test deploy and undeploy; see AbstractWebAppFixtureIntegrationTest#testWarDeployAndUndeploy
    +
    +    // TODO Does not set WebAppService.REQUEST_COUNT, WebAppService.ERROR_COUNT, REQUESTS_PER_SECOND_IN_WINDOW
etc
    +    // See AbstractWebAppFixtureIntegrationTest#testPublishesRequestAndErrorCountMetrics
and
    +    // testPublishesRequestsPerSecondMetric for example tests.
    +    
    +
    +    private static final Logger log = LoggerFactory.getLogger(NodeJsWebAppFixtureIntegrationTest.class);
    +    
    +    // Don't use 8080 since that is commonly used by testing software
    +    public static final String DEFAULT_HTTP_PORT = "7880+";
    +    
         public static final String GIT_REPO_URL = "https://github.com/grkvlt/node-hello-world.git";
         public static final String APP_FILE = "app.js";
         public static final String APP_NAME = "node-hello-world";
     
    -    @DataProvider(name = "basicEntities")
    -    public Object[][] basicEntities() {
    -        TestApplication nodejsApp = newTestApplication();
    -        NodeJsWebAppService nodejs = nodejsApp.createAndManageChild(EntitySpec.create(NodeJsWebAppService.class)
    +    // The parent application entity for these tests
    +    private ManagementContext mgmt;
    +    private TestApplication app;
    +    private Location loc;
    +    private NodeJsWebAppService entity;
    +    
    +    public static void main(String ...args) throws Exception {
    +        NodeJsWebAppFixtureIntegrationTest t = new NodeJsWebAppFixtureIntegrationTest();
    +        try {
    +            t.setUp();
    +            t.testReportsServiceDownWhenKilled();
    +        } finally {
    +            t.tearDown();
    +        }
    +    }
    +
    +    @BeforeMethod(alwaysRun=true)
    +    public void setUp() throws Exception {
    +        app = TestApplication.Factory.newManagedInstanceForTests();
    +        mgmt = app.getManagementContext();
    +        loc = app.newLocalhostProvisioningLocation();
    +        
    +        entity = app.createAndManageChild(EntitySpec.create(NodeJsWebAppService.class)
                     .configure(NodeJsWebAppService.HTTP_PORT, PortRanges.fromString(DEFAULT_HTTP_PORT))
                     .configure("gitRepoUrl", GIT_REPO_URL)
                     .configure("appFileName", APP_FILE)
                     .configure("appName", APP_NAME));
    +    }
    +    
    +    @AfterMethod(alwaysRun=true)
    +    public void tearDown() {
    +        if (mgmt != null) Entities.destroyAll(mgmt);
    +        mgmt = null;
    +    }
     
    -        return new WebAppService[][] {
    -                new WebAppService[] { nodejs }
    -        };
    +    /**
    +     * Checks an entity can start, set SERVICE_UP to true and shutdown again.
    +     */
    +    @Test(groups = "Integration")
    +    public void testCanStartAndStop() {
    +        log.info("test=canStartAndStop; entity="+entity+"; app="+entity.getApplication());
    +        
    +        Entities.start(entity.getApplication(), ImmutableList.of(loc));
    +        Asserts.succeedsEventually(MutableMap.of("timeout", 120*1000), new Runnable()
{
    +            public void run() {
    +                assertTrue(entity.getAttribute(Startable.SERVICE_UP));
    +            }});
    +        
    +        entity.stop();
    +        assertFalse(entity.getAttribute(Startable.SERVICE_UP));
    --- End diff --
    
    Almost all of our entity integration tests do this: so seems that contract of `stop()`
is assumed to be that `SERVICE_UP` will be false at the end. I'll leave as-is for consistency
with other entity impls.


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