brooklyn-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rich...@apache.org
Subject [4/7] incubator-brooklyn git commit: fix failing test where location sensor is added; also fix caps of that new sensor, and remove warnings in the tests
Date Fri, 12 Dec 2014 12:06:19 GMT
fix failing test where location sensor is added; also fix caps of that new sensor, and remove
warnings in the tests


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

Branch: refs/heads/master
Commit: 6dfe0997260055335f34c6848eaad8dbe597324f
Parents: eacfe13
Author: Alex Heneveld <alex.heneveld@cloudsoftcorp.com>
Authored: Fri Dec 12 11:48:09 2014 +0000
Committer: Alex Heneveld <alex.heneveld@cloudsoftcorp.com>
Committed: Fri Dec 12 11:48:09 2014 +0000

----------------------------------------------------------------------
 .../brooklyn/entity/basic/AbstractEntity.java   |  4 +-
 .../brooklyn/event/basic/BasicSensorEvent.java  | 18 +++++++
 .../brooklyn/entity/basic/EntityTypeTest.java   | 54 ++++++++++----------
 3 files changed, 46 insertions(+), 30 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/6dfe0997/core/src/main/java/brooklyn/entity/basic/AbstractEntity.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/brooklyn/entity/basic/AbstractEntity.java b/core/src/main/java/brooklyn/entity/basic/AbstractEntity.java
index 9b0399b..6a64cb0 100644
--- a/core/src/main/java/brooklyn/entity/basic/AbstractEntity.java
+++ b/core/src/main/java/brooklyn/entity/basic/AbstractEntity.java
@@ -146,9 +146,9 @@ public abstract class AbstractEntity extends AbstractBrooklynObject implements
E
     static { BrooklynLanguageExtensions.init(); }
     
     public static final BasicNotificationSensor<Location> LOCATION_ADDED = new BasicNotificationSensor<Location>(
-            Location.class, "entity.Location.added", "Location dynamically added to entity");
+            Location.class, "entity.location.added", "Location dynamically added to entity");
     public static final BasicNotificationSensor<Location> LOCATION_REMOVED = new BasicNotificationSensor<Location>(
-            Location.class, "entity.Location.removed", "Location dynamically removed from
entity");
+            Location.class, "entity.location.removed", "Location dynamically removed from
entity");
 
     public static final BasicNotificationSensor<Sensor> SENSOR_ADDED = new BasicNotificationSensor<Sensor>(Sensor.class,
             "entity.sensor.added", "Sensor dynamically added to entity");

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/6dfe0997/core/src/main/java/brooklyn/event/basic/BasicSensorEvent.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/brooklyn/event/basic/BasicSensorEvent.java b/core/src/main/java/brooklyn/event/basic/BasicSensorEvent.java
index 3f09ffe..da912a8 100644
--- a/core/src/main/java/brooklyn/event/basic/BasicSensorEvent.java
+++ b/core/src/main/java/brooklyn/event/basic/BasicSensorEvent.java
@@ -65,6 +65,24 @@ public class BasicSensorEvent<T> implements SensorEvent<T>
{
             this.timestamp = System.currentTimeMillis();
         }
     }
+    
+    public static <T> SensorEvent<T> of(Sensor<T> sensor, Entity source,
T value, long timestamp) {
+        return new BasicSensorEvent<T>(sensor, source, value, timestamp);
+    }
+
+    @SuppressWarnings("unchecked")
+    public static <T> SensorEvent<T> ofUnchecked(Sensor<T> sensor, Entity
source, Object value, long timestamp) {
+        return new BasicSensorEvent<T>(sensor, source, (T)value, timestamp);
+    }
+
+    public static <T> SensorEvent<T> of(Sensor<T> sensor, Entity source,
T value) {
+        return new BasicSensorEvent<T>(sensor, source, value);
+    }
+
+    @SuppressWarnings("unchecked")
+    public static <T> SensorEvent<T> ofUnchecked(Sensor<T> sensor, Entity
source, Object value) {
+        return new BasicSensorEvent<T>(sensor, source, (T)value);
+    }
 
     @Override
     public int hashCode() {

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/6dfe0997/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 6dd5693..67113fe 100644
--- a/core/src/test/java/brooklyn/entity/basic/EntityTypeTest.java
+++ b/core/src/test/java/brooklyn/entity/basic/EntityTypeTest.java
@@ -23,6 +23,8 @@ import static brooklyn.entity.basic.AbstractEntity.CHILD_REMOVED;
 import static brooklyn.entity.basic.AbstractEntity.EFFECTOR_ADDED;
 import static brooklyn.entity.basic.AbstractEntity.EFFECTOR_CHANGED;
 import static brooklyn.entity.basic.AbstractEntity.EFFECTOR_REMOVED;
+import static brooklyn.entity.basic.AbstractEntity.LOCATION_ADDED;
+import static brooklyn.entity.basic.AbstractEntity.LOCATION_REMOVED;
 import static brooklyn.entity.basic.AbstractEntity.POLICY_ADDED;
 import static brooklyn.entity.basic.AbstractEntity.POLICY_REMOVED;
 import static brooklyn.entity.basic.AbstractEntity.SENSOR_ADDED;
@@ -33,6 +35,7 @@ import static org.testng.Assert.assertNotNull;
 import static org.testng.Assert.assertNull;
 import static org.testng.Assert.assertTrue;
 
+import java.util.List;
 import java.util.Set;
 
 import javax.annotation.Nullable;
@@ -48,7 +51,7 @@ import brooklyn.event.AttributeSensor;
 import brooklyn.event.Sensor;
 import brooklyn.event.basic.BasicSensorEvent;
 import brooklyn.event.basic.Sensors;
-import brooklyn.test.TestUtils;
+import brooklyn.test.Asserts;
 import brooklyn.test.entity.TestEntity;
 import brooklyn.test.entity.TestEntityImpl;
 import brooklyn.util.collections.CollectionFunctionals;
@@ -70,7 +73,8 @@ public class EntityTypeTest extends BrooklynAppUnitTestSupport {
             SENSOR_ADDED, SENSOR_REMOVED,
             EFFECTOR_ADDED, EFFECTOR_REMOVED, EFFECTOR_CHANGED,
             POLICY_ADDED, POLICY_REMOVED,
-            CHILD_ADDED, CHILD_REMOVED); 
+            CHILD_ADDED, CHILD_REMOVED,
+            LOCATION_ADDED, LOCATION_REMOVED); 
 
     public static class EmptyEntityForTesting extends AbstractEntity {}
     
@@ -79,9 +83,6 @@ public class EntityTypeTest extends BrooklynAppUnitTestSupport {
     public void setUp() throws Exception{
         super.setUp();
         entity = (EntityInternal) app.createAndManageChild(EntitySpec.create(Entity.class,
EmptyEntityForTesting.class));
-//        entity = new AbstractEntity(app) {};
-//        Entities.startManagement(entity);
-        
         listener = new EntitySubscriptionTest.RecordingSensorEventListener();
         app.getSubscriptionContext().subscribe(entity, SENSOR_ADDED, listener);
         app.getSubscriptionContext().subscribe(entity, SENSOR_REMOVED, listener);
@@ -133,8 +134,8 @@ public class EntityTypeTest extends BrooklynAppUnitTestSupport {
     @Test
     public void testGetEffectorDeprecated() throws Exception {
         TestEntity entity2 = app.createAndManageChild(EntitySpec.create(TestEntity.class));
-        Effector<?> effector = entity2.getEntityType().getEffector("myEffector");
-        Effector<?> effector2 = entity2.getEntityType().getEffector("identityEffector",
Object.class);
+        Effector<?> effector = entity2.getEntityType().getEffectorByName("myEffector").get();
+        Effector<?> effector2 = entity2.getEntityType().getEffectorByName("identityEffector").get();
         assertEquals(effector.getName(), "myEffector");
         assertEquals(effector2.getName(), "identityEffector");
     }
@@ -143,6 +144,7 @@ public class EntityTypeTest extends BrooklynAppUnitTestSupport {
     public void testCustomSimpleName() throws Exception {
         class CustomTypeNamedEntity extends AbstractEntity {
             private final String typeName;
+            @SuppressWarnings("deprecation")
             CustomTypeNamedEntity(Entity parent, String typeName) {
                 super(parent);
                 this.typeName = typeName;
@@ -170,15 +172,20 @@ 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));
+    }
+    
     @Test
     public void testAddSensors() throws Exception{
         entity.getMutableEntityType().addSensor(TEST_SENSOR);
         assertEquals(entity.getEntityType().getSensors(), 
                 ImmutableSet.builder().addAll(DEFAULT_SENSORS).add(TEST_SENSOR).build());
         
-        TestUtils.assertEventually(
-                Suppliers.ofInstance(listener.events), 
-                Predicates.equalTo(ImmutableList.of(new BasicSensorEvent(SENSOR_ADDED, entity,
TEST_SENSOR))));
+        assertEventuallyListenerEventsEqual(ImmutableList.of(BasicSensorEvent.ofUnchecked(SENSOR_ADDED,
entity, TEST_SENSOR)));
     }
 
     @Test
@@ -187,9 +194,7 @@ public class EntityTypeTest extends BrooklynAppUnitTestSupport {
         assertEquals(entity.getEntityType().getSensors(), 
                 ImmutableSet.builder().addAll(DEFAULT_SENSORS).add(TEST_SENSOR).build());
         
-        TestUtils.assertEventually(
-                Suppliers.ofInstance(listener.events), 
-                Predicates.equalTo(ImmutableList.of(new BasicSensorEvent(SENSOR_ADDED, entity,
TEST_SENSOR))));
+        assertEventuallyListenerEventsEqual(ImmutableList.of(BasicSensorEvent.ofUnchecked(SENSOR_ADDED,
entity, TEST_SENSOR)));
     }
 
     @Test
@@ -199,11 +204,8 @@ public class EntityTypeTest extends BrooklynAppUnitTestSupport {
         assertFalse(entity.getEntityType().getSensors().contains(TEST_SENSOR), "sensors="+entity.getEntityType().getSensors());

         assertEquals(entity.getAttribute(TEST_SENSOR), null);
         
-        TestUtils.assertEventually(
-                Suppliers.ofInstance(listener.events), 
-                Predicates.equalTo(ImmutableList.of(
-                        new BasicSensorEvent(SENSOR_ADDED, entity, TEST_SENSOR), 
-                        new BasicSensorEvent(SENSOR_REMOVED, entity, TEST_SENSOR))));
+        assertEventuallyListenerEventsEqual(ImmutableList.of(BasicSensorEvent.ofUnchecked(SENSOR_ADDED,
entity, TEST_SENSOR),
+            BasicSensorEvent.ofUnchecked(SENSOR_REMOVED, entity, TEST_SENSOR)));
     }
 
     @Test
@@ -212,9 +214,8 @@ public class EntityTypeTest extends BrooklynAppUnitTestSupport {
         assertEquals(entity.getEntityType().getSensors(), 
                 MutableSet.builder().addAll(DEFAULT_SENSORS).remove(SENSOR_ADDED).build().asUnmodifiable());
         
-        TestUtils.assertEventually(
-                Suppliers.ofInstance(listener.events), 
-                Predicates.equalTo(ImmutableList.of(new BasicSensorEvent(SENSOR_REMOVED,
entity, SENSOR_ADDED))));
+        assertEventuallyListenerEventsEqual(ImmutableList.of(
+            BasicSensorEvent.ofUnchecked(SENSOR_REMOVED, entity, SENSOR_ADDED)));
     }
 
     @Test
@@ -224,15 +225,12 @@ public class EntityTypeTest extends BrooklynAppUnitTestSupport {
         assertEquals(entity.getEntityType().getSensors(), 
                 MutableSet.builder().addAll(DEFAULT_SENSORS).remove(SENSOR_ADDED).remove(POLICY_ADDED).build().asUnmodifiable());
         
-        TestUtils.assertEventually(
+        Asserts.eventually(
                 CollectionFunctionals.sizeSupplier(listener.events), 
                 Predicates.equalTo(2));
-        TestUtils.assertEventually(
-                Suppliers.ofInstance(listener.events), 
-                CollectionFunctionals.equalsSetOf(
-                        new BasicSensorEvent(SENSOR_REMOVED, entity, SENSOR_ADDED),
-                        new BasicSensorEvent(SENSOR_REMOVED, entity, POLICY_ADDED)
-                    ));
+        assertEventuallyListenerEventsEqual(ImmutableList.of(
+            BasicSensorEvent.ofUnchecked(SENSOR_REMOVED, entity, SENSOR_ADDED),
+            BasicSensorEvent.ofUnchecked(SENSOR_REMOVED, entity, POLICY_ADDED)));
     }
 
     @Test


Mime
View raw message