| | |
| | | class TTestLiveServiceImplTest |
| | | { |
| | | @Test |
| | | void persistedOfflineWarningWithoutMeasurementReplacesLiveHintAndSurvivesRefresh() |
| | | { |
| | | TTest test = test("RECEIVING"); |
| | | var mapper = mock(TTestMapper.class); |
| | | TTestWarningException warning = new TTestWarningException(); |
| | | warning.setExceptionId(21L); |
| | | warning.setExceptionType("DEVICE_OFFLINE"); |
| | | warning.setSourceType("CABINET_CHANNEL"); |
| | | warning.setSourceIdentity("dev-sim:1:1:0:1"); |
| | | warning.setMetricCode("DEVICE_ONLINE"); |
| | | warning.setExceptionStatus("OPEN"); |
| | | when(mapper.selectWarningExceptions(10L, "OPEN")).thenReturn(List.of(warning)); |
| | | var service = liveService(test, Instant.now(), false, DeviceWorkStatus.WORKING, mapper); |
| | | |
| | | for (int attempt = 0; attempt < 2; attempt++) { |
| | | var alarms = service.current(10L).exceptions(); |
| | | assertEquals(1, alarms.size()); |
| | | assertEquals(21L, alarms.get(0).get("exceptionId")); |
| | | assertEquals("DEVICE_OFFLINE", alarms.get(0).get("exceptionType")); |
| | | } |
| | | test.setReceptionStatus("PAUSED"); |
| | | assertTrue(service.current(10L).exceptions().isEmpty()); |
| | | test.setReceptionStatus("ENDED"); |
| | | assertTrue(service.current(10L).exceptions().isEmpty()); |
| | | } |
| | | |
| | | @Test |
| | | void receivingOfflineCabinetAndCollectorAreVisibleAsOpenAlarms() |
| | | { |
| | | TTest test = test("RECEIVING"); |
| | | test.getBatteries().get(0).setCollectorId(7L); |
| | | var service = liveService(test, Instant.now(), false); |
| | | |
| | | var alarms = service.current(10L).exceptions(); |
| | | |
| | | assertEquals(2, alarms.size()); |
| | | assertTrue(alarms.stream().allMatch(item -> "OPEN".equals(item.get("status")))); |
| | | assertTrue(alarms.stream().anyMatch(item -> "COLLECTOR".equals(item.get("sourceType")))); |
| | | assertTrue(alarms.stream().anyMatch(item -> "CABINET_CHANNEL".equals(item.get("sourceType")))); |
| | | } |
| | | |
| | | @Test |
| | | void nonReceivingConsoleReadsCollectorStatusWithoutRequestingMeasurements() throws Exception |
| | | { |
| | | try (var simulator = new com.battery.device.simulator.BtsDevelopmentSimulator(0)) |
| | | { |
| | | TTest test = test("RECEIVING"); |
| | | test.getBatteries().get(0).setCollectorId(7L); |
| | | var tests = mock(ITTestService.class); |
| | | when(tests.selectTestById(10L)).thenReturn(test); |
| | | var mapper = mock(TTestMapper.class); |
| | | when(mapper.selectCollectorCode(7L)).thenReturn("dev-sim-collector-1"); |
| | | var candidates = new com.battery.device.api.discovery.InMemoryDeviceDiscoveryCandidateStore(); |
| | | Instant now = Instant.now(); |
| | | candidates.replaceCollectors("dev-sim", List.of(new DeviceDiscoveryCandidateStore.CollectorCandidate( |
| | | "dev-sim", "dev-sim-collector-1", "127.0.1.2", null, "模拟采集器", null, null, |
| | | 4, true, now, now.plusSeconds(30)))); |
| | | var service = new TTestLiveServiceImpl(tests, candidates, simulator, mapper); |
| | | service.current(10L); |
| | | var received = simulator.snapshot().recentRequests(); |
| | | assertTrue(received.stream().anyMatch(item -> item.command().equals("collector-realtime"))); |
| | | for (String status : List.of("PAUSED", "ENDED", "NOT_STARTED")) |
| | | { |
| | | test.setReceptionStatus(status); |
| | | var source = service.current(10L).sources().stream() |
| | | .filter(item -> item.sourceType().equals("COLLECTOR")).findFirst().orElseThrow(); |
| | | assertEquals("ONLINE", source.deviceStatus()); |
| | | assertTrue(source.latestSnapshot().isEmpty()); |
| | | assertEquals(received, simulator.snapshot().recentRequests()); |
| | | } |
| | | } |
| | | } |
| | | |
| | | @Test |
| | | void notStartedShouldNotExposePreTestDeviceSnapshot() |
| | | { |
| | | Instant now = Instant.parse("2026-09-02T06:00:00Z"); |