brooklyn-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From henev...@apache.org
Subject [12/23] brooklyn-server git commit: fix tests that asserted specific tasks (as there are now more)
Date Fri, 06 Oct 2017 08:06:36 GMT
fix tests that asserted specific tasks (as there are now more)


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

Branch: refs/heads/master
Commit: 130a29b906da83f108ae1ea6cebef94c0c5f6a6f
Parents: 79cc9bc
Author: Alex Heneveld <alex.heneveld@cloudsoftcorp.com>
Authored: Wed Sep 20 13:37:21 2017 +0100
Committer: Alex Heneveld <alex.heneveld@cloudsoftcorp.com>
Committed: Wed Sep 20 13:37:21 2017 +0100

----------------------------------------------------------------------
 .../mgmt/internal/LocalSubscriptionManager.java |  2 +-
 .../core/entity/hello/LocalEntitiesTest.java    | 20 +++++++++-----------
 .../internal/EntityExecutionManagerTest.java    | 15 ++++++++++++---
 .../core/mgmt/rebind/RebindFeedWithHaTest.java  |  9 +++++++--
 4 files changed, 29 insertions(+), 17 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/130a29b9/core/src/main/java/org/apache/brooklyn/core/mgmt/internal/LocalSubscriptionManager.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/core/mgmt/internal/LocalSubscriptionManager.java
b/core/src/main/java/org/apache/brooklyn/core/mgmt/internal/LocalSubscriptionManager.java
index 6b1a5d9..a927a89 100644
--- a/core/src/main/java/org/apache/brooklyn/core/mgmt/internal/LocalSubscriptionManager.java
+++ b/core/src/main/java/org/apache/brooklyn/core/mgmt/internal/LocalSubscriptionManager.java
@@ -147,7 +147,7 @@ public class LocalSubscriptionManager extends AbstractSubscriptionManager
{
             } else {
                 if (LOG.isTraceEnabled()) LOG.trace("sending initial value of {} -> {}
to {}", new Object[] {s.producer, s.sensor, s});
                 em.submit(
-                    MutableMap.of("tags", ImmutableList.of(BrooklynTaskTags.tagForContextEntity(s.producer)),
+                    MutableMap.of("tags", ImmutableList.of(BrooklynTaskTags.tagForContextEntity(s.producer),
BrooklynTaskTags.SENSOR_TAG),
                         "displayName", "Initial publication of "+s.sensor.getName()),
                     () -> {
                         T val = (T) s.producer.getAttribute((AttributeSensor<?>) s.sensor);

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/130a29b9/core/src/test/java/org/apache/brooklyn/core/entity/hello/LocalEntitiesTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/brooklyn/core/entity/hello/LocalEntitiesTest.java
b/core/src/test/java/org/apache/brooklyn/core/entity/hello/LocalEntitiesTest.java
index 985997e..6951a97 100644
--- a/core/src/test/java/org/apache/brooklyn/core/entity/hello/LocalEntitiesTest.java
+++ b/core/src/test/java/org/apache/brooklyn/core/entity/hello/LocalEntitiesTest.java
@@ -33,20 +33,19 @@ import java.util.concurrent.TimeUnit;
 import java.util.concurrent.atomic.AtomicReference;
 
 import org.apache.brooklyn.api.entity.EntitySpec;
-import org.apache.brooklyn.api.mgmt.EntityManager;
 import org.apache.brooklyn.api.mgmt.Task;
 import org.apache.brooklyn.api.sensor.SensorEvent;
 import org.apache.brooklyn.api.sensor.SensorEventListener;
 import org.apache.brooklyn.core.entity.EntityInternal;
 import org.apache.brooklyn.core.location.SimulatedLocation;
 import org.apache.brooklyn.core.test.BrooklynAppUnitTestSupport;
+import org.apache.brooklyn.test.Asserts;
+import org.apache.brooklyn.util.time.Duration;
+import org.apache.brooklyn.util.time.Time;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.testng.annotations.BeforeMethod;
 import org.testng.annotations.Test;
-import org.apache.brooklyn.test.Asserts;
-import org.apache.brooklyn.util.collections.MutableMap;
-import org.apache.brooklyn.util.time.Time;
 
 import com.google.common.base.Function;
 import com.google.common.base.Predicate;
@@ -63,14 +62,12 @@ public class LocalEntitiesTest extends BrooklynAppUnitTestSupport {
     public static final Logger log = LoggerFactory.getLogger(LocalEntitiesTest.class);
     
     private SimulatedLocation loc;
-    private EntityManager entityManager;
             
     @BeforeMethod(alwaysRun=true)
     @Override
     public void setUp() throws Exception {
         super.setUp();
         loc = new SimulatedLocation();
-        entityManager = mgmt.getEntityManager();
     }
 
     @Test
@@ -165,9 +162,10 @@ public class LocalEntitiesTest extends BrooklynAppUnitTestSupport {
         h.setAge(6);
         long totalTime = stopwatch.elapsed(TimeUnit.MILLISECONDS);
         
-        // TODO guava util for (1..5)
-        Asserts.continually(MutableMap.of("timeout", 50), Suppliers.ofInstance(data), Predicates.<Object>equalTo(ImmutableList.of(1,2,3,4,5)));
-        assertTrue(totalTime < 2000, "totalTime="+totalTime);  //shouldn't have blocked
for anywhere close to 2s (Aled says TODO: too time sensitive for BuildHive?)
+        Asserts.continually(
+            Suppliers.ofInstance(data), Predicates.<Object>equalTo(ImmutableList.of(1,2,3,4,5)),
+            Duration.millis(50), null, null);
+        assertTrue(totalTime < 2000, "totalTime="+totalTime);  //shouldn't have blocked
for anywhere close to 2s (unless build machine v v slow eg BuildHive)
     }
 
     @Test
@@ -224,8 +222,8 @@ public class LocalEntitiesTest extends BrooklynAppUnitTestSupport {
         assertTrue(System.currentTimeMillis() - startTime < 1500);
         synchronized (sonsConfig) {
             assertEquals(null, sonsConfig[0]);
-            for (Task tt : ((EntityInternal)dad).getExecutionContext().getTasks()) { log.info("task
at dad:  {}, {}", tt, tt.getStatusDetail(false)); }
-            for (Task tt : ((EntityInternal)son).getExecutionContext().getTasks()) { log.info("task
at son:  {}, {}", tt, tt.getStatusDetail(false)); }
+            for (Task<?> tt : ((EntityInternal)dad).getExecutionContext().getTasks())
{ log.info("task at dad:  {}, {}", tt, tt.getStatusDetail(false)); }
+            for (Task<?> tt : ((EntityInternal)son).getExecutionContext().getTasks())
{ log.info("task at son:  {}, {}", tt, tt.getStatusDetail(false)); }
             dad.sensors().set(HelloEntity.FAVOURITE_NAME, "Dan");
             if (!s1.tryAcquire(2, TimeUnit.SECONDS)) fail("race mismatch, missing permits");
         }

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/130a29b9/core/src/test/java/org/apache/brooklyn/core/mgmt/internal/EntityExecutionManagerTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/brooklyn/core/mgmt/internal/EntityExecutionManagerTest.java
b/core/src/test/java/org/apache/brooklyn/core/mgmt/internal/EntityExecutionManagerTest.java
index 97f02b7..4f581f5 100644
--- a/core/src/test/java/org/apache/brooklyn/core/mgmt/internal/EntityExecutionManagerTest.java
+++ b/core/src/test/java/org/apache/brooklyn/core/mgmt/internal/EntityExecutionManagerTest.java
@@ -30,6 +30,7 @@ import java.util.Set;
 import java.util.concurrent.CountDownLatch;
 import java.util.concurrent.TimeUnit;
 import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.stream.Collectors;
 
 import org.apache.brooklyn.api.entity.Entity;
 import org.apache.brooklyn.api.entity.EntitySpec;
@@ -46,6 +47,7 @@ import org.apache.brooklyn.core.test.BrooklynAppUnitTestSupport;
 import org.apache.brooklyn.core.test.entity.LocalManagementContextForTests;
 import org.apache.brooklyn.core.test.entity.TestEntity;
 import org.apache.brooklyn.test.Asserts;
+import org.apache.brooklyn.util.collections.MutableList;
 import org.apache.brooklyn.util.collections.MutableMap;
 import org.apache.brooklyn.util.collections.MutableSet;
 import org.apache.brooklyn.util.core.task.BasicExecutionManager;
@@ -149,6 +151,7 @@ public class EntityExecutionManagerTest extends BrooklynAppUnitTestSupport
{
         for (Task<?> t: tasks) {
             if (t instanceof ScheduledTask) continue;
             if (t.getTags().contains(BrooklynTaskTags.SENSOR_TAG)) continue;
+            if (t.getDisplayName().contains("Validating")) continue;
             result.add(t);
         }
         return result;
@@ -294,8 +297,6 @@ public class EntityExecutionManagerTest extends BrooklynAppUnitTestSupport
{
         forceGc();
         stopCondition.set(true);
 
-        // might need an eventually here, if the internal job completion and GC is done in
the background
-        // (if there are no test failures for a few months, since Sept 2014, then we can
remove this comment)
         assertTaskMaxCountForEntityEventually(e, 2);
     }
 
@@ -343,7 +344,15 @@ public class EntityExecutionManagerTest extends BrooklynAppUnitTestSupport
{
         forceGc();
         Collection<Task<?>> t2 = em.getAllTasks();
 
-        Assert.assertEquals(t1.size(), t2.size(), "lists are different:\n"+t1+"\n"+t2+"\n");
+        // no tasks from first batch were GC'd
+        Asserts.assertSize(MutableList.builder().addAll(t1).removeAll(t2).build(), 0);
+
+        // and we expect just the add/remove cycle at parent, and service problems
+        Set<String> newOnes = MutableList.<Task<?>>builder().addAll(t2).removeAll(t1).build().stream().map(
+            (t) -> t.getDisplayName()).collect(Collectors.toSet());
+        Function<String,String> prefix = (s) -> "sensor "+app.getId()+":"+s;
+        Assert.assertEquals(newOnes, MutableSet.of(
+            prefix.apply("entity.children.removed"), prefix.apply("entity.children.added"),
prefix.apply("service.problems"))); 
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/130a29b9/core/src/test/java/org/apache/brooklyn/core/mgmt/rebind/RebindFeedWithHaTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/brooklyn/core/mgmt/rebind/RebindFeedWithHaTest.java
b/core/src/test/java/org/apache/brooklyn/core/mgmt/rebind/RebindFeedWithHaTest.java
index a38a873..319311a 100644
--- a/core/src/test/java/org/apache/brooklyn/core/mgmt/rebind/RebindFeedWithHaTest.java
+++ b/core/src/test/java/org/apache/brooklyn/core/mgmt/rebind/RebindFeedWithHaTest.java
@@ -24,6 +24,7 @@ import java.net.URL;
 import java.util.Collection;
 import java.util.List;
 import java.util.concurrent.Callable;
+import java.util.stream.Collectors;
 
 import org.apache.brooklyn.api.entity.EntitySpec;
 import org.apache.brooklyn.api.mgmt.Task;
@@ -31,7 +32,6 @@ import org.apache.brooklyn.api.mgmt.ha.HighAvailabilityMode;
 import org.apache.brooklyn.api.sensor.AttributeSensor;
 import org.apache.brooklyn.api.sensor.Feed;
 import org.apache.brooklyn.core.entity.EntityAsserts;
-import org.apache.brooklyn.core.mgmt.internal.LocalManagementContext;
 import org.apache.brooklyn.core.test.entity.TestApplication;
 import org.apache.brooklyn.core.test.entity.TestEntity;
 import org.apache.brooklyn.util.core.http.BetterMockWebServer;
@@ -102,10 +102,11 @@ public class RebindFeedWithHaTest extends RebindTestFixtureWithApp {
             @Override
             public Boolean call() throws Exception {
                 origManagementContext.getGarbageCollector().gcIteration();
-                List<Task<?>> tasksAfter = ((BasicExecutionManager)origManagementContext.getExecutionManager()).getAllTasks();
+                List<Task<?>> tasksAfter = removeSystemTasks( ((BasicExecutionManager)origManagementContext.getExecutionManager()).getAllTasks()
);
                 log.info("tasks after disabling HA, "+tasksAfter.size()+": "+tasksAfter);
                 return tasksAfter.isEmpty();
             }
+
         }).runRequiringTrue();
         
         newManagementContext = createNewManagementContext();
@@ -123,6 +124,10 @@ public class RebindFeedWithHaTest extends RebindTestFixtureWithApp {
         EntityAsserts.assertAttributeEqualsEventually(newEntity, SENSOR_STRING, "{\"foo\":\"myfoo\"}");
     }
 
+    static List<Task<?>> removeSystemTasks(List<Task<?>> tasks) {
+        return tasks.stream().filter(t -> !("rebind".equals(t.getDisplayName()) || t.getDisplayName().contains("Validating"))).collect(Collectors.toList());
+    }
+
     @Test(groups="Integration", invocationCount=50)
     public void testHttpFeedCleansUpAfterHaDisabledAndRunsAtFailoverManyTimes() throws Exception
{
         testHttpFeedCleansUpAfterHaDisabledAndRunsAtFailover();


Mime
View raw message