brooklyn-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aleds...@apache.org
Subject [3/4] incubator-brooklyn git commit: Replace many versions of RecordingSensorEventListener
Date Thu, 06 Aug 2015 16:33:49 GMT
Replace many versions of RecordingSensorEventListener


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

Branch: refs/heads/master
Commit: 8439d9fde7077d30e794ede40652e89e15ddbda0
Parents: 379d6a1
Author: Sam Corbett <sam.corbett@cloudsoftcorp.com>
Authored: Wed Aug 5 16:04:21 2015 +0100
Committer: Sam Corbett <sam.corbett@cloudsoftcorp.com>
Committed: Thu Aug 6 16:01:57 2015 +0100

----------------------------------------------------------------------
 .../java/brooklyn/enricher/EnrichersTest.java   | 30 +++++++--------
 .../brooklyn/entity/basic/AttributeMapTest.java | 19 ++--------
 .../entity/basic/EntityLocationsTest.java       | 25 ++++++------
 .../entity/basic/EntitySubscriptionTest.java    | 40 ++++++++------------
 .../brooklyn/entity/basic/EntityTypeTest.java   | 35 +++++++++--------
 .../entity/group/DynamicClusterTest.java        |  8 ++--
 .../policy/basic/PolicySubscriptionTest.java    | 23 +++--------
 ...lledDynamicWebAppClusterIntegrationTest.java | 13 +++----
 .../ControlledDynamicWebAppClusterTest.java     | 38 +------------------
 9 files changed, 85 insertions(+), 146 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/8439d9fd/core/src/test/java/brooklyn/enricher/EnrichersTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/brooklyn/enricher/EnrichersTest.java b/core/src/test/java/brooklyn/enricher/EnrichersTest.java
index 20ffab0..b20f722 100644
--- a/core/src/test/java/brooklyn/enricher/EnrichersTest.java
+++ b/core/src/test/java/brooklyn/enricher/EnrichersTest.java
@@ -30,7 +30,7 @@ import brooklyn.entity.BrooklynAppUnitTestSupport;
 import brooklyn.entity.basic.BasicGroup;
 import brooklyn.entity.basic.Entities;
 import brooklyn.entity.basic.EntityAdjuncts;
-import brooklyn.entity.basic.EntitySubscriptionTest.RecordingSensorEventListener;
+import org.apache.brooklyn.entity.basic.RecordingSensorEventListener;
 import brooklyn.entity.proxying.EntitySpec;
 import brooklyn.event.AttributeSensor;
 import brooklyn.event.SensorEvent;
@@ -190,7 +190,7 @@ public class EnrichersTest extends BrooklynAppUnitTestSupport {
 
     @Test(groups="Integration") // because takes a second
     public void testTransformingRespectsUnchangedButWillRepublish() {
-        RecordingSensorEventListener record = new RecordingSensorEventListener();
+        RecordingSensorEventListener<String> record = new RecordingSensorEventListener<>();
         app.getManagementContext().getSubscriptionManager().subscribe(entity, STR2, record);
         
         entity.addEnricher(Enrichers.builder()
@@ -201,29 +201,29 @@ public class EnrichersTest extends BrooklynAppUnitTestSupport {
                             return ("ignoredval".equals(input)) ? Entities.UNCHANGED : input;
                         }})
                 .build());
-        Asserts.assertThat(record.events, CollectionFunctionals.sizeEquals(0));
-        
+        Asserts.assertThat(record.getEvents(), CollectionFunctionals.sizeEquals(0));
+
         entity.setAttribute(STR1, "myval");
-        Asserts.eventually(Suppliers.ofInstance(record.events), CollectionFunctionals.sizeEquals(1));
+        Asserts.eventually(Suppliers.ofInstance(record), CollectionFunctionals.sizeEquals(1));
         EntityTestUtils.assertAttributeEquals(entity, STR2, "myval");
-        
+
         entity.setAttribute(STR1, "ignoredval");
         EntityTestUtils.assertAttributeEqualsContinually(entity, STR2, "myval");
-        
+
         entity.setAttribute(STR1, "myval2");
-        Asserts.eventually(Suppliers.ofInstance(record.events), CollectionFunctionals.sizeEquals(2));
+        Asserts.eventually(Suppliers.ofInstance(record), CollectionFunctionals.sizeEquals(2));
         EntityTestUtils.assertAttributeEquals(entity, STR2, "myval2");
-        
+
         entity.setAttribute(STR1, "myval2");
         entity.setAttribute(STR1, "myval2");
         entity.setAttribute(STR1, "myval3");
-        Asserts.eventually(Suppliers.ofInstance(record.events), CollectionFunctionals.sizeEquals(5));
+        Asserts.eventually(Suppliers.ofInstance(record), CollectionFunctionals.sizeEquals(5));
     }
 
     public void testTransformingSuppressDuplicates() {
-        RecordingSensorEventListener record = new RecordingSensorEventListener();
+        RecordingSensorEventListener<String> record = new RecordingSensorEventListener<>();
         app.getManagementContext().getSubscriptionManager().subscribe(entity, STR2, record);
-        
+
         entity.addEnricher(Enrichers.builder()
                 .transforming(STR1)
                 .publishing(STR2)
@@ -232,14 +232,14 @@ public class EnrichersTest extends BrooklynAppUnitTestSupport {
                 .build());
 
         entity.setAttribute(STR1, "myval");
-        Asserts.eventually(Suppliers.ofInstance(record.events), CollectionFunctionals.sizeEquals(1));
+        Asserts.eventually(Suppliers.ofInstance(record), CollectionFunctionals.sizeEquals(1));
         EntityTestUtils.assertAttributeEquals(entity, STR2, "myval");
-        
+
         entity.setAttribute(STR1, "myval2");
         entity.setAttribute(STR1, "myval2");
         entity.setAttribute(STR1, "myval3");
         EntityTestUtils.assertAttributeEqualsContinually(entity, STR2, "myval3");
-        Asserts.assertThat(record.events, CollectionFunctionals.sizeEquals(3));
+        Asserts.assertThat(record.getEvents(), CollectionFunctionals.sizeEquals(3));
     }
 
     @Test

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/8439d9fd/core/src/test/java/brooklyn/entity/basic/AttributeMapTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/brooklyn/entity/basic/AttributeMapTest.java b/core/src/test/java/brooklyn/entity/basic/AttributeMapTest.java
index bdbd25e..6e95706 100644
--- a/core/src/test/java/brooklyn/entity/basic/AttributeMapTest.java
+++ b/core/src/test/java/brooklyn/entity/basic/AttributeMapTest.java
@@ -29,14 +29,13 @@ import java.util.concurrent.ExecutorService;
 import java.util.concurrent.Executors;
 import java.util.concurrent.Future;
 
+import org.apache.brooklyn.entity.basic.RecordingSensorEventListener;
 import org.testng.annotations.AfterMethod;
 import org.testng.annotations.BeforeMethod;
 import org.testng.annotations.Test;
 
 import brooklyn.entity.Application;
 import brooklyn.event.AttributeSensor;
-import brooklyn.event.SensorEvent;
-import brooklyn.event.SensorEventListener;
 import brooklyn.event.basic.AttributeMap;
 import brooklyn.event.basic.Sensors;
 import brooklyn.test.Asserts;
@@ -48,6 +47,7 @@ import brooklyn.util.guava.Maybe;
 import com.google.common.base.Function;
 import com.google.common.base.Functions;
 import com.google.common.collect.ImmutableList;
+import com.google.common.collect.Iterables;
 import com.google.common.collect.Lists;
 
 public class AttributeMapTest {
@@ -189,14 +189,14 @@ public class AttributeMapTest {
         AttributeSensor<Integer> sensor = Sensors.newIntegerSensor("a", "");
         AttributeSensor<Integer> childSensor = Sensors.newIntegerSensor("a.b", "");
         
-        final RecordingSensorEventListener listener = new RecordingSensorEventListener();
+        final RecordingSensorEventListener<Object> listener = new RecordingSensorEventListener<>();
         entity.subscribe(entity, sensor, listener);
         
         map.modify(childSensor, Functions.constant(Maybe.<Integer>absent()));
         
         Asserts.succeedsContinually(new Runnable() {
             @Override public void run() {
-                assertTrue(listener.getEvents().isEmpty(), "events="+listener.getEvents());
+                assertTrue(Iterables.isEmpty(listener.getEvents()), "events="+listener.getEvents());
             }});
     }
     
@@ -223,16 +223,5 @@ public class AttributeMapTest {
             }
         };
     }
-    
-    public static class RecordingSensorEventListener implements SensorEventListener<Object>
{
-        private List<SensorEvent<Object>> events = Collections.synchronizedList(Lists.<SensorEvent<Object>>newArrayList());
 
-        @Override public void onEvent(SensorEvent<Object> event) {
-            events.add(event);
-        }
-        
-        public List<SensorEvent<Object>> getEvents() {
-            return ImmutableList.copyOf(events);
-        }
-    }
 }

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/8439d9fd/core/src/test/java/brooklyn/entity/basic/EntityLocationsTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/brooklyn/entity/basic/EntityLocationsTest.java b/core/src/test/java/brooklyn/entity/basic/EntityLocationsTest.java
index 5207256..074ff0b 100644
--- a/core/src/test/java/brooklyn/entity/basic/EntityLocationsTest.java
+++ b/core/src/test/java/brooklyn/entity/basic/EntityLocationsTest.java
@@ -23,15 +23,17 @@ import static org.testng.Assert.assertEquals;
 import java.util.Arrays;
 import java.util.List;
 
+import org.apache.brooklyn.entity.basic.RecordingSensorEventListener;
 import org.testng.Assert;
 import org.testng.annotations.Test;
 
 import brooklyn.entity.BrooklynAppUnitTestSupport;
-import brooklyn.entity.basic.EntitySubscriptionTest.RecordingSensorEventListener;
+import brooklyn.event.SensorEvent;
 import brooklyn.location.Location;
 import brooklyn.test.Asserts;
 
 import com.google.common.collect.ImmutableList;
+import com.google.common.collect.Iterables;
 
 public class EntityLocationsTest extends BrooklynAppUnitTestSupport {
 
@@ -48,8 +50,8 @@ public class EntityLocationsTest extends BrooklynAppUnitTestSupport {
         final Location l = app.newSimulatedLocation();
         final Location l2 = app.newSimulatedLocation();
         
-        final RecordingSensorEventListener addedEvents = new RecordingSensorEventListener();
-        final RecordingSensorEventListener removedEvents = new RecordingSensorEventListener();
+        final RecordingSensorEventListener<Object> addedEvents = new RecordingSensorEventListener<>();
+        final RecordingSensorEventListener<Object> removedEvents = new RecordingSensorEventListener<>();
         app.subscribe(app, AbstractEntity.LOCATION_ADDED, addedEvents);
         app.subscribe(app, AbstractEntity.LOCATION_REMOVED, removedEvents);
 
@@ -82,8 +84,8 @@ public class EntityLocationsTest extends BrooklynAppUnitTestSupport {
     public void testNotNotifiedDuplicateAddedLocations() throws Exception {
         final Location l = app.newSimulatedLocation();
         
-        final RecordingSensorEventListener addedEvents = new RecordingSensorEventListener();
-        final RecordingSensorEventListener removedEvents = new RecordingSensorEventListener();
+        final RecordingSensorEventListener<Object> addedEvents = new RecordingSensorEventListener<>();
+        final RecordingSensorEventListener<Object> removedEvents = new RecordingSensorEventListener<>();
         app.subscribe(app, AbstractEntity.LOCATION_ADDED, addedEvents);
         app.subscribe(app, AbstractEntity.LOCATION_REMOVED, removedEvents);
 
@@ -100,25 +102,26 @@ public class EntityLocationsTest extends BrooklynAppUnitTestSupport
{
         assertEventValuesEquals(removedEvents, ImmutableList.of());
     }
     
-    private void assertEventValuesEqualsEventually(final RecordingSensorEventListener listener,
final List<?> expectedVals) {
+    private void assertEventValuesEqualsEventually(final RecordingSensorEventListener<Object>
listener, final List<?> expectedVals) {
         Asserts.succeedsEventually(new Runnable() {
             @Override public void run() {
                 assertEventValuesEquals(listener, expectedVals);
             }});
     }
     
-    private void assertEventValuesEqualsContinually(final RecordingSensorEventListener listener,
final List<?> expectedVals) {
+    private void assertEventValuesEqualsContinually(final RecordingSensorEventListener<Object>
listener, final List<?> expectedVals) {
         Asserts.succeedsContinually(new Runnable() {
             @Override public void run() {
                 assertEventValuesEquals(listener, expectedVals);
             }});
     }
-    
-    private void assertEventValuesEquals(final RecordingSensorEventListener listener, final
List<?> expectedVals) {
-        assertEquals(listener.events.size(), expectedVals.size(), "events="+listener.events);
+
+    private void assertEventValuesEquals(final RecordingSensorEventListener<Object>
listener, final List<?> expectedVals) {
+        Iterable<SensorEvent<Object>> events = listener.getEvents();
+        assertEquals(Iterables.size(events), expectedVals.size(), "events=" + events);
         for (int i = 0; i < expectedVals.size(); i++) {
             Object expectedVal = expectedVals.get(i);
-            assertEquals(listener.events.get(i).getValue(), expectedVal, "events="+listener.events);
+            assertEquals(Iterables.get(events, i).getValue(), expectedVal, "events=" + events);
         }
     }
 }

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/8439d9fd/core/src/test/java/brooklyn/entity/basic/EntitySubscriptionTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/brooklyn/entity/basic/EntitySubscriptionTest.java b/core/src/test/java/brooklyn/entity/basic/EntitySubscriptionTest.java
index fd648d4..42d705c 100644
--- a/core/src/test/java/brooklyn/entity/basic/EntitySubscriptionTest.java
+++ b/core/src/test/java/brooklyn/entity/basic/EntitySubscriptionTest.java
@@ -20,16 +20,12 @@ package brooklyn.entity.basic;
 
 import static org.testng.Assert.assertEquals;
 
-import java.util.List;
-import java.util.concurrent.CopyOnWriteArrayList;
-
+import org.apache.brooklyn.entity.basic.RecordingSensorEventListener;
 import org.testng.annotations.AfterMethod;
 import org.testng.annotations.BeforeMethod;
 import org.testng.annotations.Test;
 
 import brooklyn.entity.proxying.EntitySpec;
-import brooklyn.event.SensorEvent;
-import brooklyn.event.SensorEventListener;
 import brooklyn.event.basic.BasicSensorEvent;
 import brooklyn.location.basic.SimulatedLocation;
 import brooklyn.management.SubscriptionHandle;
@@ -38,6 +34,7 @@ import brooklyn.test.entity.TestApplication;
 import brooklyn.test.entity.TestEntity;
 
 import com.google.common.collect.ImmutableList;
+import com.google.common.collect.Iterables;
 
 public class EntitySubscriptionTest {
 
@@ -51,7 +48,7 @@ public class EntitySubscriptionTest {
     private TestEntity observedChildEntity;
     private TestEntity observedMemberEntity;
     private TestEntity otherEntity;
-    private RecordingSensorEventListener listener;
+    private RecordingSensorEventListener<Object> listener;
     
     @BeforeMethod(alwaysRun=true)
     public void setUp() {
@@ -67,7 +64,7 @@ public class EntitySubscriptionTest {
         
         otherEntity = app.createAndManageChild(EntitySpec.create(TestEntity.class));
         
-        listener = new RecordingSensorEventListener();
+        listener = new RecordingSensorEventListener<>();
         
         app.start(ImmutableList.of(loc));
     }
@@ -90,7 +87,7 @@ public class EntitySubscriptionTest {
         
         Asserts.succeedsEventually(new Runnable() {
             @Override public void run() {
-                assertEquals(listener.events, ImmutableList.of(
+                assertEquals(listener.getEvents(), ImmutableList.of(
                         new BasicSensorEvent<Integer>(TestEntity.SEQUENCE, observedEntity,
123),
                         new BasicSensorEvent<String>(TestEntity.NAME, observedEntity,
"myname"),
                         new BasicSensorEvent<Integer>(TestEntity.MY_NOTIF, observedEntity,
456)));
@@ -106,7 +103,7 @@ public class EntitySubscriptionTest {
         
         Asserts.succeedsEventually(new Runnable() {
             @Override public void run() {
-                assertEquals(listener.events, ImmutableList.of(
+                assertEquals(listener.getEvents(), ImmutableList.of(
                         new BasicSensorEvent<Integer>(TestEntity.SEQUENCE, observedEntity,
123),
                         new BasicSensorEvent<Integer>(TestEntity.SEQUENCE, otherEntity,
456)));
             }});
@@ -121,7 +118,7 @@ public class EntitySubscriptionTest {
         
         Asserts.succeedsEventually(new Runnable() {
             @Override public void run() {
-                assertEquals(listener.events, ImmutableList.of(
+                assertEquals(listener.getEvents(), ImmutableList.of(
                         new BasicSensorEvent<Integer>(TestEntity.SEQUENCE, observedChildEntity,
123)));
             }});
     }
@@ -135,7 +132,7 @@ public class EntitySubscriptionTest {
         
         Asserts.succeedsEventually(new Runnable() {
             @Override public void run() {
-                assertEquals(listener.events, ImmutableList.of(
+                assertEquals(listener.getEvents(), ImmutableList.of(
                         new BasicSensorEvent<Integer>(TestEntity.SEQUENCE, observedChildEntity2,
123)));
             }});
     }
@@ -149,7 +146,7 @@ public class EntitySubscriptionTest {
         
         Asserts.succeedsEventually(new Runnable() {
             @Override public void run() {
-                assertEquals(listener.events, ImmutableList.of(
+                assertEquals(listener.getEvents(), ImmutableList.of(
                         new BasicSensorEvent<Integer>(TestEntity.SEQUENCE, observedMemberEntity,
123)));
             }});
     }
@@ -164,7 +161,7 @@ public class EntitySubscriptionTest {
         
         Asserts.succeedsEventually(new Runnable() {
             @Override public void run() {
-                assertEquals(listener.events, ImmutableList.of(
+                assertEquals(listener.getEvents(), ImmutableList.of(
                         new BasicSensorEvent<Integer>(TestEntity.SEQUENCE, observedMemberEntity2,
123)));
             }});
     }
@@ -179,7 +176,7 @@ public class EntitySubscriptionTest {
         
         Asserts.succeedsEventually(new Runnable() {
             @Override public void run() {
-                assertEquals(listener.events, ImmutableList.of());
+                assertEquals(listener.getEvents(), ImmutableList.of());
             }});
     }
     
@@ -198,7 +195,7 @@ public class EntitySubscriptionTest {
         
         Asserts.succeedsEventually(new Runnable() {
             @Override public void run() {
-                assertEquals(listener.events, ImmutableList.of(
+                assertEquals(listener.getEvents(), ImmutableList.of(
                         new BasicSensorEvent<Integer>(TestEntity.SEQUENCE, otherEntity,
456)));
             }});
     }
@@ -217,7 +214,7 @@ public class EntitySubscriptionTest {
         
         Asserts.succeedsEventually(new Runnable() {
             @Override public void run() {
-                assertEquals(listener.events, ImmutableList.of(
+                assertEquals(listener.getEvents(), ImmutableList.of(
                         new BasicSensorEvent<Integer>(TestEntity.SEQUENCE, observedEntity,
123),
                         new BasicSensorEvent<Integer>(TestEntity.SEQUENCE, otherEntity,
456)));
             }});
@@ -234,18 +231,11 @@ public class EntitySubscriptionTest {
         
         Asserts.succeedsEventually(new Runnable() {
             @Override public void run() {
-                assertEquals(listener.events.size(), NUM_EVENTS);
+                assertEquals(Iterables.size(listener.getEvents()), NUM_EVENTS);
                 for (int i = 0; i < NUM_EVENTS; i++) {
-                    assertEquals(listener.events.get(i).getValue(), i);
+                    assertEquals(Iterables.get(listener.getEvents(), i).getValue(), i);
                 }
             }});
     }
 
-    public static class RecordingSensorEventListener implements SensorEventListener<Object>
{
-        public final List<SensorEvent<?>> events = new CopyOnWriteArrayList<SensorEvent<?>>();
-        
-        @Override public void onEvent(SensorEvent<Object> event) {
-            events.add(event);
-        }
-    }
 }

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/8439d9fd/core/src/test/java/brooklyn/entity/basic/EntityTypeTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/brooklyn/entity/basic/EntityTypeTest.java b/core/src/test/java/brooklyn/entity/basic/EntityTypeTest.java
index 67113fe..7035ccd 100644
--- a/core/src/test/java/brooklyn/entity/basic/EntityTypeTest.java
+++ b/core/src/test/java/brooklyn/entity/basic/EntityTypeTest.java
@@ -40,6 +40,7 @@ import java.util.Set;
 
 import javax.annotation.Nullable;
 
+import org.apache.brooklyn.entity.basic.RecordingSensorEventListener;
 import org.testng.annotations.BeforeMethod;
 import org.testng.annotations.Test;
 
@@ -54,12 +55,9 @@ import brooklyn.event.basic.Sensors;
 import brooklyn.test.Asserts;
 import brooklyn.test.entity.TestEntity;
 import brooklyn.test.entity.TestEntityImpl;
-import brooklyn.util.collections.CollectionFunctionals;
 import brooklyn.util.collections.MutableSet;
 
 import com.google.common.base.Predicate;
-import com.google.common.base.Predicates;
-import com.google.common.base.Suppliers;
 import com.google.common.collect.ImmutableList;
 import com.google.common.collect.ImmutableSet;
 import com.google.common.collect.Iterables;
@@ -67,8 +65,8 @@ import com.google.common.collect.Iterables;
 public class EntityTypeTest extends BrooklynAppUnitTestSupport {
     private static final AttributeSensor<String> TEST_SENSOR = Sensors.newStringSensor("test.sensor");
     private EntityInternal entity;
-    private EntitySubscriptionTest.RecordingSensorEventListener listener;
-    
+    private RecordingSensorEventListener<Sensor> listener;
+
     public final static Set<Sensor<?>> DEFAULT_SENSORS = ImmutableSet.<Sensor<?>>of(
             SENSOR_ADDED, SENSOR_REMOVED,
             EFFECTOR_ADDED, EFFECTOR_REMOVED, EFFECTOR_CHANGED,
@@ -83,7 +81,7 @@ public class EntityTypeTest extends BrooklynAppUnitTestSupport {
     public void setUp() throws Exception{
         super.setUp();
         entity = (EntityInternal) app.createAndManageChild(EntitySpec.create(Entity.class,
EmptyEntityForTesting.class));
-        listener = new EntitySubscriptionTest.RecordingSensorEventListener();
+        listener = new RecordingSensorEventListener<>();
         app.getSubscriptionContext().subscribe(entity, SENSOR_ADDED, listener);
         app.getSubscriptionContext().subscribe(entity, SENSOR_REMOVED, listener);
     }
@@ -172,11 +170,14 @@ public class EntityTypeTest extends BrooklynAppUnitTestSupport {
         assertEquals(entity.getEntityType().getSensors(), DEFAULT_SENSORS);
     }
 
-    @SuppressWarnings("unchecked")
-    protected <T> void assertEventuallyListenerEventsEqual(List<T> sensorEvents)
{
-        Asserts.eventually(
-            Suppliers.ofInstance((List<T>)listener.events), 
-            Predicates.equalTo(sensorEvents));
+    protected <T> void assertEventuallyListenerEventsEqual(final List<T> sensorEvents)
{
+        final RecordingSensorEventListener listener = this.listener;
+        Asserts.succeedsEventually(new Runnable() {
+            @Override
+            public void run() {
+                assertEquals(listener.getEvents(), sensorEvents);
+            }
+        });
     }
     
     @Test
@@ -224,10 +225,14 @@ public class EntityTypeTest extends BrooklynAppUnitTestSupport {
         entity.getMutableEntityType().removeSensor(POLICY_ADDED.getName());
         assertEquals(entity.getEntityType().getSensors(), 
                 MutableSet.builder().addAll(DEFAULT_SENSORS).remove(SENSOR_ADDED).remove(POLICY_ADDED).build().asUnmodifiable());
-        
-        Asserts.eventually(
-                CollectionFunctionals.sizeSupplier(listener.events), 
-                Predicates.equalTo(2));
+
+        final RecordingSensorEventListener<?> listener = this.listener;
+        Asserts.succeedsEventually(new Runnable() {
+            @Override
+            public void run() {
+                assertEquals(Iterables.size(listener.getEvents()), 2);
+            }
+        });
         assertEventuallyListenerEventsEqual(ImmutableList.of(
             BasicSensorEvent.ofUnchecked(SENSOR_REMOVED, entity, SENSOR_ADDED),
             BasicSensorEvent.ofUnchecked(SENSOR_REMOVED, entity, POLICY_ADDED)));

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/8439d9fd/core/src/test/java/brooklyn/entity/group/DynamicClusterTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/brooklyn/entity/group/DynamicClusterTest.java b/core/src/test/java/brooklyn/entity/group/DynamicClusterTest.java
index 1d144a0..b8a1839 100644
--- a/core/src/test/java/brooklyn/entity/group/DynamicClusterTest.java
+++ b/core/src/test/java/brooklyn/entity/group/DynamicClusterTest.java
@@ -50,8 +50,8 @@ import brooklyn.entity.basic.BasicEntity;
 import brooklyn.entity.basic.BrooklynTaskTags;
 import brooklyn.entity.basic.Entities;
 import brooklyn.entity.basic.EntityFactory;
-import brooklyn.entity.basic.EntitySubscriptionTest.RecordingSensorEventListener;
 import brooklyn.entity.basic.Lifecycle;
+import org.apache.brooklyn.entity.basic.RecordingSensorEventListener;
 import brooklyn.entity.basic.ServiceStateLogic;
 import brooklyn.entity.proxying.EntitySpec;
 import brooklyn.entity.trait.Changeable;
@@ -212,14 +212,14 @@ public class DynamicClusterTest extends BrooklynAppUnitTestSupport {
             .configure(DynamicCluster.MEMBER_SPEC, EntitySpec.create(TestEntity.class))
             .configure(DynamicCluster.INITIAL_SIZE, 1));
         
-        RecordingSensorEventListener r = new RecordingSensorEventListener();
+        RecordingSensorEventListener<Lifecycle> r = new RecordingSensorEventListener<>();
         app.subscribe(cluster, Attributes.SERVICE_STATE_ACTUAL, r);
 
         cluster.start(ImmutableList.of(loc));
         EntityTestUtils.assertAttributeEqualsEventually(cluster, Attributes.SERVICE_STATE_ACTUAL,
Lifecycle.RUNNING);
-        for (SensorEvent<?> evt: r.events) {
+        for (SensorEvent<Lifecycle> evt: r.getEvents()) {
             if (evt.getValue()==Lifecycle.ON_FIRE)
-                Assert.fail("Should not have published "+Lifecycle.ON_FIRE+" during normal
start up: "+r.events);
+                Assert.fail("Should not have published " + Lifecycle.ON_FIRE + " during normal
start up: " + r.getEvents());
         }
     }
 

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/8439d9fd/core/src/test/java/brooklyn/policy/basic/PolicySubscriptionTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/brooklyn/policy/basic/PolicySubscriptionTest.java b/core/src/test/java/brooklyn/policy/basic/PolicySubscriptionTest.java
index 41a0736..ed2bc47 100644
--- a/core/src/test/java/brooklyn/policy/basic/PolicySubscriptionTest.java
+++ b/core/src/test/java/brooklyn/policy/basic/PolicySubscriptionTest.java
@@ -20,16 +20,12 @@ package brooklyn.policy.basic;
 
 import static org.testng.Assert.assertEquals;
 
-import java.util.List;
-import java.util.concurrent.CopyOnWriteArrayList;
-
 import org.testng.annotations.BeforeMethod;
 import org.testng.annotations.Test;
 
 import brooklyn.entity.BrooklynAppUnitTestSupport;
+import org.apache.brooklyn.entity.basic.RecordingSensorEventListener;
 import brooklyn.entity.proxying.EntitySpec;
-import brooklyn.event.SensorEvent;
-import brooklyn.event.SensorEventListener;
 import brooklyn.event.basic.BasicSensorEvent;
 import brooklyn.location.basic.SimulatedLocation;
 import brooklyn.management.SubscriptionHandle;
@@ -48,7 +44,7 @@ public class PolicySubscriptionTest extends BrooklynAppUnitTestSupport {
     private TestEntity entity;
     private TestEntity otherEntity;
     private AbstractPolicy policy;
-    private RecordingSensorEventListener listener;
+    private RecordingSensorEventListener<Object> listener;
     
     @BeforeMethod(alwaysRun=true)
     @Override
@@ -57,7 +53,7 @@ public class PolicySubscriptionTest extends BrooklynAppUnitTestSupport {
         loc = app.newSimulatedLocation();
         entity = app.createAndManageChild(EntitySpec.create(TestEntity.class));
         otherEntity = app.createAndManageChild(EntitySpec.create(TestEntity.class));
-        listener = new RecordingSensorEventListener();
+        listener = new RecordingSensorEventListener<>();
         policy = new AbstractPolicy() {};
         entity.addPolicy(policy);
         app.start(ImmutableList.of(loc));
@@ -76,7 +72,7 @@ public class PolicySubscriptionTest extends BrooklynAppUnitTestSupport {
         
         Asserts.succeedsEventually(new Runnable() {
             @Override public void run() {
-                assertEquals(listener.events, ImmutableList.of(
+                assertEquals(listener.getEvents(), ImmutableList.of(
                         new BasicSensorEvent<Integer>(TestEntity.SEQUENCE, entity,
123),
                         new BasicSensorEvent<String>(TestEntity.NAME, entity, "myname"),
                         new BasicSensorEvent<Integer>(TestEntity.MY_NOTIF, entity,
789)));
@@ -99,7 +95,7 @@ public class PolicySubscriptionTest extends BrooklynAppUnitTestSupport {
         Thread.sleep(SHORT_WAIT_MS);
         Asserts.succeedsEventually(new Runnable() {
             @Override public void run() {
-                assertEquals(listener.events, ImmutableList.of(
+                assertEquals(listener.getEvents(), ImmutableList.of(
                         new BasicSensorEvent<Integer>(TestEntity.SEQUENCE, otherEntity,
789)));
             }});
     }
@@ -118,17 +114,10 @@ public class PolicySubscriptionTest extends BrooklynAppUnitTestSupport
{
         
         Asserts.succeedsEventually(new Runnable() {
             @Override public void run() {
-                assertEquals(listener.events, ImmutableList.of(
+                assertEquals(listener.getEvents(), ImmutableList.of(
                         new BasicSensorEvent<Integer>(TestEntity.SEQUENCE, entity,
123),
                         new BasicSensorEvent<Integer>(TestEntity.SEQUENCE, otherEntity,
456)));
             }});
     }
     
-    private static class RecordingSensorEventListener implements SensorEventListener<Object>
{
-        final List<SensorEvent<?>> events = new CopyOnWriteArrayList<SensorEvent<?>>();
-        
-        @Override public void onEvent(SensorEvent<Object> event) {
-            events.add(event);
-        }
-    }
 }

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/8439d9fd/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 44212d8..7f9a18f 100644
--- a/software/webapp/src/test/java/brooklyn/entity/webapp/ControlledDynamicWebAppClusterIntegrationTest.java
+++ b/software/webapp/src/test/java/brooklyn/entity/webapp/ControlledDynamicWebAppClusterIntegrationTest.java
@@ -25,6 +25,7 @@ import java.util.List;
 import java.util.concurrent.Callable;
 
 import org.apache.brooklyn.test.TestResourceUnavailableException;
+import org.apache.brooklyn.entity.basic.RecordingSensorEventListener;
 
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -39,7 +40,6 @@ import brooklyn.entity.proxy.AbstractController;
 import brooklyn.entity.proxy.LoadBalancer;
 import brooklyn.entity.proxy.nginx.NginxController;
 import brooklyn.entity.proxying.EntitySpec;
-import brooklyn.entity.webapp.ControlledDynamicWebAppClusterTest.RecordingSensorEventListener;
 import brooklyn.entity.webapp.tomcat.TomcatServer;
 import brooklyn.location.basic.LocalhostMachineProvisioningLocation;
 import brooklyn.test.Asserts;
@@ -49,7 +49,6 @@ import brooklyn.test.entity.TestJavaWebAppEntity;
 import brooklyn.util.collections.CollectionFunctionals;
 import brooklyn.util.collections.MutableMap;
 
-import com.google.common.base.Predicates;
 import com.google.common.base.Suppliers;
 import com.google.common.collect.ImmutableList;
 import com.google.common.collect.Iterables;
@@ -146,14 +145,14 @@ public class ControlledDynamicWebAppClusterIntegrationTest extends BrooklynAppLi
         app.subscribe(cluster, Attributes.SERVICE_STATE_ACTUAL, listener);
         app.start(locs);
         
-        Asserts.eventually(Suppliers.ofInstance(listener.getValues()), CollectionFunctionals.sizeEquals(2));
-        assertEquals(listener.getValues(), ImmutableList.of(Lifecycle.STARTING, Lifecycle.RUNNING),
"vals="+listener.getValues());
-        listener.getValues().clear();
+        Asserts.eventually(Suppliers.ofInstance(listener.getEventValues()), CollectionFunctionals.sizeEquals(2));
+        assertEquals(listener.getEventValues(), ImmutableList.of(Lifecycle.STARTING, Lifecycle.RUNNING),
"vals="+listener.getEventValues());
+        listener.clearEvents();
         
         app.stop();
         EntityTestUtils.assertAttributeEqualsEventually(cluster, Attributes.SERVICE_STATE_ACTUAL,
Lifecycle.STOPPED);
-        Asserts.eventually(Suppliers.ofInstance(listener.getValues()), CollectionFunctionals.sizeEquals(2));
-        assertEquals(listener.getValues(), ImmutableList.of(Lifecycle.STOPPING, Lifecycle.STOPPED),
"vals="+listener.getValues());
+        Asserts.eventually(Suppliers.ofInstance(listener), CollectionFunctionals.sizeEquals(2));
+        assertEquals(listener.getEventValues(), ImmutableList.of(Lifecycle.STOPPING, Lifecycle.STOPPED),
"vals="+listener.getEventValues());
     }
     
     @Test(groups="Integration")

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/8439d9fd/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 66bacc6..7a361f2 100644
--- a/software/webapp/src/test/java/brooklyn/entity/webapp/ControlledDynamicWebAppClusterTest.java
+++ b/software/webapp/src/test/java/brooklyn/entity/webapp/ControlledDynamicWebAppClusterTest.java
@@ -20,7 +20,6 @@ package brooklyn.entity.webapp;
 
 import static org.testng.Assert.assertEquals;
 
-import java.net.URL;
 import java.util.List;
 
 import org.apache.brooklyn.test.TestResourceUnavailableException;
@@ -38,8 +37,6 @@ import brooklyn.entity.proxy.LoadBalancer;
 import brooklyn.entity.proxy.TrackingAbstractController;
 import brooklyn.entity.proxying.EntitySpec;
 import brooklyn.entity.webapp.jboss.JBoss7Server;
-import brooklyn.event.SensorEvent;
-import brooklyn.event.SensorEventListener;
 import brooklyn.location.basic.LocalhostMachineProvisioningLocation;
 import brooklyn.test.Asserts;
 import brooklyn.test.EntityTestUtils;
@@ -47,7 +44,6 @@ import brooklyn.test.entity.TestJavaWebAppEntity;
 
 import com.google.common.collect.ImmutableList;
 import com.google.common.collect.Iterables;
-import com.google.common.collect.Lists;
 
 public class ControlledDynamicWebAppClusterTest extends BrooklynAppUnitTestSupport {
     private static final Logger log = LoggerFactory.getLogger(ControlledDynamicWebAppClusterTest.class);
@@ -138,39 +134,7 @@ public class ControlledDynamicWebAppClusterTest extends BrooklynAppUnitTestSuppo
 
         assertEquals(cluster.getCluster().getDisplayName(), "mydisplayname");
     }
-    
-    public static class RecordingSensorEventListener<T> implements SensorEventListener<T>
{
-        private final List<SensorEvent<T>> events = Lists.newCopyOnWriteArrayList();
-        private final List<T> values = Lists.newCopyOnWriteArrayList();
-        private boolean skipDuplicateValues;
-
-        public RecordingSensorEventListener() {
-            this(false);
-        }
-        
-        public RecordingSensorEventListener(boolean skipDuplicateValues) {
-            this.skipDuplicateValues = skipDuplicateValues;
-        }
-        
-        @Override
-        public void onEvent(SensorEvent<T> event) {
-            events.add(event);
-            if (skipDuplicateValues && !values.isEmpty() && values.get(values.size()-1).equals(event.getValue()))
{
-                // skip
-            } else {
-                values.add(event.getValue());
-            }
-        }
-        
-        public List<SensorEvent<T>> getEvents() {
-            return events;
-        }
-        
-        public List<T> getValues() {
-            return values;
-        }
-    }
-    
+
     @Test
     public void testMembersReflectChildClusterMembers() {
         final ControlledDynamicWebAppCluster cluster = app.createAndManageChild(EntitySpec.create(ControlledDynamicWebAppCluster.class)


Mime
View raw message