You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@brooklyn.apache.org by al...@apache.org on 2016/05/24 09:54:15 UTC
[2/4] brooklyn-server git commit: Transformer enricher: support
triggerSensors
Transformer enricher: support triggerSensors
Some uses of the transformer want to be triggered by multiple sensor
events (e.g. when they will combine two sensor values). This change
allows us to subscribe to multiple sensors, and to trigger the
evaulation when any of those change.
The sourceSensor is now optional. You can use it in the same way as
previously, or you can use just triggerSensors, or you can combine the
two. If combined, then the triggerSensors will cause us to look up the
latest value of the sourceSensor and synthesise an event as though
the source sensor had just published.
Project: http://git-wip-us.apache.org/repos/asf/brooklyn-server/repo
Commit: http://git-wip-us.apache.org/repos/asf/brooklyn-server/commit/b59e7463
Tree: http://git-wip-us.apache.org/repos/asf/brooklyn-server/tree/b59e7463
Diff: http://git-wip-us.apache.org/repos/asf/brooklyn-server/diff/b59e7463
Branch: refs/heads/master
Commit: b59e7463a9b337c2d0e7931cd420d5bac68d8549
Parents: c9db37e
Author: Aled Sage <al...@gmail.com>
Authored: Tue May 17 11:08:54 2016 +0100
Committer: Aled Sage <al...@gmail.com>
Committed: Tue May 24 10:53:13 2016 +0100
----------------------------------------------------------------------
.../enricher/stock/AbstractTransformer.java | 65 ++++++--
.../brooklyn/enricher/stock/Transformer.java | 6 +-
.../YamlRollingTimeWindowMeanEnricher.java | 10 ++
.../stock/YamlTimeWeightedDeltaEnricher.java | 11 +-
.../stock/TransformingEnricherTest.java | 157 +++++++++++++++++++
5 files changed, 233 insertions(+), 16 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/b59e7463/core/src/main/java/org/apache/brooklyn/enricher/stock/AbstractTransformer.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/enricher/stock/AbstractTransformer.java b/core/src/main/java/org/apache/brooklyn/enricher/stock/AbstractTransformer.java
index 5d1fe3e..a9c6d07 100644
--- a/core/src/main/java/org/apache/brooklyn/enricher/stock/AbstractTransformer.java
+++ b/core/src/main/java/org/apache/brooklyn/enricher/stock/AbstractTransformer.java
@@ -18,6 +18,8 @@
*/
package org.apache.brooklyn.enricher.stock;
+import java.util.List;
+
import org.apache.brooklyn.api.entity.Entity;
import org.apache.brooklyn.api.entity.EntityLocal;
import org.apache.brooklyn.api.sensor.AttributeSensor;
@@ -27,12 +29,17 @@ import org.apache.brooklyn.api.sensor.SensorEventListener;
import org.apache.brooklyn.config.ConfigKey;
import org.apache.brooklyn.core.config.ConfigKeys;
import org.apache.brooklyn.core.enricher.AbstractEnricher;
+import org.apache.brooklyn.core.mgmt.BrooklynTaskTags;
import org.apache.brooklyn.core.sensor.BasicSensorEvent;
+import org.apache.brooklyn.core.sensor.Sensors;
+import org.apache.brooklyn.util.collections.MutableMap;
+import org.apache.brooklyn.util.core.task.Tasks;
import org.apache.brooklyn.util.javalang.JavaClassNames;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.google.common.base.Function;
+import com.google.common.collect.ImmutableList;
import com.google.common.reflect.TypeToken;
@SuppressWarnings("serial")
@@ -40,12 +47,18 @@ public abstract class AbstractTransformer<T,U> extends AbstractEnricher implemen
private static final Logger LOG = LoggerFactory.getLogger(AbstractTransformer.class);
- public static ConfigKey<Entity> PRODUCER = ConfigKeys.newConfigKey(Entity.class, "enricher.producer");
+ public static final ConfigKey<Entity> PRODUCER = ConfigKeys.newConfigKey(Entity.class, "enricher.producer");
- public static ConfigKey<Sensor<?>> SOURCE_SENSOR = ConfigKeys.newConfigKey(new TypeToken<Sensor<?>>() {}, "enricher.sourceSensor");
+ public static final ConfigKey<Sensor<?>> SOURCE_SENSOR = ConfigKeys.newConfigKey(new TypeToken<Sensor<?>>() {}, "enricher.sourceSensor");
- public static ConfigKey<Sensor<?>> TARGET_SENSOR = ConfigKeys.newConfigKey(new TypeToken<Sensor<?>>() {}, "enricher.targetSensor");
+ public static final ConfigKey<Sensor<?>> TARGET_SENSOR = ConfigKeys.newConfigKey(new TypeToken<Sensor<?>>() {}, "enricher.targetSensor");
+ public static final ConfigKey<List<? extends Sensor<?>>> TRIGGER_SENSORS = ConfigKeys.newConfigKey(
+ new TypeToken<List<? extends Sensor<?>>>() {},
+ "enricher.triggerSensors",
+ "Sensors that will trigger re-evaluation",
+ ImmutableList.<Sensor<?>>of());
+
protected Entity producer;
protected Sensor<T> sourceSensor;
protected Sensor<U> targetSensor;
@@ -59,27 +72,55 @@ public abstract class AbstractTransformer<T,U> extends AbstractEnricher implemen
super.setEntity(entity);
this.producer = getConfig(PRODUCER) == null ? entity: getConfig(PRODUCER);
- this.sourceSensor = (Sensor<T>) getRequiredConfig(SOURCE_SENSOR);
+ this.sourceSensor = (Sensor<T>) getConfig(SOURCE_SENSOR);
Sensor<?> targetSensorSpecified = getConfig(TARGET_SENSOR);
+ List<? extends Sensor<?>> triggerSensorsSpecified = getConfig(TRIGGER_SENSORS);
+ List<? extends Sensor<?>> triggerSensors = triggerSensorsSpecified != null ? triggerSensorsSpecified : ImmutableList.<Sensor<?>>of();
this.targetSensor = targetSensorSpecified!=null ? (Sensor<U>) targetSensorSpecified : (Sensor<U>) this.sourceSensor;
- if (producer.equals(entity) && targetSensorSpecified==null) {
+ if (targetSensor == null) {
+ throw new IllegalArgumentException("Enricher "+JavaClassNames.simpleClassName(this)+" has no "+TARGET_SENSOR.getName()+", and it cannot be inferred as "+SOURCE_SENSOR.getName()+" is also not set");
+ }
+ if (sourceSensor == null && triggerSensors.isEmpty()) {
+ throw new IllegalArgumentException("Enricher "+JavaClassNames.simpleClassName(this)+" has no "+SOURCE_SENSOR.getName()+" and no "+TRIGGER_SENSORS.getName());
+ }
+ if (producer.equals(entity) && (targetSensor.equals(sourceSensor) || triggerSensors.contains(targetSensor))) {
// We cannot call getTransformation() here to log the tranformation, as it will attempt
// to resolve the transformation, which will cause the entity initialization thread to block
LOG.error("Refusing to add an enricher which reads and publishes on the same sensor: "+
- producer+"."+sourceSensor+" (computing transformation with "+JavaClassNames.simpleClassName(this)+")");
+ producer+"->"+targetSensor+" (computing transformation with "+JavaClassNames.simpleClassName(this)+")");
// we don't throw because this error may manifest itself after a lengthy deployment,
// and failing it at that point simply because of an enricher is not very pleasant
// (at least not until we have good re-run support across the board)
return;
}
- subscriptions().subscribe(producer, sourceSensor, this);
+ if (sourceSensor != null) {
+ subscriptions().subscribe(MutableMap.of("notifyOfInitialValue", true), producer, sourceSensor, this);
+ }
- if (sourceSensor instanceof AttributeSensor) {
- Object value = producer.getAttribute((AttributeSensor<?>)sourceSensor);
- // TODO would be useful to have a convenience to "subscribeAndThenIfItIsAlreadySetRunItOnce"
- if (value!=null) {
- onEvent(new BasicSensorEvent(sourceSensor, producer, value, -1));
+ if (triggerSensors.size() > 0) {
+ SensorEventListener<Object> triggerListener = new SensorEventListener<Object>() {
+ @Override public void onEvent(SensorEvent<Object> event) {
+ if (sourceSensor != null) {
+ // Simulate an event, as though our sourceSensor changed
+ Object value = producer.getAttribute((AttributeSensor<?>)sourceSensor);
+ AbstractTransformer.this.onEvent(new BasicSensorEvent(sourceSensor, producer, value, event.getTimestamp()));
+ } else {
+ // Assume the transform doesn't care about the value - otherwise it would
+ // have declared a sourceSensor!
+ AbstractTransformer.this.onEvent(null);
+ }
+ }
+ };
+ for (Object sensor : triggerSensors) {
+ if (sensor instanceof String) {
+ Sensor<?> resolvedSensor = entity.getEntityType().getSensor((String)sensor);
+ if (resolvedSensor == null) {
+ resolvedSensor = Sensors.newSensor(Object.class, (String)sensor);
+ }
+ sensor = resolvedSensor;
+ }
+ subscriptions().subscribe(MutableMap.of("notifyOfInitialValue", true), producer, (Sensor<?>)sensor, triggerListener);
}
}
}
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/b59e7463/core/src/main/java/org/apache/brooklyn/enricher/stock/Transformer.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/enricher/stock/Transformer.java b/core/src/main/java/org/apache/brooklyn/enricher/stock/Transformer.java
index d6c4549..8445076 100644
--- a/core/src/main/java/org/apache/brooklyn/enricher/stock/Transformer.java
+++ b/core/src/main/java/org/apache/brooklyn/enricher/stock/Transformer.java
@@ -40,9 +40,9 @@ public class Transformer<T,U> extends AbstractTransformer<T,U> {
private static final Logger LOG = LoggerFactory.getLogger(Transformer.class);
// exactly one of these should be supplied to set a value
- public static ConfigKey<?> TARGET_VALUE = ConfigKeys.newConfigKey(Object.class, "enricher.targetValue");
- public static ConfigKey<Function<?, ?>> TRANSFORMATION_FROM_VALUE = ConfigKeys.newConfigKey(new TypeToken<Function<?, ?>>() {}, "enricher.transformation");
- public static ConfigKey<Function<?, ?>> TRANSFORMATION_FROM_EVENT = ConfigKeys.newConfigKey(new TypeToken<Function<?, ?>>() {}, "enricher.transformation.fromevent");
+ public static final ConfigKey<Object> TARGET_VALUE = ConfigKeys.newConfigKey(Object.class, "enricher.targetValue");
+ public static final ConfigKey<Function<?, ?>> TRANSFORMATION_FROM_VALUE = ConfigKeys.newConfigKey(new TypeToken<Function<?, ?>>() {}, "enricher.transformation");
+ public static final ConfigKey<Function<?, ?>> TRANSFORMATION_FROM_EVENT = ConfigKeys.newConfigKey(new TypeToken<Function<?, ?>>() {}, "enricher.transformation.fromevent");
public Transformer() { }
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/b59e7463/core/src/main/java/org/apache/brooklyn/enricher/stock/YamlRollingTimeWindowMeanEnricher.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/enricher/stock/YamlRollingTimeWindowMeanEnricher.java b/core/src/main/java/org/apache/brooklyn/enricher/stock/YamlRollingTimeWindowMeanEnricher.java
index f4e5484..dfbc4f8 100644
--- a/core/src/main/java/org/apache/brooklyn/enricher/stock/YamlRollingTimeWindowMeanEnricher.java
+++ b/core/src/main/java/org/apache/brooklyn/enricher/stock/YamlRollingTimeWindowMeanEnricher.java
@@ -20,7 +20,9 @@ package org.apache.brooklyn.enricher.stock;
import java.util.Iterator;
import java.util.LinkedList;
+import java.util.List;
+import org.apache.brooklyn.api.entity.EntityLocal;
import org.apache.brooklyn.api.sensor.Sensor;
import org.apache.brooklyn.api.sensor.SensorEvent;
import org.apache.brooklyn.config.ConfigKey;
@@ -81,6 +83,14 @@ public class YamlRollingTimeWindowMeanEnricher<T extends Number> extends Abstrac
volatile ConfidenceQualifiedNumber lastAverage = new ConfidenceQualifiedNumber(0d,0d);
@Override
+ public void setEntity(EntityLocal entity) {
+ super.setEntity(entity);
+
+ // Check that sourceSensor has been set (rather than triggerSensors)
+ getRequiredConfig(SOURCE_SENSOR);
+ }
+
+ @Override
protected Function<SensorEvent<T>, Double> getTransformation() {
return new Function<SensorEvent<T>, Double>() {
@Override
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/b59e7463/core/src/main/java/org/apache/brooklyn/enricher/stock/YamlTimeWeightedDeltaEnricher.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/enricher/stock/YamlTimeWeightedDeltaEnricher.java b/core/src/main/java/org/apache/brooklyn/enricher/stock/YamlTimeWeightedDeltaEnricher.java
index e1a661e..9193e28 100644
--- a/core/src/main/java/org/apache/brooklyn/enricher/stock/YamlTimeWeightedDeltaEnricher.java
+++ b/core/src/main/java/org/apache/brooklyn/enricher/stock/YamlTimeWeightedDeltaEnricher.java
@@ -18,6 +18,7 @@
*/
package org.apache.brooklyn.enricher.stock;
+import org.apache.brooklyn.api.entity.EntityLocal;
import org.apache.brooklyn.api.sensor.SensorEvent;
import org.apache.brooklyn.config.ConfigKey;
import org.apache.brooklyn.core.config.ConfigKeys;
@@ -44,10 +45,18 @@ public class YamlTimeWeightedDeltaEnricher<T extends Number> extends AbstractTra
Number lastValue;
long lastTime = -1;
- public static ConfigKey<Duration> DELTA_PERIOD = ConfigKeys.newConfigKey(Duration.class, "enricher.delta.period",
+ public static final ConfigKey<Duration> DELTA_PERIOD = ConfigKeys.newConfigKey(Duration.class, "enricher.delta.period",
"Duration that this delta should compute for, default per second", Duration.ONE_SECOND);
@Override
+ public void setEntity(EntityLocal entity) {
+ super.setEntity(entity);
+
+ // Check that sourceSensor has been set (rather than triggerSensors)
+ getRequiredConfig(SOURCE_SENSOR);
+ }
+
+ @Override
protected Function<SensorEvent<T>, Double> getTransformation() {
return new Function<SensorEvent<T>, Double>() {
@Override
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/b59e7463/core/src/test/java/org/apache/brooklyn/enricher/stock/TransformingEnricherTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/brooklyn/enricher/stock/TransformingEnricherTest.java b/core/src/test/java/org/apache/brooklyn/enricher/stock/TransformingEnricherTest.java
index a236edb..7481fa8 100644
--- a/core/src/test/java/org/apache/brooklyn/enricher/stock/TransformingEnricherTest.java
+++ b/core/src/test/java/org/apache/brooklyn/enricher/stock/TransformingEnricherTest.java
@@ -18,21 +18,30 @@
*/
package org.apache.brooklyn.enricher.stock;
+import java.util.List;
+
import org.apache.brooklyn.api.entity.EntitySpec;
import org.apache.brooklyn.api.sensor.AttributeSensor;
+import org.apache.brooklyn.api.sensor.EnricherSpec;
+import org.apache.brooklyn.api.sensor.Sensor;
import org.apache.brooklyn.core.entity.EntityAsserts;
import org.apache.brooklyn.core.location.SimulatedLocation;
import org.apache.brooklyn.core.sensor.BasicAttributeSensor;
import org.apache.brooklyn.core.test.BrooklynAppUnitTestSupport;
import org.apache.brooklyn.core.test.entity.TestEntity;
+import org.apache.brooklyn.test.Asserts;
+import org.apache.brooklyn.util.core.task.DeferredSupplier;
import org.apache.brooklyn.util.math.MathFunctions;
+import org.apache.brooklyn.util.time.Duration;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
import com.google.common.base.Function;
+import com.google.common.base.Functions;
import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableMap;
public class TransformingEnricherTest extends BrooklynAppUnitTestSupport {
@@ -40,6 +49,7 @@ public class TransformingEnricherTest extends BrooklynAppUnitTestSupport {
TestEntity producer;
AttributeSensor<Integer> intSensorA;
+ AttributeSensor<Integer> intSensorB;
AttributeSensor<Long> target;
@BeforeMethod(alwaysRun=true)
@@ -48,6 +58,7 @@ public class TransformingEnricherTest extends BrooklynAppUnitTestSupport {
super.setUp();
producer = app.createAndManageChild(EntitySpec.create(TestEntity.class));
intSensorA = new BasicAttributeSensor<Integer>(Integer.class, "int.sensor.a");
+ intSensorB = new BasicAttributeSensor<Integer>(Integer.class, "int.sensor.b");
target = new BasicAttributeSensor<Long>(Long.class, "long.sensor.target");
app.start(ImmutableList.of(new SimulatedLocation()));
@@ -67,4 +78,150 @@ public class TransformingEnricherTest extends BrooklynAppUnitTestSupport {
EntityAsserts.assertAttributeEqualsEventually(producer, target, 6L);
}
+
+ @Test
+ public void testTargetValueTriggeredBySourceSensor() throws Exception {
+ //ensure previous values get picked up
+ producer.sensors().set(intSensorA, 3);
+
+ producer.enrichers().add(EnricherSpec.create(Transformer.class)
+ .configure(Transformer.TARGET_SENSOR, target)
+ .configure(Transformer.SOURCE_SENSOR, intSensorA)
+ .configure(Transformer.PRODUCER, producer)
+ .configure(Transformer.TARGET_VALUE, new DeferredSupplier<Long>() {
+ @Override public Long get() {
+ Integer a = producer.sensors().get(intSensorA);
+ return (a == null ? null : a.longValue());
+ }}));
+
+ EntityAsserts.assertAttributeEqualsEventually(producer, target, 3L);
+
+ producer.sensors().set(intSensorA, 4);
+ EntityAsserts.assertAttributeEqualsEventually(producer, target, 4L);
+ }
+
+ @Test
+ public void testTargetValueTriggeredByOtherSensors() throws Exception {
+ //ensure previous values get picked up
+ producer.sensors().set(intSensorA, 3);
+
+ producer.enrichers().add(EnricherSpec.create(Transformer.class)
+ .configure(Transformer.TARGET_SENSOR, target)
+ .configure(Transformer.TRIGGER_SENSORS, ImmutableList.of(intSensorA, intSensorB))
+ .configure(Transformer.PRODUCER, producer)
+ .configure(Transformer.TARGET_VALUE, new DeferredSupplier<Long>() {
+ @Override public Long get() {
+ Integer a = producer.sensors().get(intSensorA);
+ Integer b = producer.sensors().get(intSensorB);
+ return (long) ((a == null ? 0 : a) + (b == null ? 0 : b));
+ }}));
+
+ EntityAsserts.assertAttributeEqualsEventually(producer, target, 3L);
+
+ producer.sensors().set(intSensorA, 4);
+ EntityAsserts.assertAttributeEqualsEventually(producer, target, 4L);
+
+ producer.sensors().set(intSensorB, 1);
+ EntityAsserts.assertAttributeEqualsEventually(producer, target, 5L);
+ }
+
+ @Test
+ public void testTransformationTriggeredByOtherSensors() throws Exception {
+ //ensure previous values get picked up
+ producer.sensors().set(intSensorA, 3);
+
+ producer.enrichers().add(EnricherSpec.create(Transformer.class)
+ .configure(Transformer.TARGET_SENSOR, target)
+ .configure(Transformer.SOURCE_SENSOR, intSensorA)
+ .configure(Transformer.TRIGGER_SENSORS, ImmutableList.of(intSensorB))
+ .configure(Transformer.PRODUCER, producer)
+ .configure(Transformer.TRANSFORMATION_FROM_VALUE, (Function)MathFunctions.times(2))); // TODO doesn't match strongly typed int->long
+
+ EntityAsserts.assertAttributeEqualsEventually(producer, target, 6L);
+
+ producer.sensors().set(intSensorA, 4);
+ EntityAsserts.assertAttributeEqualsEventually(producer, target, 8L);
+
+ producer.sensors().set(target, -1L);
+ producer.sensors().set(intSensorB, 1);
+ EntityAsserts.assertAttributeEqualsEventually(producer, target, 8L);
+ }
+
+ @Test
+ public void testTriggeringSensorNamesResolvedFromStrings() throws Exception {
+ // Doing nasty casting here, but in YAML we could easily get passed this.
+ producer.enrichers().add(EnricherSpec.create(Transformer.class)
+ .configure(Transformer.TARGET_SENSOR, target)
+ .configure(Transformer.TRIGGER_SENSORS, (List<Sensor<?>>)(List)ImmutableList.of(intSensorA.getName(), intSensorB.getName()))
+ .configure(Transformer.PRODUCER, producer)
+ .configure(Transformer.TARGET_VALUE, new DeferredSupplier<Long>() {
+ @Override public Long get() {
+ Integer a = producer.sensors().get(intSensorA);
+ Integer b = producer.sensors().get(intSensorB);
+ return (long) ((a == null ? 0 : a) + (b == null ? 0 : b));
+ }}));
+
+ producer.sensors().set(intSensorA, 1);
+ EntityAsserts.assertAttributeEqualsEventually(producer, target, 1L);
+ }
+
+ @Test
+ public void testTransformerAvoidsInfiniteLoopWhereSourceAndTargetSame() throws Exception {
+ producer.enrichers().add(EnricherSpec.create(Transformer.class)
+ .configure(Transformer.SOURCE_SENSOR, intSensorA)
+ .configure(Transformer.TARGET_SENSOR, intSensorA)
+ .configure(Transformer.PRODUCER, producer)
+ .configure(Transformer.TRANSFORMATION_FROM_VALUE, (Function)MathFunctions.times(2))); // TODO doesn't match strongly typed int->long
+
+ // Short wait; expect us to never re-publish the source-sensor as that would cause infinite loop.
+ producer.sensors().set(intSensorA, 1);
+ EntityAsserts.assertAttributeEqualsContinually(ImmutableMap.of("timeout", Duration.millis(250)), producer, intSensorA, 1);
+ }
+
+ @Test
+ public void testTransformerAvoidsInfiniteLoopWhereTriggerAndTargetSame() throws Exception {
+ //ensure previous values get picked up
+ producer.sensors().set(intSensorA, 3);
+
+ producer.enrichers().add(EnricherSpec.create(Transformer.class)
+ .configure(Transformer.TRIGGER_SENSORS, ImmutableList.of(intSensorA))
+ .configure(Transformer.TARGET_SENSOR, intSensorA)
+ .configure(Transformer.PRODUCER, producer)
+ .configure(Transformer.TARGET_VALUE, new DeferredSupplier<Integer>() {
+ @Override public Integer get() {
+ Integer a = producer.sensors().get(intSensorA);
+ return (a == null ? 0 : a+1);
+ }}));
+
+ producer.sensors().set(intSensorA, 1);
+ EntityAsserts.assertAttributeEqualsContinually(ImmutableMap.of("timeout", Duration.millis(250)), producer, intSensorA, 1);
+ }
+
+ @Test
+ public void testTransformerFailsIfMissingTriggers() throws Exception {
+ //ensure previous values get picked up
+ producer.sensors().set(intSensorA, 3);
+
+ try {
+ producer.enrichers().add(EnricherSpec.create(Transformer.class)
+ .configure(Transformer.TARGET_SENSOR, target)
+ .configure(Transformer.PRODUCER, producer)
+ .configure(Transformer.TRANSFORMATION_FROM_VALUE, Functions.identity()));
+ Asserts.shouldHaveFailedPreviously();
+ } catch (IllegalArgumentException e) {
+ Asserts.expectedFailureContains(e, "has no "+Transformer.SOURCE_SENSOR.getName()+" and no "+Transformer.TRIGGER_SENSORS.getName());
+ }
+ }
+
+ @Test
+ public void testInfersTargetSensorSameAsSource() throws Exception {
+ producer.sensors().set(intSensorA, 3);
+
+ app.enrichers().add(EnricherSpec.create(Transformer.class)
+ .configure(Transformer.SOURCE_SENSOR, intSensorA)
+ .configure(Transformer.PRODUCER, producer)
+ .configure(Transformer.TRANSFORMATION_FROM_VALUE, Functions.identity()));
+
+ EntityAsserts.assertAttributeEqualsEventually(app, intSensorA, 3);
+ }
}