From 14ac9c2a2384f1e55b4c01eb7a104033b589d1e0 Mon Sep 17 00:00:00 2001
From: yeg <1347747024@qq.com>
Date: 星期六, 29 八月 2026 16:47:05 +0800
Subject: [PATCH] 增加模拟器设备总开关
---
ruoyi-device/src/test/java/com/ruoyi/device/contract/SimulatorPublicContractTest.java | 37 +++++++++++++++++++++++++++++++++++++
1 files changed, 37 insertions(+), 0 deletions(-)
diff --git a/ruoyi-device/src/test/java/com/ruoyi/device/contract/SimulatorPublicContractTest.java b/ruoyi-device/src/test/java/com/ruoyi/device/contract/SimulatorPublicContractTest.java
index 4570d60..83c40aa 100644
--- a/ruoyi-device/src/test/java/com/ruoyi/device/contract/SimulatorPublicContractTest.java
+++ b/ruoyi-device/src/test/java/com/ruoyi/device/contract/SimulatorPublicContractTest.java
@@ -120,6 +120,43 @@
}
@Test
+ void simulatorPowerSwitchStopsSamplingAndRestoresWithoutDeletingHistory() throws Exception
+ {
+ InMemoryBtsSimulatorStateStore store = new InMemoryBtsSimulatorStateStore();
+ long historyCount;
+ try (BtsDevelopmentSimulator simulator = new BtsDevelopmentSimulator(0, store))
+ {
+ simulator.advanceCollectors(Instant.now());
+ historyCount = simulator.snapshot().collectors().get(0).historyRecordCount();
+
+ simulator.setAllDevicesPoweredOn(false);
+ simulator.advanceCollectors(Instant.now().plusSeconds(10));
+
+ var poweredOff = simulator.snapshot();
+ assertTrue(poweredOff.devices().stream().noneMatch(device -> device.online()
+ || device.channels().stream().anyMatch(channel -> channel.online()
+ || channel.workStatus() != DeviceWorkStatus.STOPPED)));
+ assertTrue(poweredOff.collectors().stream().noneMatch(collector -> collector.online()));
+ assertEquals(historyCount, poweredOff.collectors().get(0).historyRecordCount());
+ }
+
+ try (BtsDevelopmentSimulator restored = new BtsDevelopmentSimulator(0, store))
+ {
+ assertFalse(restored.snapshot().collectors().get(0).online());
+ assertEquals(historyCount, restored.collectorHistory(1, 0, 1000).total());
+
+ restored.setAllDevicesPoweredOn(true);
+ var poweredOn = restored.snapshot();
+ assertTrue(poweredOn.devices().stream().allMatch(device -> device.online()
+ && device.channels().stream().allMatch(channel -> channel.online()
+ && channel.workStatus() == DeviceWorkStatus.STOPPED)));
+ assertTrue(poweredOn.collectors().stream().allMatch(collector -> collector.online()));
+ restored.advanceCollectors(Instant.now().plusSeconds(2));
+ assertTrue(restored.snapshot().collectors().get(0).historyRecordCount() > historyCount);
+ }
+ }
+
+ @Test
void collectorKeepsAppendOnlyHistoryBeyondPreviousDisplayLimit() throws Exception
{
Instant startedAt = Instant.parse("2026-08-29T03:00:00Z");
--
Gitblit v1.7.1