brooklyn-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aleds...@apache.org
Subject [04/11] git commit: TestJavaWebAppEntity: tidies
Date Tue, 28 Oct 2014 15:37:15 GMT
TestJavaWebAppEntity: tidies


Project: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/commit/0def1df7
Tree: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/tree/0def1df7
Diff: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/diff/0def1df7

Branch: refs/heads/master
Commit: 0def1df756026c67162427de1f65fbece65f253d
Parents: b7c4d52
Author: Aled Sage <aled.sage@gmail.com>
Authored: Fri Oct 24 17:09:16 2014 +0100
Committer: Aled Sage <aled.sage@gmail.com>
Committed: Tue Oct 28 15:35:32 2014 +0000

----------------------------------------------------------------------
 ...lledDynamicWebAppClusterIntegrationTest.java |  1 -
 .../ControlledDynamicWebAppClusterTest.java     |  2 -
 .../entity/webapp/DynamicWebAppClusterTest.java | 12 +--
 .../entity/webapp/DynamicWebAppFabricTest.java  | 12 ++-
 .../test/entity/TestJavaWebAppEntity.java       | 72 ---------------
 .../test/entity/TestJavaWebAppEntityImpl.java   | 92 ++++++++++++++++++++
 6 files changed, 107 insertions(+), 84 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/0def1df7/software/webapp/src/test/java/brooklyn/entity/webapp/ControlledDynamicWebAppClusterIntegrationTest.java
----------------------------------------------------------------------
diff --git a/software/webapp/src/test/java/brooklyn/entity/webapp/ControlledDynamicWebAppClusterIntegrationTest.java
b/software/webapp/src/test/java/brooklyn/entity/webapp/ControlledDynamicWebAppClusterIntegrationTest.java
index 471f485..4d97b40 100644
--- a/software/webapp/src/test/java/brooklyn/entity/webapp/ControlledDynamicWebAppClusterIntegrationTest.java
+++ b/software/webapp/src/test/java/brooklyn/entity/webapp/ControlledDynamicWebAppClusterIntegrationTest.java
@@ -33,7 +33,6 @@ import org.testng.annotations.Test;
 import brooklyn.entity.BrooklynAppLiveTestSupport;
 import brooklyn.entity.Entity;
 import brooklyn.entity.basic.Attributes;
-import brooklyn.entity.basic.BasicConfigurableEntityFactory;
 import brooklyn.entity.basic.Lifecycle;
 import brooklyn.entity.proxy.AbstractController;
 import brooklyn.entity.proxy.LoadBalancer;

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/0def1df7/software/webapp/src/test/java/brooklyn/entity/webapp/ControlledDynamicWebAppClusterTest.java
----------------------------------------------------------------------
diff --git a/software/webapp/src/test/java/brooklyn/entity/webapp/ControlledDynamicWebAppClusterTest.java
b/software/webapp/src/test/java/brooklyn/entity/webapp/ControlledDynamicWebAppClusterTest.java
index 366f29b..54509b7 100644
--- a/software/webapp/src/test/java/brooklyn/entity/webapp/ControlledDynamicWebAppClusterTest.java
+++ b/software/webapp/src/test/java/brooklyn/entity/webapp/ControlledDynamicWebAppClusterTest.java
@@ -29,7 +29,6 @@ import org.testng.annotations.BeforeMethod;
 import org.testng.annotations.Test;
 
 import brooklyn.entity.BrooklynAppUnitTestSupport;
-import brooklyn.entity.basic.BasicConfigurableEntityFactory;
 import brooklyn.entity.basic.Entities;
 import brooklyn.entity.basic.Lifecycle;
 import brooklyn.entity.basic.SoftwareProcess;
@@ -44,7 +43,6 @@ import brooklyn.location.basic.LocalhostMachineProvisioningLocation;
 import brooklyn.test.Asserts;
 import brooklyn.test.EntityTestUtils;
 import brooklyn.test.entity.TestJavaWebAppEntity;
-import brooklyn.test.entity.TestJavaWebAppEntity.TestJavaWebAppEntityImpl;
 
 import com.google.common.collect.ImmutableList;
 import com.google.common.collect.Iterables;

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/0def1df7/software/webapp/src/test/java/brooklyn/entity/webapp/DynamicWebAppClusterTest.java
----------------------------------------------------------------------
diff --git a/software/webapp/src/test/java/brooklyn/entity/webapp/DynamicWebAppClusterTest.java
b/software/webapp/src/test/java/brooklyn/entity/webapp/DynamicWebAppClusterTest.java
index 446aa46..9f57784 100644
--- a/software/webapp/src/test/java/brooklyn/entity/webapp/DynamicWebAppClusterTest.java
+++ b/software/webapp/src/test/java/brooklyn/entity/webapp/DynamicWebAppClusterTest.java
@@ -27,7 +27,6 @@ import org.testng.annotations.BeforeMethod;
 import org.testng.annotations.Test;
 
 import brooklyn.entity.Entity;
-import brooklyn.entity.basic.ApplicationBuilder;
 import brooklyn.entity.basic.BasicConfigurableEntityFactory;
 import brooklyn.entity.basic.Entities;
 import brooklyn.entity.basic.EntityLocal;
@@ -38,6 +37,7 @@ import brooklyn.test.Asserts;
 import brooklyn.test.EntityTestUtils;
 import brooklyn.test.entity.TestApplication;
 import brooklyn.test.entity.TestJavaWebAppEntity;
+import brooklyn.test.entity.TestJavaWebAppEntityImpl;
 import brooklyn.util.collections.MutableMap;
 
 import com.google.common.collect.ImmutableList;
@@ -54,10 +54,12 @@ public class DynamicWebAppClusterTest {
     private static final int SHORT_WAIT_MS = 250;
     
     private TestApplication app;
+    private SimulatedLocation loc;
     
     @BeforeMethod(alwaysRun=true)
     public void setUp() throws Exception {
-        app = ApplicationBuilder.newManagedApp(TestApplication.class);
+        app = TestApplication.Factory.newManagedInstanceForTests();
+        loc = app.newSimulatedLocation();
     }
     
     @AfterMethod(alwaysRun=true)
@@ -77,7 +79,7 @@ public class DynamicWebAppClusterTest {
                 .configure("initialSize", 2)
                 .configure(ControlledDynamicWebAppCluster.MEMBER_SPEC, EntitySpec.create(TestJavaWebAppEntity.class))
);
         
-        app.start(ImmutableList.of(new SimulatedLocation()));
+        app.start(ImmutableList.of(loc));
         
         for (Entity member : cluster.getMembers()) {
             ((TestJavaWebAppEntity)member).spoofRequest();
@@ -107,7 +109,7 @@ public class DynamicWebAppClusterTest {
                 .configure("initialSize", 1)
                 .configure(ControlledDynamicWebAppCluster.MEMBER_SPEC, EntitySpec.create(TestJavaWebAppEntity.class))
);
     
-        app.start(ImmutableList.of(new SimulatedLocation()));
+        app.start(ImmutableList.of(loc));
         
         // Should initially be true (now that TestJavaWebAppEntity sets true) 
         EntityTestUtils.assertAttributeEqualsEventually(MutableMap.of("timeout", TIMEOUT_MS),
cluster, DynamicWebAppCluster.SERVICE_UP, true);
@@ -136,7 +138,7 @@ public class DynamicWebAppClusterTest {
                 .configure("a", 1))
             .configure(DynamicWebAppCluster.CUSTOM_CHILD_FLAGS, ImmutableMap.of("b", 2)));
 
-        app.start(ImmutableList.of(new SimulatedLocation()));
+        app.start(ImmutableList.of(loc));
         
         TestJavaWebAppEntity we = (TestJavaWebAppEntity) Iterables.getOnlyElement(cluster.getMembers());
         assertEquals(we.getA(), 1);

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/0def1df7/software/webapp/src/test/java/brooklyn/entity/webapp/DynamicWebAppFabricTest.java
----------------------------------------------------------------------
diff --git a/software/webapp/src/test/java/brooklyn/entity/webapp/DynamicWebAppFabricTest.java
b/software/webapp/src/test/java/brooklyn/entity/webapp/DynamicWebAppFabricTest.java
index d898bf6..5a805cc 100644
--- a/software/webapp/src/test/java/brooklyn/entity/webapp/DynamicWebAppFabricTest.java
+++ b/software/webapp/src/test/java/brooklyn/entity/webapp/DynamicWebAppFabricTest.java
@@ -27,11 +27,12 @@ import org.testng.annotations.BeforeMethod;
 import org.testng.annotations.Test;
 
 import brooklyn.entity.Entity;
-import brooklyn.entity.basic.ApplicationBuilder;
 import brooklyn.entity.basic.DynamicGroup;
 import brooklyn.entity.basic.Entities;
 import brooklyn.entity.basic.EntityInternal;
+import brooklyn.entity.basic.EntityLocal;
 import brooklyn.entity.proxying.EntitySpec;
+import brooklyn.entity.trait.Changeable;
 import brooklyn.location.basic.SimulatedLocation;
 import brooklyn.test.EntityTestUtils;
 import brooklyn.test.entity.TestApplication;
@@ -55,9 +56,9 @@ public class DynamicWebAppFabricTest {
     
     @BeforeMethod(alwaysRun=true)
     public void setUp() throws Exception {
-        app = ApplicationBuilder.newManagedApp(TestApplication.class);
-        loc1 = new SimulatedLocation();
-        loc2 = new SimulatedLocation();
+        app = TestApplication.Factory.newManagedInstanceForTests();
+        loc1 = app.newSimulatedLocation();
+        loc2 = app.newSimulatedLocation();
         locs = ImmutableList.of(loc1, loc2);
     }
     
@@ -72,6 +73,9 @@ public class DynamicWebAppFabricTest {
                 .configure(DynamicWebAppFabric.MEMBER_SPEC, EntitySpec.create(TestJavaWebAppEntity.class))
);
         
         app.start(locs);
+        for (Entity member : fabric.getChildren()) {
+            ((EntityLocal)member).setAttribute(Changeable.GROUP_SIZE, 1);
+        }
         
         for (Entity member : fabric.getChildren()) {
             ((EntityInternal)member).setAttribute(DynamicGroup.GROUP_SIZE, 1);

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/0def1df7/software/webapp/src/test/java/brooklyn/test/entity/TestJavaWebAppEntity.java
----------------------------------------------------------------------
diff --git a/software/webapp/src/test/java/brooklyn/test/entity/TestJavaWebAppEntity.java
b/software/webapp/src/test/java/brooklyn/test/entity/TestJavaWebAppEntity.java
index 48d5376..8710d0b 100644
--- a/software/webapp/src/test/java/brooklyn/test/entity/TestJavaWebAppEntity.java
+++ b/software/webapp/src/test/java/brooklyn/test/entity/TestJavaWebAppEntity.java
@@ -18,24 +18,9 @@
  */
 package brooklyn.test.entity;
 
-import java.util.Map;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import brooklyn.entity.Entity;
-import brooklyn.entity.basic.Attributes;
-import brooklyn.entity.basic.Lifecycle;
-import brooklyn.entity.basic.ServiceStateLogic;
-import brooklyn.entity.basic.SoftwareProcessDriverLifecycleEffectorTasks;
 import brooklyn.entity.java.VanillaJavaApp;
-import brooklyn.entity.java.VanillaJavaAppImpl;
 import brooklyn.entity.proxying.ImplementedBy;
 import brooklyn.entity.webapp.WebAppService;
-import brooklyn.entity.webapp.WebAppServiceConstants;
-import brooklyn.location.Location;
-import brooklyn.test.entity.TestJavaWebAppEntity.TestJavaWebAppEntityImpl;
-import brooklyn.util.flags.SetFromFlag;
 
 /**
  * Mock web application server entity for testing.
@@ -47,61 +32,4 @@ public interface TestJavaWebAppEntity extends VanillaJavaApp, WebAppService
{
     int getA();
     int getB();
     int getC();
-    
-    public static class TestJavaWebAppEntityImpl extends VanillaJavaAppImpl implements TestJavaWebAppEntity
{
-
-        private static final Logger LOG = LoggerFactory.getLogger(TestJavaWebAppEntity.class);
-
-        @SetFromFlag public int a;
-        @SetFromFlag public int b;
-        @SetFromFlag public int c;
-
-        public TestJavaWebAppEntityImpl() {}
-        public TestJavaWebAppEntityImpl(@SuppressWarnings("rawtypes") Map flags, Entity parent)
{ super(flags, parent); }
-
-        private static final SoftwareProcessDriverLifecycleEffectorTasks LIFECYCLE_TASKS
=
-            new SoftwareProcessDriverLifecycleEffectorTasks() {
-            public void start(java.util.Collection<? extends Location> locations) {
-                ServiceStateLogic.setExpectedState(entity(), Lifecycle.STARTING);
-                LOG.trace("Starting {}", this);
-                entity().setAttribute(Attributes.SERVICE_UP, true);
-                ServiceStateLogic.setExpectedState(entity(), Lifecycle.RUNNING);
-            }
-            public void stop() {
-                ServiceStateLogic.setExpectedState(entity(), Lifecycle.STOPPING);
-                LOG.trace("Stopping {}", this);
-                entity().setAttribute(Attributes.SERVICE_UP, false);
-                ServiceStateLogic.setExpectedState(entity(), Lifecycle.STOPPED);
-            }
-        };
-
-        @Override
-        public void init() {
-            super.init();
-            LIFECYCLE_TASKS.attachLifecycleEffectors(this);
-        }
-
-        @Override
-        public synchronized void spoofRequest() {
-            Integer rc = getAttribute(WebAppServiceConstants.REQUEST_COUNT);
-            if (rc==null) rc = 0;
-            setAttribute(WebAppServiceConstants.REQUEST_COUNT, rc+1);
-        }
-
-        @Override
-        public int getA() {
-            return a;
-        }
-        
-        @Override
-        public int getB() {
-            return b;
-        }
-        
-        @Override
-        public int getC() {
-            return c;
-        }
-    }
-
 }

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/0def1df7/software/webapp/src/test/java/brooklyn/test/entity/TestJavaWebAppEntityImpl.java
----------------------------------------------------------------------
diff --git a/software/webapp/src/test/java/brooklyn/test/entity/TestJavaWebAppEntityImpl.java
b/software/webapp/src/test/java/brooklyn/test/entity/TestJavaWebAppEntityImpl.java
new file mode 100644
index 0000000..ea7e440
--- /dev/null
+++ b/software/webapp/src/test/java/brooklyn/test/entity/TestJavaWebAppEntityImpl.java
@@ -0,0 +1,92 @@
+/*
+ * 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 brooklyn.test.entity;
+
+import java.util.Map;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import brooklyn.entity.Entity;
+import brooklyn.entity.basic.Attributes;
+import brooklyn.entity.basic.Lifecycle;
+import brooklyn.entity.basic.ServiceStateLogic;
+import brooklyn.entity.basic.SoftwareProcessDriverLifecycleEffectorTasks;
+import brooklyn.entity.java.VanillaJavaAppImpl;
+import brooklyn.entity.webapp.WebAppServiceConstants;
+import brooklyn.location.Location;
+import brooklyn.util.flags.SetFromFlag;
+
+public class TestJavaWebAppEntityImpl extends VanillaJavaAppImpl implements TestJavaWebAppEntity
{
+
+    private static final Logger LOG = LoggerFactory.getLogger(TestJavaWebAppEntity.class);
+
+    @SetFromFlag public int a;
+    @SetFromFlag public int b;
+    @SetFromFlag public int c;
+
+    public TestJavaWebAppEntityImpl() {}
+    
+    // constructor required for use in DynamicCluster.factory
+    public TestJavaWebAppEntityImpl(@SuppressWarnings("rawtypes") Map flags, Entity parent)
{ super(flags, parent); }
+
+    private static final SoftwareProcessDriverLifecycleEffectorTasks LIFECYCLE_TASKS =
+        new SoftwareProcessDriverLifecycleEffectorTasks() {
+        public void start(java.util.Collection<? extends Location> locations) {
+            ServiceStateLogic.setExpectedState(entity(), Lifecycle.STARTING);
+            LOG.trace("Starting {}", this);
+            entity().setAttribute(Attributes.SERVICE_UP, true);
+            ServiceStateLogic.setExpectedState(entity(), Lifecycle.RUNNING);
+        }
+        public void stop() {
+            ServiceStateLogic.setExpectedState(entity(), Lifecycle.STOPPING);
+            LOG.trace("Stopping {}", this);
+            entity().setAttribute(Attributes.SERVICE_UP, false);
+            ServiceStateLogic.setExpectedState(entity(), Lifecycle.STOPPED);
+        }
+    };
+
+    @Override
+    public void init() {
+        super.init();
+        LIFECYCLE_TASKS.attachLifecycleEffectors(this);
+    }
+
+    @Override
+    public synchronized void spoofRequest() {
+        Integer rc = getAttribute(WebAppServiceConstants.REQUEST_COUNT);
+        if (rc==null) rc = 0;
+        setAttribute(WebAppServiceConstants.REQUEST_COUNT, rc+1);
+    }
+
+    @Override
+    public int getA() {
+        return a;
+    }
+    
+    @Override
+    public int getB() {
+        return b;
+    }
+    
+    @Override
+    public int getC() {
+        return c;
+    }
+}


Mime
View raw message