| | |
| | | } |
| | | |
| | | @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"); |