brooklyn-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rich...@apache.org
Subject [2/4] git commit: Convert DynamicWebAppClusterTest from groovy to java
Date Sun, 15 Jun 2014 03:25:14 GMT
Convert DynamicWebAppClusterTest from groovy to java


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

Branch: refs/heads/master
Commit: 1bd0d9ee27041bf9297da1905778b28900eb3182
Parents: d3312f1
Author: Aled Sage <aled.sage@gmail.com>
Authored: Fri Jun 13 20:47:44 2014 +0100
Committer: Aled Sage <aled.sage@gmail.com>
Committed: Fri Jun 13 23:05:24 2014 +0100

----------------------------------------------------------------------
 .../webapp/DynamicWebAppClusterTest.groovy      | 122 ------------------
 .../entity/webapp/DynamicWebAppClusterTest.java | 124 +++++++++++++++++++
 .../test/entity/JavaWebAppTestEntities.groovy   |   6 +-
 3 files changed, 127 insertions(+), 125 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/1bd0d9ee/software/webapp/src/test/java/brooklyn/entity/webapp/DynamicWebAppClusterTest.groovy
----------------------------------------------------------------------
diff --git a/software/webapp/src/test/java/brooklyn/entity/webapp/DynamicWebAppClusterTest.groovy
b/software/webapp/src/test/java/brooklyn/entity/webapp/DynamicWebAppClusterTest.groovy
deleted file mode 100644
index b61cf55..0000000
--- a/software/webapp/src/test/java/brooklyn/entity/webapp/DynamicWebAppClusterTest.groovy
+++ /dev/null
@@ -1,122 +0,0 @@
-package brooklyn.entity.webapp;
-
-import static brooklyn.test.TestUtils.*
-import static java.util.concurrent.TimeUnit.*
-import static org.testng.AssertJUnit.*
-
-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.ApplicationBuilder
-import brooklyn.entity.basic.Entities
-import brooklyn.entity.proxying.EntitySpec
-import brooklyn.entity.trait.Startable
-import brooklyn.location.basic.SimulatedLocation
-import brooklyn.test.EntityTestUtils
-import brooklyn.test.entity.TestApplication
-import brooklyn.test.entity.TestJavaWebAppEntity
-import brooklyn.util.collections.MutableMap
-import brooklyn.util.internal.TimeExtras
-
-import com.google.common.collect.Iterables
-
-/**
- * TODO clarify test purpose
- */
-public class DynamicWebAppClusterTest {
-    private static final Logger log = LoggerFactory.getLogger(this)
-    
-    private static final int TIMEOUT_MS = 1*1000;
-    private static final int SHORT_WAIT_MS = 250;
-    
-    static { TimeExtras.init() }
-
-    private TestApplication app;
-    
-    @BeforeMethod(alwaysRun=true)
-    public void setUp() throws Exception {
-        app = ApplicationBuilder.newManagedApp(TestApplication.class);
-    }
-    
-    @AfterMethod(alwaysRun=true)
-    public void tearDown() throws Exception {
-        if (app != null) Entities.destroyAll(app.getManagementContext());
-    }
-
-    @Test
-    public void testTestJWAEntity() {
-        Entity test = app.createAndManageChild(EntitySpec.create(Entity.class, TestJavaWebAppEntity.class))
-        try {
-            test.invoke(Startable.START, [locations:[]]).get()
-        } catch (Throwable t) {
-            t.printStackTrace();
-            throw t;
-        }
-//        ((Startable)test).start([])
-    }
-    
-    @Test
-    public void testRequestCountAggregation() {
-        DynamicWebAppCluster cluster = app.createAndManageChild(EntitySpec.create(DynamicWebAppCluster.class)
-                .configure("initialSize", 2)
-                .configure("factory", { properties -> new TestJavaWebAppEntity(properties)
}));
-        
-        app.start([new SimulatedLocation()])
-        
-        cluster.members.each { it.spoofRequest() }
-        executeUntilSucceeds(timeout: 3*SECONDS) {
-            // intermittent failure observed 4 may 2012
-            assertEquals 2, cluster.getAttribute(DynamicWebAppCluster.REQUEST_COUNT)
-        }
-        
-        cluster.members.each { it.spoofRequest(); it.spoofRequest() }
-        executeUntilSucceeds(timeout: 3*SECONDS) {
-            assertEquals 3d, cluster.getAttribute(DynamicWebAppCluster.REQUEST_COUNT_PER_NODE)
-        }
-    }
-    
-    @Test
-    public void testSetsServiceUpIfMemberIsUp() throws Exception {
-        DynamicWebAppCluster cluster = app.createAndManageChild(EntitySpec.create(DynamicWebAppCluster.class)
-            .configure("initialSize", 1)
-            .configure("factory", { properties -> new TestJavaWebAppEntity(properties)
}));
-    
-        app.start([new SimulatedLocation()])
-        
-        // Should initially be false (when child has no service_up value) 
-        EntityTestUtils.assertAttributeEqualsEventually(MutableMap.of("timeout", TIMEOUT_MS),
cluster, DynamicWebAppCluster.SERVICE_UP, false);
-        
-        // When child is !service_up, should continue to report false
-        Iterables.get(cluster.getMembers(), 0).setAttribute(Startable.SERVICE_UP, false);
-        EntityTestUtils.assertAttributeEqualsContinually(MutableMap.of("timeout", SHORT_WAIT_MS),
cluster, DynamicWebAppCluster.SERVICE_UP, false);
-        
-        cluster.resize(2);
-        
-        // When one of the two children is service_up, should report true
-        Iterables.get(cluster.getMembers(), 0).setAttribute(Startable.SERVICE_UP, true);
-        EntityTestUtils.assertAttributeEqualsEventually(MutableMap.of("timeout", TIMEOUT_MS),
cluster, DynamicWebAppCluster.SERVICE_UP, true);
-
-        // And if that serviceUp child goes away, should again report false
-        Entities.unmanage(Iterables.get(cluster.getMembers(), 0));
-        EntityTestUtils.assertAttributeEqualsEventually(MutableMap.of("timeout", TIMEOUT_MS),
cluster, DynamicWebAppCluster.SERVICE_UP, false);
-    }
-    
-    @Test
-    public void testPropertiesToChildren() {
-        DynamicWebAppCluster cluster = app.createAndManageChild(EntitySpec.create(DynamicWebAppCluster.class)
-            .configure(DynamicWebAppCluster.FACTORY, { properties -> new TestJavaWebAppEntity(properties
+ ["a": 1]) })
-            .configure(DynamicWebAppCluster.CUSTOM_CHILD_FLAGS, ["b":2]));
-
-        Entities.manage(cluster);
-        
-        app.start([new SimulatedLocation()])
-        assertEquals 1, cluster.members.size()
-        TestJavaWebAppEntity we = Iterables.get(cluster.getMembers(), 0);
-        assertEquals we.a, 1
-        assertEquals we.b, 2
-    }
-}

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/1bd0d9ee/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
new file mode 100644
index 0000000..7785d19
--- /dev/null
+++ b/software/webapp/src/test/java/brooklyn/entity/webapp/DynamicWebAppClusterTest.java
@@ -0,0 +1,124 @@
+package brooklyn.entity.webapp;
+
+import static org.testng.Assert.assertEquals;
+
+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.ApplicationBuilder;
+import brooklyn.entity.basic.BasicConfigurableEntityFactory;
+import brooklyn.entity.basic.Entities;
+import brooklyn.entity.basic.EntityLocal;
+import brooklyn.entity.proxying.EntitySpec;
+import brooklyn.entity.trait.Startable;
+import brooklyn.location.basic.SimulatedLocation;
+import brooklyn.test.Asserts;
+import brooklyn.test.EntityTestUtils;
+import brooklyn.test.entity.TestApplication;
+import brooklyn.test.entity.TestJavaWebAppEntity;
+import brooklyn.util.collections.MutableMap;
+
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.Iterables;
+
+/**
+ * TODO clarify test purpose
+ */
+public class DynamicWebAppClusterTest {
+    private static final Logger log = LoggerFactory.getLogger(DynamicWebAppClusterTest.class);
+    
+    private static final int TIMEOUT_MS = 1*1000;
+    private static final int SHORT_WAIT_MS = 250;
+    
+    private TestApplication app;
+    
+    @BeforeMethod(alwaysRun=true)
+    public void setUp() throws Exception {
+        app = ApplicationBuilder.newManagedApp(TestApplication.class);
+    }
+    
+    @AfterMethod(alwaysRun=true)
+    public void tearDown() throws Exception {
+        if (app != null) Entities.destroyAll(app.getManagementContext());
+    }
+
+    @Test
+    public void testTestJavaWebAppEntity() throws Exception {
+        Entity test = app.createAndManageChild(EntitySpec.create(Entity.class, TestJavaWebAppEntity.class));
+        test.invoke(Startable.START, ImmutableMap.of("locations", ImmutableList.of())).get();
+    }
+    
+    @Test
+    public void testRequestCountAggregation() throws Exception {
+        final DynamicWebAppCluster cluster = app.createAndManageChild(EntitySpec.create(DynamicWebAppCluster.class)
+                .configure("initialSize", 2)
+                .configure("factory", new BasicConfigurableEntityFactory<TestJavaWebAppEntity>(TestJavaWebAppEntity.class)));
+        
+        app.start(ImmutableList.of(new SimulatedLocation()));
+        
+        for (Entity member : cluster.getMembers()) {
+            ((TestJavaWebAppEntity)member).spoofRequest();
+        }
+        
+        Asserts.succeedsEventually(new Runnable() {
+            @Override public void run() {
+                // intermittent failure observed 4 may 2012
+                assertEquals(cluster.getAttribute(DynamicWebAppCluster.REQUEST_COUNT), (Integer)2);
+            }});
+        
+        for (Entity member : cluster.getMembers()) {
+            for (int i = 0; i < 2; i++) {
+                ((TestJavaWebAppEntity)member).spoofRequest();
+            }
+        }
+        Asserts.succeedsEventually(new Runnable() {
+            @Override public void run() {
+                // intermittent failure observed 4 may 2012
+                assertEquals(cluster.getAttribute(DynamicWebAppCluster.REQUEST_COUNT_PER_NODE),
(Double)3d);
+            }});
+    }
+    
+    @Test
+    public void testSetsServiceUpIfMemberIsUp() throws Exception {
+        DynamicWebAppCluster cluster = app.createAndManageChild(EntitySpec.create(DynamicWebAppCluster.class)
+                .configure("initialSize", 1)
+                .configure("factory", new BasicConfigurableEntityFactory<TestJavaWebAppEntity>(TestJavaWebAppEntity.class)));
+    
+        app.start(ImmutableList.of(new SimulatedLocation()));
+        
+        // Should initially be false (when child has no service_up value) 
+        EntityTestUtils.assertAttributeEqualsEventually(MutableMap.of("timeout", TIMEOUT_MS),
cluster, DynamicWebAppCluster.SERVICE_UP, false);
+        
+        // When child is !service_up, should continue to report false
+        ((EntityLocal)Iterables.get(cluster.getMembers(), 0)).setAttribute(Startable.SERVICE_UP,
false);
+        EntityTestUtils.assertAttributeEqualsContinually(MutableMap.of("timeout", SHORT_WAIT_MS),
cluster, DynamicWebAppCluster.SERVICE_UP, false);
+        
+        cluster.resize(2);
+        
+        // When one of the two children is service_up, should report true
+        ((EntityLocal)Iterables.get(cluster.getMembers(), 0)).setAttribute(Startable.SERVICE_UP,
true);
+        EntityTestUtils.assertAttributeEqualsEventually(MutableMap.of("timeout", TIMEOUT_MS),
cluster, DynamicWebAppCluster.SERVICE_UP, true);
+
+        // And if that serviceUp child goes away, should again report false
+        Entities.unmanage(Iterables.get(cluster.getMembers(), 0));
+        EntityTestUtils.assertAttributeEqualsEventually(MutableMap.of("timeout", TIMEOUT_MS),
cluster, DynamicWebAppCluster.SERVICE_UP, false);
+    }
+    
+    @Test
+    public void testPropertiesToChildren() throws Exception {
+        DynamicWebAppCluster cluster = app.createAndManageChild(EntitySpec.create(DynamicWebAppCluster.class)
+            .configure("factory", new BasicConfigurableEntityFactory<TestJavaWebAppEntity>(MutableMap.of("a",
1), TestJavaWebAppEntity.class))
+            .configure(DynamicWebAppCluster.CUSTOM_CHILD_FLAGS, ImmutableMap.of("b", 2)));
+
+        app.start(ImmutableList.of(new SimulatedLocation()));
+        
+        TestJavaWebAppEntity we = (TestJavaWebAppEntity) Iterables.getOnlyElement(cluster.getMembers());
+        assertEquals(we.a, 1);
+        assertEquals(we.b, 2);
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/1bd0d9ee/software/webapp/src/test/java/brooklyn/test/entity/JavaWebAppTestEntities.groovy
----------------------------------------------------------------------
diff --git a/software/webapp/src/test/java/brooklyn/test/entity/JavaWebAppTestEntities.groovy
b/software/webapp/src/test/java/brooklyn/test/entity/JavaWebAppTestEntities.groovy
index 7e98c1d..bb16a1f 100644
--- a/software/webapp/src/test/java/brooklyn/test/entity/JavaWebAppTestEntities.groovy
+++ b/software/webapp/src/test/java/brooklyn/test/entity/JavaWebAppTestEntities.groovy
@@ -24,9 +24,9 @@ public class TestJavaWebAppEntity extends VanillaJavaAppImpl {
         super(properties, parent)
     }
     
-    @SetFromFlag int a;
-    @SetFromFlag int b;
-    @SetFromFlag int c;
+    @SetFromFlag public int a;
+    @SetFromFlag public int b;
+    @SetFromFlag public int c;
 
 	public void waitForHttpPort() { }
 


Mime
View raw message