diff --git a/dz3-model/src/main/java/net/sf/dz3/device/model/impl/AbstractDamperController.java b/dz3-model/src/main/java/net/sf/dz3/device/model/impl/AbstractDamperController.java index f8303d899..8863062aa 100644 --- a/dz3-model/src/main/java/net/sf/dz3/device/model/impl/AbstractDamperController.java +++ b/dz3-model/src/main/java/net/sf/dz3/device/model/impl/AbstractDamperController.java @@ -130,7 +130,10 @@ public synchronized void remove(Thermostat ts) { ts2damper.remove(ts); } - public synchronized void stateChanged(Thermostat source, ThermostatSignal signal) { + /** + * {@inheritDoc} + */ + public synchronized Future stateChanged(Thermostat source, ThermostatSignal signal) { ThreadContext.push("signalChanged"); @@ -146,12 +149,11 @@ public synchronized void stateChanged(Thermostat source, ThermostatSignal signal logger.info("Demand: " + source.getName() + "=" + signal.demand.sample); logger.info("ts2signal.size()=" + ts2signal.size()); - sync(); + return sync(); } finally { ThreadContext.pop(); } - } public synchronized void consume(DataSample signal) { @@ -206,7 +208,7 @@ public synchronized void consume(DataSample signal) { } } - private void park(boolean async) { + private Future park(boolean async) { ThreadContext.push("park"); @@ -224,10 +226,12 @@ private void park(boolean async) { damperMap.put(d, d.getParkPosition()); } - shuffle(damperMap, async); + Future done = shuffle(damperMap, async); logger.info("parked"); + return done; + } finally { ThreadContext.pop(); } @@ -310,7 +314,7 @@ public synchronized String[] getDamperMap() { /** * Recalculate the damper state according to [possibly] changed internal state. */ - protected final void sync() { + protected final Future sync() { // VT: NOTE: This assumes compute() is stateless, ideally, it should stay that way. // If there is ever a need to make it stateful, compute() should be called outside @@ -318,11 +322,11 @@ protected final void sync() { if (this.hvacSignal != null && this.hvacSignal.sample.running) { - shuffle(compute(), true); + return shuffle(compute(), true); } else { - park(true); + return park(true); } } diff --git a/dz3-model/src/test/java/net/sf/dz3/device/model/impl/BalancingDamperControllerTest.java b/dz3-model/src/test/java/net/sf/dz3/device/model/impl/BalancingDamperControllerTest.java index 31eb02b8d..a56e97ed6 100644 --- a/dz3-model/src/test/java/net/sf/dz3/device/model/impl/BalancingDamperControllerTest.java +++ b/dz3-model/src/test/java/net/sf/dz3/device/model/impl/BalancingDamperControllerTest.java @@ -2,6 +2,7 @@ import java.io.IOException; import java.util.concurrent.CompletableFuture; +import java.util.concurrent.ExecutionException; import java.util.concurrent.Future; import org.apache.logging.log4j.LogManager; @@ -59,7 +60,7 @@ public void testBoundaries() { /** * Make sure that zero demand from all thermostats doesn't cause NaN sent to dampers. */ - public void testNaN() { + public void testNaN() throws InterruptedException, ExecutionException { ThreadContext.push("testNaN"); @@ -76,7 +77,11 @@ public void testNaN() { // No calculations are performed unless the HVAC unit signal is present damperController.consume(new DataSample("unit1", "unit1", new UnitSignal(1.0, true, 0), null)); - damperController.stateChanged(ts1, new ThermostatSignal(true, false, true, true, new DataSample("ts1", "ts1", -50.0, null))); + Future done = damperController.stateChanged(ts1, new ThermostatSignal(true, false, true, true, new DataSample("ts1", "ts1", -50.0, null))); + + TransitionStatus status = done.get(); + + assertTrue(status.isOK()); logger.debug("about to assert");