brooklyn-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aleds...@apache.org
Subject [1/2] brooklyn-server git commit: Fix FunctionSensor’s rebind
Date Thu, 21 Sep 2017 08:08:28 GMT
Repository: brooklyn-server
Updated Branches:
  refs/heads/master a0e5edcf6 -> 2a63d8e57


Fix FunctionSensor’s rebind

It was trying to serialise the TypeCoercions function. We don’t need
that - it coerces automatically.

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

Branch: refs/heads/master
Commit: 733554dbf3965de0f0be208c3b9d41173cb9abe2
Parents: a0e5edc
Author: Aled Sage <aled.sage@gmail.com>
Authored: Wed Sep 20 23:12:48 2017 +0100
Committer: Aled Sage <aled.sage@gmail.com>
Committed: Wed Sep 20 23:12:48 2017 +0100

----------------------------------------------------------------------
 .../camp/brooklyn/FunctionSensorYamlTest.java   | 38 ++++++++++++++++++--
 .../core/sensor/function/FunctionSensor.java    |  2 --
 2 files changed, 36 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/733554db/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/FunctionSensorYamlTest.java
----------------------------------------------------------------------
diff --git a/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/FunctionSensorYamlTest.java
b/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/FunctionSensorYamlTest.java
index 14402ec..ba6e669 100644
--- a/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/FunctionSensorYamlTest.java
+++ b/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/FunctionSensorYamlTest.java
@@ -38,7 +38,7 @@ public class FunctionSensorYamlTest extends AbstractYamlRebindTest {
     private static final Logger log = LoggerFactory.getLogger(FunctionSensorYamlTest.class);
 
     final static AttributeSensor<String> SENSOR_STRING = Sensors.newStringSensor("aString");
-    final static String TARGET_TYPE = "java.lang.String";
+    final static AttributeSensor<Integer> SENSOR_INT = Sensors.newIntegerSensor("anInt");
 
     public static class MyCallable implements Callable<Object> {
         public static AtomicReference<Object> val = new AtomicReference<>();
@@ -62,7 +62,7 @@ public class FunctionSensorYamlTest extends AbstractYamlRebindTest {
             "    brooklyn.config:",
             "      "+FunctionSensor.SENSOR_PERIOD.getName()+": 100ms",
             "      "+FunctionSensor.SENSOR_NAME.getName()+": " + SENSOR_STRING.getName(),
-            "      "+FunctionSensor.SENSOR_TYPE.getName()+": " + TARGET_TYPE,
+            "      "+FunctionSensor.SENSOR_TYPE.getName()+": String",
             "      "+FunctionSensor.FUNCTION.getName()+":",
             "        $brooklyn:object:",
             "          type: "+MyCallable.class.getName());
@@ -82,6 +82,40 @@ public class FunctionSensorYamlTest extends AbstractYamlRebindTest {
         EntityAsserts.assertAttributeEqualsEventually(newEntity, SENSOR_STRING, "third");
     }
 
+    @Test
+    public void testFunctionSensorCoerces() throws Exception {
+        MyCallable.val.set("1");
+        
+        Entity app = createAndStartApplication(
+            "services:",
+            "- type: " + TestEntity.class.getName(),
+            "  brooklyn.config:",
+            "    onbox.base.dir.skipResolution: true",
+            "  brooklyn.initializers:",
+            "  - type: "+FunctionSensor.class.getName(),
+            "    brooklyn.config:",
+            "      "+FunctionSensor.SENSOR_PERIOD.getName()+": 100ms",
+            "      "+FunctionSensor.SENSOR_NAME.getName()+": " + SENSOR_INT.getName(),
+            "      "+FunctionSensor.SENSOR_TYPE.getName()+": int",
+            "      "+FunctionSensor.FUNCTION.getName()+":",
+            "        $brooklyn:object:",
+            "          type: "+MyCallable.class.getName());
+        waitForApplicationTasks(app);
+        Entity entity = Iterables.getOnlyElement(app.getChildren());
+
+        EntityAsserts.assertAttributeEqualsEventually(entity, SENSOR_INT, 1);
+        
+        MyCallable.val.set("1");
+        EntityAsserts.assertAttributeEqualsEventually(entity, SENSOR_INT, 1);
+        
+        // Rebind, and confirm that it resumes polling
+        Application newApp = rebind();
+        Entity newEntity = Iterables.getOnlyElement(newApp.getChildren());
+
+        MyCallable.val.set("3");
+        EntityAsserts.assertAttributeEqualsEventually(newEntity, SENSOR_INT, 3);
+    }
+
     @Override
     protected Logger getLogger() {
         return log;

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/733554db/core/src/main/java/org/apache/brooklyn/core/sensor/function/FunctionSensor.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/core/sensor/function/FunctionSensor.java
b/core/src/main/java/org/apache/brooklyn/core/sensor/function/FunctionSensor.java
index cc77f02..4b32451 100644
--- a/core/src/main/java/org/apache/brooklyn/core/sensor/function/FunctionSensor.java
+++ b/core/src/main/java/org/apache/brooklyn/core/sensor/function/FunctionSensor.java
@@ -28,7 +28,6 @@ import org.apache.brooklyn.core.entity.EntityInitializers;
 import org.apache.brooklyn.feed.function.FunctionFeed;
 import org.apache.brooklyn.feed.function.FunctionPollConfig;
 import org.apache.brooklyn.util.core.config.ConfigBag;
-import org.apache.brooklyn.util.core.flags.TypeCoercions;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -77,7 +76,6 @@ public final class FunctionSensor<T> extends AddSensor<T> {
 
         FunctionPollConfig<?, T> pollConfig = new FunctionPollConfig<Object, T>(sensor)
                 .callable(function)
-                .onSuccess(TypeCoercions.function((Class<T>)sensor.getType()))
                 .onFailureOrException(Functions.constant((T) null))
                 .suppressDuplicates(Boolean.TRUE.equals(suppressDuplicates))
                 .period(period);


Mime
View raw message