brooklyn-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From henev...@apache.org
Subject [7/8] incubator-brooklyn git commit: comments and more test for yaml enrichers
Date Fri, 17 Apr 2015 14:35:03 GMT
comments and more test for yaml enrichers


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

Branch: refs/heads/master
Commit: b887c19011027d874138e7f6391bb8c3f0c81e02
Parents: 7ba6df7
Author: Alex Heneveld <alex.heneveld@cloudsoftcorp.com>
Authored: Fri Apr 17 09:32:33 2015 -0500
Committer: Alex Heneveld <alex.heneveld@cloudsoftcorp.com>
Committed: Fri Apr 17 09:33:04 2015 -0500

----------------------------------------------------------------------
 .../java/brooklyn/enricher/basic/Joiner.java    |  1 -
 .../brooklyn/enricher/basic/Propagator.java     |  1 +
 .../brooklyn/enricher/basic/Transformer.java    |  3 ++-
 .../java/brooklyn/enricher/EnrichersTest.java   | 24 +++++++++++++++++++-
 4 files changed, 26 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/b887c190/core/src/main/java/brooklyn/enricher/basic/Joiner.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/brooklyn/enricher/basic/Joiner.java b/core/src/main/java/brooklyn/enricher/basic/Joiner.java
index 5189273..96509e1 100644
--- a/core/src/main/java/brooklyn/enricher/basic/Joiner.java
+++ b/core/src/main/java/brooklyn/enricher/basic/Joiner.java
@@ -57,7 +57,6 @@ public class Joiner<T> extends AbstractEnricher implements SensorEventListener<T
     @SetFromFlag("maximum")
     public static ConfigKey<Integer> MAXIMUM = ConfigKeys.newIntegerConfigKey("enricher.joiner.maximum",
"Maximum number of elements to join; default null means all elements always taken");
     
-//    protected Function<? super SensorEvent<T>, ? extends U> transformation;
     protected Entity producer;
     protected AttributeSensor<T> sourceSensor;
     protected Sensor<String> targetSensor;

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/b887c190/core/src/main/java/brooklyn/enricher/basic/Propagator.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/brooklyn/enricher/basic/Propagator.java b/core/src/main/java/brooklyn/enricher/basic/Propagator.java
index fd012a3..7d6e383 100644
--- a/core/src/main/java/brooklyn/enricher/basic/Propagator.java
+++ b/core/src/main/java/brooklyn/enricher/basic/Propagator.java
@@ -122,6 +122,7 @@ public class Propagator extends AbstractEnricher implements SensorEventListener<
                 // user specified nothing, so *set* the all_but to the default set
                 // if desired, we could allow this to be dynamically reconfigurable, remove
this field and always look up;
                 // slight performance hit (always looking up), and might need to recompute
subscriptions, so not supported currently
+                // TODO this default is @Beta behaviour! -- maybe better to throw?
                 propagatingAllBut = SENSORS_NOT_USUALLY_PROPAGATED;
             } else {
                 propagatingAllBut = getConfig(PROPAGATING_ALL_BUT);

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/b887c190/core/src/main/java/brooklyn/enricher/basic/Transformer.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/brooklyn/enricher/basic/Transformer.java b/core/src/main/java/brooklyn/enricher/basic/Transformer.java
index 0811fcc..224f201 100644
--- a/core/src/main/java/brooklyn/enricher/basic/Transformer.java
+++ b/core/src/main/java/brooklyn/enricher/basic/Transformer.java
@@ -57,7 +57,6 @@ public class Transformer<T,U> extends AbstractEnricher implements
SensorEventLis
 
     public static ConfigKey<Sensor<?>> TARGET_SENSOR = ConfigKeys.newConfigKey(new
TypeToken<Sensor<?>>() {}, "enricher.targetSensor");
     
-//    protected Function<? super SensorEvent<T>, ? extends U> transformation;
     protected Entity producer;
     protected Sensor<T> sourceSensor;
     protected Sensor<U> targetSensor;
@@ -153,6 +152,8 @@ public class Transformer<T,U> extends AbstractEnricher implements
SensorEventLis
     }
 
     protected Object compute(SensorEvent<T> event) {
+        // transformation is not going to change, but this design makes it easier to support
changing config in future. 
+        // if it's an efficiency hole we can switch to populate the transformation at start.
         U result = getTransformation().apply(event);
         if (LOG.isTraceEnabled())
             LOG.trace("Enricher "+this+" computed "+result+" from "+event);

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/b887c190/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 43d55c3..20ffab0 100644
--- a/core/src/test/java/brooklyn/enricher/EnrichersTest.java
+++ b/core/src/test/java/brooklyn/enricher/EnrichersTest.java
@@ -456,7 +456,6 @@ public class EnrichersTest extends BrooklynAppUnitTestSupport {
         EntityTestUtils.assertAttributeEqualsEventually(entity, TestEntity.NAME, null);
     }
 
-    
     @Test
     public void testJoinerUnquoted() {
         entity.setAttribute(LIST_SENSOR, MutableList.<String>of("a", "\"b", "ccc").append(null));
@@ -476,4 +475,27 @@ public class EnrichersTest extends BrooklynAppUnitTestSupport {
         EntityTestUtils.assertAttributeEqualsEventually(entity, TestEntity.NAME, null);
     }
 
+    @Test
+    public void testJoinerMinMax() {
+        entity.addEnricher(Enrichers.builder()
+                .joining(LIST_SENSOR)
+                .publishing(TestEntity.NAME)
+                .minimum(2)
+                .maximum(4)
+                .quote(false)
+                .build());
+        // null values ignored, and it quotes
+        entity.setAttribute(LIST_SENSOR, MutableList.<String>of("a", "b"));
+        EntityTestUtils.assertAttributeEqualsEventually(entity, TestEntity.NAME, "a,b");
+        
+        // empty list causes ""
+        entity.setAttribute(LIST_SENSOR, MutableList.<String>of("x"));
+        EntityTestUtils.assertAttributeEqualsEventually(entity, TestEntity.NAME, null);
+        
+        // null causes null
+        entity.setAttribute(LIST_SENSOR, MutableList.<String>of("a", "b", "c", "d",
"e"));
+        EntityTestUtils.assertAttributeEqualsEventually(entity, TestEntity.NAME, "a,b,c,d");
+    }
+
+
 }


Mime
View raw message