brooklyn-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From geom...@apache.org
Subject [08/10] brooklyn-server git commit: misc test speed-ups
Date Fri, 28 Apr 2017 13:53:46 GMT
misc test speed-ups


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

Branch: refs/heads/master
Commit: db882bbc9581becfedb718054a5f0976db5e1d24
Parents: cca032f
Author: Alex Heneveld <alex.heneveld@cloudsoftcorp.com>
Authored: Tue Apr 25 16:08:49 2017 +0100
Committer: Alex Heneveld <alex.heneveld@cloudsoftcorp.com>
Committed: Fri Apr 28 14:09:51 2017 +0100

----------------------------------------------------------------------
 .../brooklyn/ReloadBrooklynPropertiesTest.java  |  5 ++-
 .../entity/group/DynamicClusterImpl.java        |  9 ++---
 .../entity/AbstractApplicationLegacyTest.java   |  2 +-
 .../core/entity/trait/FailingEntityImpl.java    |  4 +--
 .../internal/LocalManagementContextTest.java    | 26 ++++++++++++--
 .../core/mgmt/rebind/RebindLocationTest.java    |  1 -
 .../entity/group/DynamicClusterTest.java        | 14 ++------
 .../LoopOverGroupMembersTestCaseTest.java       | 37 +++++++-------------
 .../brooklyn/util/stream/StreamGobblerTest.java |  3 ++
 9 files changed, 53 insertions(+), 48 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/db882bbc/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/ReloadBrooklynPropertiesTest.java
----------------------------------------------------------------------
diff --git a/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/ReloadBrooklynPropertiesTest.java
b/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/ReloadBrooklynPropertiesTest.java
index 929ab89..2bdc319 100644
--- a/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/ReloadBrooklynPropertiesTest.java
+++ b/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/ReloadBrooklynPropertiesTest.java
@@ -28,6 +28,7 @@ import org.apache.brooklyn.camp.spi.AssemblyTemplate;
 import org.apache.brooklyn.core.entity.Entities;
 import org.apache.brooklyn.core.entity.EntityAsserts;
 import org.apache.brooklyn.core.entity.trait.Startable;
+import org.apache.brooklyn.core.test.entity.LocalManagementContextForTests;
 import org.apache.brooklyn.util.core.ResourceUtils;
 import org.apache.brooklyn.util.exceptions.Exceptions;
 import org.apache.brooklyn.util.stream.Streams;
@@ -46,7 +47,9 @@ public class ReloadBrooklynPropertiesTest {
     
     @BeforeMethod(alwaysRun=true)
     public void setup() {
-        brooklynMgmt = new BrooklynCampPlatformLauncherNoServer().launch().getBrooklynMgmt();
+        brooklynMgmt = new BrooklynCampPlatformLauncherNoServer().
+            useManagementContext(LocalManagementContextForTests.newInstance()).
+            launch().getBrooklynMgmt();
     }
     
     @AfterMethod(alwaysRun=true)

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/db882bbc/core/src/main/java/org/apache/brooklyn/entity/group/DynamicClusterImpl.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/entity/group/DynamicClusterImpl.java b/core/src/main/java/org/apache/brooklyn/entity/group/DynamicClusterImpl.java
index a207ec6..03eec38 100644
--- a/core/src/main/java/org/apache/brooklyn/entity/group/DynamicClusterImpl.java
+++ b/core/src/main/java/org/apache/brooklyn/entity/group/DynamicClusterImpl.java
@@ -408,12 +408,13 @@ public class DynamicClusterImpl extends AbstractGroupImpl implements
DynamicClus
         try {
             doStart();
             DynamicTasks.waitForLast();
+            ServiceStateLogic.setExpectedState(this, Lifecycle.RUNNING);
             
         } catch (Exception e) {
             ServiceProblemsLogic.updateProblemsIndicator(this, START, "start failed with
error: "+e);
+            ServiceStateLogic.setExpectedStateRunningWithErrors(this);
+            
             throw Exceptions.propagate(e);
-        } finally {
-            ServiceStateLogic.setExpectedState(this, Lifecycle.RUNNING);
         }
     }
 
@@ -956,8 +957,8 @@ public class DynamicClusterImpl extends AbstractGroupImpl implements DynamicClus
                 .putAll(extraFlags)
                 .put(CLUSTER_MEMBER_ID, sensors().get(NEXT_CLUSTER_MEMBER_ID).get())
                 .build();
-        if (LOG.isDebugEnabled()) {
-            LOG.debug("Creating and adding a node to cluster {}({}) with properties {}",
new Object[] { this, getId(), Sanitizer.sanitize(createFlags) });
+        if (LOG.isTraceEnabled()) {
+            LOG.trace("Creating and adding a node to cluster {}({}) with properties {}",
new Object[] { this, getId(), Sanitizer.sanitize(createFlags) });
         }
 
         // TODO should refactor to have a createNodeSpec; and spec should support initial
sensor values 

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/db882bbc/core/src/test/java/org/apache/brooklyn/core/entity/AbstractApplicationLegacyTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/brooklyn/core/entity/AbstractApplicationLegacyTest.java
b/core/src/test/java/org/apache/brooklyn/core/entity/AbstractApplicationLegacyTest.java
index 68ac612..1ae56cf 100644
--- a/core/src/test/java/org/apache/brooklyn/core/entity/AbstractApplicationLegacyTest.java
+++ b/core/src/test/java/org/apache/brooklyn/core/entity/AbstractApplicationLegacyTest.java
@@ -81,7 +81,7 @@ public class AbstractApplicationLegacyTest extends BrooklynAppUnitTestSupport
{
     
     // App and its children will be implicitly managed on first effector call on app.
     // Will cause the implicit creation of a new management context!
-    @Test
+    @Test(groups="Integration")  // Implicit creation is deprecaed and can be removed, plus
the test is slow
     public void testStartAndStopUnmanagedAppAutomanagesTheAppAndChildren() throws Exception
{
         // deliberately unmanaged
         TestApplication app2 = new TestApplicationImpl();

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/db882bbc/core/src/test/java/org/apache/brooklyn/core/entity/trait/FailingEntityImpl.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/brooklyn/core/entity/trait/FailingEntityImpl.java
b/core/src/test/java/org/apache/brooklyn/core/entity/trait/FailingEntityImpl.java
index bc7f483..a5b5efc 100644
--- a/core/src/test/java/org/apache/brooklyn/core/entity/trait/FailingEntityImpl.java
+++ b/core/src/test/java/org/apache/brooklyn/core/entity/trait/FailingEntityImpl.java
@@ -42,7 +42,7 @@ public class FailingEntityImpl extends TestEntityImpl implements FailingEntity
{
             if (Boolean.TRUE.equals(getConfig(SET_SERVICE_DOWN_ON_FAILURE))) {
                 ServiceStateLogic.setExpectedState(this, Lifecycle.STARTING);
                 sensors().set(SERVICE_UP, false);
-                ServiceStateLogic.setExpectedState(this, Lifecycle.RUNNING);
+                ServiceStateLogic.setExpectedStateRunningWithErrors(this);
             }
             
             callHistory.add("start");
@@ -78,7 +78,7 @@ public class FailingEntityImpl extends TestEntityImpl implements FailingEntity
{
                 sensors().set(SERVICE_UP, false);
                 ServiceStateLogic.setExpectedState(this, Lifecycle.STOPPED);
                 ServiceStateLogic.setExpectedState(this, Lifecycle.STARTING);
-                ServiceStateLogic.setExpectedState(this, Lifecycle.RUNNING);
+                ServiceStateLogic.setExpectedStateRunningWithErrors(this);
             }
 
             callHistory.add("restart");

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/db882bbc/core/src/test/java/org/apache/brooklyn/core/mgmt/internal/LocalManagementContextTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/brooklyn/core/mgmt/internal/LocalManagementContextTest.java
b/core/src/test/java/org/apache/brooklyn/core/mgmt/internal/LocalManagementContextTest.java
index 6067777..b77e685 100644
--- a/core/src/test/java/org/apache/brooklyn/core/mgmt/internal/LocalManagementContextTest.java
+++ b/core/src/test/java/org/apache/brooklyn/core/mgmt/internal/LocalManagementContextTest.java
@@ -23,6 +23,7 @@ import static org.testng.Assert.assertNotEquals;
 
 import java.io.File;
 import java.io.IOException;
+import java.util.Map;
 import java.util.concurrent.atomic.AtomicInteger;
 
 import org.apache.brooklyn.api.location.Location;
@@ -31,8 +32,11 @@ import org.apache.brooklyn.config.ConfigKey;
 import org.apache.brooklyn.core.config.ConfigKeys;
 import org.apache.brooklyn.core.internal.BrooklynProperties;
 import org.apache.brooklyn.core.internal.BrooklynProperties.Factory.Builder;
+import org.apache.brooklyn.core.server.BrooklynServerConfig;
 import org.apache.brooklyn.core.test.entity.LocalManagementContextForTests;
+import org.apache.brooklyn.util.collections.MutableMap;
 import org.apache.brooklyn.util.os.Os;
+import org.apache.brooklyn.util.text.Strings;
 import org.testng.annotations.AfterMethod;
 import org.testng.annotations.BeforeMethod;
 import org.testng.annotations.Test;
@@ -59,15 +63,21 @@ public class LocalManagementContextTest {
     
     @Test
     public void testReloadPropertiesFromBuilder() throws IOException {
-        String globalPropertiesContents = "brooklyn.location.localhost.displayName=myname";
+        String globalPropertiesContents = toMapString( LocalManagementContextForTests.builder(true)
+            .useAdditionalProperties(MutableMap.of("brooklyn.location.localhost.displayName",
"myname"))
+            .buildProperties() );
         Files.write(globalPropertiesContents, globalPropertiesFile, Charsets.UTF_8);
+        
         Builder propsBuilder = BrooklynProperties.Factory.builderDefault()
             .globalPropertiesFile(globalPropertiesFile.getAbsolutePath());
         // no builder support in LocalManagementContextForTests (we are testing that the
builder's files are reloaded so we need it here)
         context = new LocalManagementContext(propsBuilder);
         Location location = context.getLocationRegistry().getLocationManaged("localhost");
         assertEquals(location.getDisplayName(), "myname");
-        String newGlobalPropertiesContents = "brooklyn.location.localhost.displayName=myname2";
+        
+        String newGlobalPropertiesContents = toMapString( LocalManagementContextForTests.builder(true)
+            .useAdditionalProperties(MutableMap.of("brooklyn.location.localhost.displayName",
"myname2"))
+            .buildProperties() );
         Files.write(newGlobalPropertiesContents, globalPropertiesFile, Charsets.UTF_8);
         context.reloadBrooklynProperties();
         Location location2 = context.getLocationRegistry().getLocationManaged("localhost");
@@ -75,6 +85,18 @@ public class LocalManagementContextTest {
         assertEquals(location2.getDisplayName(), "myname2");
     }
     
+    private String toMapString(BrooklynProperties buildProperties) {
+        StringBuilder s = new StringBuilder();
+        Map<String, Object> props = buildProperties.asMapWithStringKeys();
+        for (String key: props.keySet()) {
+            s.append(key);
+            s.append("=");
+            s.append(props.get(key));
+            s.append("\n");
+        }
+        return s.toString();
+    }
+
     @Test
     public void testReloadPropertiesFromProperties() throws IOException {
         String globalPropertiesContents = "brooklyn.location.localhost.displayName=myname";

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/db882bbc/core/src/test/java/org/apache/brooklyn/core/mgmt/rebind/RebindLocationTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/brooklyn/core/mgmt/rebind/RebindLocationTest.java
b/core/src/test/java/org/apache/brooklyn/core/mgmt/rebind/RebindLocationTest.java
index 7af5127..9de240c 100644
--- a/core/src/test/java/org/apache/brooklyn/core/mgmt/rebind/RebindLocationTest.java
+++ b/core/src/test/java/org/apache/brooklyn/core/mgmt/rebind/RebindLocationTest.java
@@ -36,7 +36,6 @@ import org.apache.brooklyn.api.mgmt.rebind.mementos.LocationMemento;
 import org.apache.brooklyn.config.ConfigKey;
 import org.apache.brooklyn.core.config.ConfigKeys;
 import org.apache.brooklyn.core.location.AbstractLocation;
-import org.apache.brooklyn.core.mgmt.rebind.BasicLocationRebindSupport;
 import org.apache.brooklyn.core.mgmt.rebind.RebindEntityTest.MyEntity;
 import org.apache.brooklyn.core.test.entity.TestApplication;
 import org.apache.brooklyn.test.Asserts;

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/db882bbc/core/src/test/java/org/apache/brooklyn/entity/group/DynamicClusterTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/brooklyn/entity/group/DynamicClusterTest.java b/core/src/test/java/org/apache/brooklyn/entity/group/DynamicClusterTest.java
index f2d74dc..b0e115c 100644
--- a/core/src/test/java/org/apache/brooklyn/entity/group/DynamicClusterTest.java
+++ b/core/src/test/java/org/apache/brooklyn/entity/group/DynamicClusterTest.java
@@ -35,7 +35,6 @@ import java.util.Set;
 import java.util.concurrent.Callable;
 import java.util.concurrent.CopyOnWriteArrayList;
 import java.util.concurrent.CountDownLatch;
-import java.util.concurrent.ExecutionException;
 import java.util.concurrent.ExecutorService;
 import java.util.concurrent.Executors;
 import java.util.concurrent.TimeUnit;
@@ -972,16 +971,6 @@ public class DynamicClusterTest extends BrooklynAppUnitTestSupport {
         assertTrue(cluster.getAttribute(Attributes.SERVICE_UP));
     }
 
-    private Throwable unwrapException(Throwable e) {
-        if (e instanceof ExecutionException) {
-            return unwrapException(e.getCause());
-        } else if (e instanceof org.codehaus.groovy.runtime.InvokerInvocationException) {
-            return unwrapException(e.getCause());
-        } else {
-            return e;
-        }
-    }
-    
     @Test
     public void testDifferentFirstMemberSpec() throws Exception {
         DynamicCluster cluster = app.createAndManageChild(EntitySpec.create(DynamicCluster.class)
@@ -1020,6 +1009,7 @@ public class DynamicClusterTest extends BrooklynAppUnitTestSupport {
 
     @Test
     public void testPrefersMemberSpecLocation() throws Exception {
+        @SuppressWarnings("deprecation")
         DynamicCluster cluster = app.createAndManageChild(EntitySpec.create(DynamicCluster.class)
                 .configure(DynamicCluster.MEMBER_SPEC, EntitySpec.create(TestEntity.class)
                         .location(loc2))
@@ -1124,7 +1114,7 @@ public class DynamicClusterTest extends BrooklynAppUnitTestSupport {
 
         ImmutableList.Builder<RemovalStrategy> sensorMatchingStrategiesBuilder = ImmutableList.builder();
         for (int i = 0; i < clusterSize; i++){
-            SensorMatchingRemovalStrategy sensorMatchingRemovalStrategy = new SensorMatchingRemovalStrategy();
+            SensorMatchingRemovalStrategy<?> sensorMatchingRemovalStrategy = new SensorMatchingRemovalStrategy<>();
             sensorMatchingRemovalStrategy.config().set(SensorMatchingRemovalStrategy.SENSOR,
TestEntity.SEQUENCE);
             sensorMatchingRemovalStrategy.config().set(SensorMatchingRemovalStrategy.DESIRED_VALUE,
i);
             sensorMatchingStrategiesBuilder.add(sensorMatchingRemovalStrategy);

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/db882bbc/test-framework/src/test/java/org/apache/brooklyn/test/framework/LoopOverGroupMembersTestCaseTest.java
----------------------------------------------------------------------
diff --git a/test-framework/src/test/java/org/apache/brooklyn/test/framework/LoopOverGroupMembersTestCaseTest.java
b/test-framework/src/test/java/org/apache/brooklyn/test/framework/LoopOverGroupMembersTestCaseTest.java
index 09dba5a..17797bb 100644
--- a/test-framework/src/test/java/org/apache/brooklyn/test/framework/LoopOverGroupMembersTestCaseTest.java
+++ b/test-framework/src/test/java/org/apache/brooklyn/test/framework/LoopOverGroupMembersTestCaseTest.java
@@ -27,48 +27,35 @@ import java.util.List;
 import java.util.Map;
 import java.util.Set;
 
-import org.testng.annotations.AfterMethod;
-import org.testng.annotations.BeforeMethod;
-import org.testng.annotations.Test;
-
-import com.google.common.collect.ImmutableList;
-import com.google.common.collect.ImmutableMap;
-
 import org.apache.brooklyn.api.entity.Entity;
 import org.apache.brooklyn.api.entity.EntitySpec;
 import org.apache.brooklyn.api.entity.Group;
-import org.apache.brooklyn.api.location.LocationSpec;
-import org.apache.brooklyn.api.mgmt.ManagementContext;
 import org.apache.brooklyn.core.config.ConfigKeys;
 import org.apache.brooklyn.core.entity.Entities;
+import org.apache.brooklyn.core.entity.EntityAsserts;
 import org.apache.brooklyn.core.sensor.AttributeSensorAndConfigKey;
 import org.apache.brooklyn.core.test.entity.TestApplication;
 import org.apache.brooklyn.entity.group.DynamicGroup;
 import org.apache.brooklyn.entity.software.base.EmptySoftwareProcess;
-import org.apache.brooklyn.location.localhost.LocalhostMachineProvisioningLocation;
 import org.apache.brooklyn.util.collections.MutableSet;
-import org.apache.brooklyn.util.text.Identifiers;
+import org.testng.annotations.AfterMethod;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
+
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableMap;
 
 public class LoopOverGroupMembersTestCaseTest {
 
     private TestApplication app;
     private Group testGroup;
-    private ManagementContext managementContext;
-    private LocalhostMachineProvisioningLocation loc;
-    private String testId;
     private final String SENSOR_VAL = "Hello World!";
 
     private static final AttributeSensorAndConfigKey<String, String> STRING_SENSOR
= ConfigKeys.newSensorAndConfigKey(String.class, "string-sensor", "String Sensor");
 
     @BeforeMethod
     public void setup() {
-        testId = Identifiers.makeRandomId(8);
         app = TestApplication.Factory.newManagedInstanceForTests();
-        managementContext = app.getManagementContext();
-
-        loc = managementContext.getLocationManager()
-                .createLocation(LocationSpec.create(LocalhostMachineProvisioningLocation.class)
-                        .configure("name", testId));
 
         testGroup = app.createAndManageChild(EntitySpec.create(DynamicGroup.class));
     }
@@ -142,7 +129,7 @@ public class LoopOverGroupMembersTestCaseTest {
         }
     }
 
-    @Test
+    @Test(groups="Integration")  // because slow; LoopOver needs changing if we want to allow
different specs for failing and passing
     public void testMultipleChildrenOneOfWhichFails() {
         Set<EmptySoftwareProcess> emptySoftwareProcesses = addMultipleEmptySoftwareProcessesToGroup(3);
         EntitySpec<TestSensor> testSpec = createPassingTestSensorSpec();
@@ -202,7 +189,7 @@ public class LoopOverGroupMembersTestCaseTest {
 
     @Test
     public void testNoTarget() {
-        EmptySoftwareProcess emptySoftwareProcess = addEmptySoftwareProcessToGroup();
+        addEmptySoftwareProcessToGroup();
         EntitySpec<TestSensor> testSpec = createFailingTestSensorSpec();
 
         LoopOverGroupMembersTestCase loopOverGroupMembersTestCase = app.createAndManageChild(EntitySpec.create(LoopOverGroupMembersTestCase.class));
@@ -216,7 +203,7 @@ public class LoopOverGroupMembersTestCaseTest {
 
     @Test
     public void testNotTargetingGroup() {
-        EmptySoftwareProcess emptySoftwareProcess = addEmptySoftwareProcessToGroup();
+        addEmptySoftwareProcessToGroup();
         EntitySpec<TestSensor> testSpec = createFailingTestSensorSpec();
 
         LoopOverGroupMembersTestCase loopOverGroupMembersTestCase = app.createAndManageChild(EntitySpec.create(LoopOverGroupMembersTestCase.class));
@@ -231,8 +218,7 @@ public class LoopOverGroupMembersTestCaseTest {
 
     @Test
     public void testNoSpec() {
-        EmptySoftwareProcess emptySoftwareProcess = addEmptySoftwareProcessToGroup();
-        EntitySpec<TestSensor> testSpec = createFailingTestSensorSpec();
+        addEmptySoftwareProcessToGroup();
 
         LoopOverGroupMembersTestCase loopOverGroupMembersTestCase = app.createAndManageChild(EntitySpec.create(LoopOverGroupMembersTestCase.class));
         loopOverGroupMembersTestCase.config().set(LoopOverGroupMembersTestCase.TARGET_ENTITY,
testGroup);
@@ -251,6 +237,7 @@ public class LoopOverGroupMembersTestCaseTest {
 
         return EntitySpec.create(TestSensor.class)
                 .configure(TestSensor.SENSOR_NAME, STRING_SENSOR.getName())
+                .configure(TestSensor.ITERATION_LIMIT, 1)
                 .configure(TestSensor.ASSERTIONS, assertions);
     }
 

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/db882bbc/utils/common/src/test/java/org/apache/brooklyn/util/stream/StreamGobblerTest.java
----------------------------------------------------------------------
diff --git a/utils/common/src/test/java/org/apache/brooklyn/util/stream/StreamGobblerTest.java
b/utils/common/src/test/java/org/apache/brooklyn/util/stream/StreamGobblerTest.java
index a4b9cb8..3ace7be 100644
--- a/utils/common/src/test/java/org/apache/brooklyn/util/stream/StreamGobblerTest.java
+++ b/utils/common/src/test/java/org/apache/brooklyn/util/stream/StreamGobblerTest.java
@@ -61,13 +61,16 @@ public class StreamGobblerTest {
         gobbler.start();
         try {
             pipedOutputStream.write("line1\n".getBytes());
+            pipedOutputStream.flush();
             assertEqualsEventually(out, "line1" + NL);
 
             pipedOutputStream.write("line2\n".getBytes());
+            pipedOutputStream.flush();
             assertEqualsEventually(out, "line1" + NL + "line2" + NL);
 
             pipedOutputStream.write("line".getBytes());
             pipedOutputStream.write("3\n".getBytes());
+            pipedOutputStream.flush();
             assertEqualsEventually(out, "line1" + NL + "line2" + NL + "line3" + NL);
 
             pipedOutputStream.close();


Mime
View raw message