| | |
| | | assertEquals(1, candidateStore.snapshot(java.time.Instant.now()).cabinets().size()); |
| | | verify(adapter).discoverChannels(); |
| | | } |
| | | |
| | | /** |
| | | * 直连厂商存储的来源:通道登记是长期事实,候选不按时间过期, |
| | | * 每条候选附带最近一次采样行的设备时间,供操作员判断哪几台真的在产出数据。 |
| | | */ |
| | | @Test |
| | | void vendorSourceCandidatesCarryLastDataTimeAndDoNotExpireByTime() |
| | | { |
| | | InMemoryDeviceDiscoveryCandidateStore candidateStore = new InMemoryDeviceDiscoveryCandidateStore(); |
| | | TDetectionCabinetMapper cabinetMapper = Mockito.mock(TDetectionCabinetMapper.class); |
| | | TTestMapper testMapper = Mockito.mock(TTestMapper.class); |
| | | DeviceAdapterRegistry registry = Mockito.mock(DeviceAdapterRegistry.class); |
| | | DeviceAdapter adapter = Mockito.mock(DeviceAdapter.class); |
| | | ChannelIdentity identity = new ChannelIdentity("neware76", 21, 36, 1, 2); |
| | | java.time.Instant lastDataAt = java.time.Instant.parse("2026-09-28T01:54:56Z"); |
| | | when(testMapper.hasReceivingTestForAdapter("neware76")).thenReturn(0); |
| | | when(adapter.discoverChannels()).thenReturn(List.of(new DetectedChannel(identity, "26.1.2.3", true, |
| | | com.battery.device.api.model.DetectedDeviceMetadata.empty(), lastDataAt))); |
| | | when(registry.execute(eq("neware76"), any())).thenAnswer(invocation -> { |
| | | @SuppressWarnings("unchecked") |
| | | Function<DeviceAdapter, Object> operation = (Function<DeviceAdapter, Object>) invocation.getArgument(1); |
| | | return operation.apply(adapter); |
| | | }); |
| | | |
| | | DeviceDiscoveryPersistenceService service = new DeviceDiscoveryPersistenceService(candidateStore, |
| | | cabinetMapper, testMapper); |
| | | service.discoverForReception(registry, new DeviceDiscoveryPersistenceService.DiscoverySource( |
| | | "neware76", 8L, "新威 7.6 那台", 60000, true)); |
| | | |
| | | var candidate = candidateStore.snapshot(java.time.Instant.now()).cabinets().get(0); |
| | | assertEquals(lastDataAt, candidate.lastDataAt()); |
| | | assertEquals(lastDataAt, candidate.channels().get(0).lastDataAt()); |
| | | // 一年后仍然是候选:候选只按"已登记且未删除"排除,不按时间过期。 |
| | | assertEquals(1, candidateStore.snapshot(java.time.Instant.now().plusSeconds(365L * 24 * 3600)) |
| | | .cabinets().size()); |
| | | } |
| | | } |