From 0d1f0a13a75d489b53e0794ad1aa23e7a68afaee Mon Sep 17 00:00:00 2001 From: Vadim Tkachenko Date: Tue, 31 Oct 2023 22:51:25 -0700 Subject: [PATCH] Bugfix: now not blowing up on missing pace (#292) --- .../dz3r/device/actuator/AbstractCqrsDevice.java | 5 +++++ .../device/actuator/AbstractCqrsDeviceTest.java | 14 ++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/dz3r-model/src/main/java/net/sf/dz3r/device/actuator/AbstractCqrsDevice.java b/dz3r-model/src/main/java/net/sf/dz3r/device/actuator/AbstractCqrsDevice.java index b80811725..c9c525710 100644 --- a/dz3r-model/src/main/java/net/sf/dz3r/device/actuator/AbstractCqrsDevice.java +++ b/dz3r-model/src/main/java/net/sf/dz3r/device/actuator/AbstractCqrsDevice.java @@ -75,6 +75,11 @@ synchronized Flux limitRate(I command) { try { + if (pace == null) { + logger.trace("{}: null pace - passthrough command={}", id, command); + return Flux.just(command); + } + var now = clock.instant(); if (!command.equals(lastCommand)) { diff --git a/dz3r-model/src/test/java/net/sf/dz3r/device/actuator/AbstractCqrsDeviceTest.java b/dz3r-model/src/test/java/net/sf/dz3r/device/actuator/AbstractCqrsDeviceTest.java index 89945f25e..b76297498 100644 --- a/dz3r-model/src/test/java/net/sf/dz3r/device/actuator/AbstractCqrsDeviceTest.java +++ b/dz3r-model/src/test/java/net/sf/dz3r/device/actuator/AbstractCqrsDeviceTest.java @@ -2,6 +2,7 @@ import net.sf.dz3r.common.TestClock; import net.sf.dz3r.device.DeviceState; +import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.MethodSource; import reactor.core.publisher.Flux; @@ -11,9 +12,22 @@ import java.util.stream.Stream; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatCode; class AbstractCqrsDeviceTest { + @Test + void noPace() { + var clock = new TestClock(); + var device = new PaceTest("pt", clock, null, null); + + device.limitRate("command"); + + assertThatCode(() -> { + device.limitRate("command"); + }).doesNotThrowAnyException(); + } + @ParameterizedTest @MethodSource("getPaceStream") void pace(Flux source) {