|
@@ -42,6 +42,7 @@ import static org.mockito.ArgumentMatchers.anyLong;
|
|
|
import static org.mockito.ArgumentMatchers.anyString;
|
|
import static org.mockito.ArgumentMatchers.anyString;
|
|
|
import static org.mockito.ArgumentMatchers.eq;
|
|
import static org.mockito.ArgumentMatchers.eq;
|
|
|
import static org.mockito.Mockito.mock;
|
|
import static org.mockito.Mockito.mock;
|
|
|
|
|
+import static org.mockito.Mockito.never;
|
|
|
import static org.mockito.Mockito.verify;
|
|
import static org.mockito.Mockito.verify;
|
|
|
import static org.mockito.Mockito.when;
|
|
import static org.mockito.Mockito.when;
|
|
|
|
|
|
|
@@ -317,11 +318,35 @@ class BusinessCockpitMapSnapshotAdapterTest {
|
|
|
eq(java.util.concurrent.TimeUnit.SECONDS));
|
|
eq(java.util.concurrent.TimeUnit.SECONDS));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ @Test
|
|
|
|
|
+ void snapshotThatExpiresDuringBuildIsNotPublishedToRedis() {
|
|
|
|
|
+ RedisTemplate<Object, Object> sharedRedis = mock(RedisTemplate.class);
|
|
|
|
|
+ ValueOperations<Object, Object> values = mock(ValueOperations.class);
|
|
|
|
|
+ Clock advancingClock = mock(Clock.class);
|
|
|
|
|
+ when(sharedRedis.opsForValue()).thenReturn(values);
|
|
|
|
|
+ when(values.get(any())).thenReturn(null);
|
|
|
|
|
+ when(advancingClock.getZone()).thenReturn(ZoneOffset.UTC);
|
|
|
|
|
+ when(advancingClock.instant()).thenReturn(
|
|
|
|
|
+ Instant.parse("2026-09-02T02:00:00Z"),
|
|
|
|
|
+ Instant.parse("2026-09-02T02:10:00.001Z"));
|
|
|
|
|
+ when(monitorPointService.list()).thenReturn(Collections.emptyList());
|
|
|
|
|
+ when(equipmentBaseService.list()).thenReturn(Collections.emptyList());
|
|
|
|
|
+ when(equipmentTypeService.list()).thenReturn(Collections.emptyList());
|
|
|
|
|
+ BusinessCockpitMapSnapshotAdapter expiringAdapter = new BusinessCockpitMapSnapshotAdapter(
|
|
|
|
|
+ monitorPointService, equipmentBaseService, equipmentTypeService, deviceFactResolver,
|
|
|
|
|
+ advancingClock, sharedRedis);
|
|
|
|
|
+
|
|
|
|
|
+ assertThrows(CockpitSnapshotExpiredException.class,
|
|
|
|
|
+ () -> expiringAdapter.load("2026-09-02T10:00:00+08:00"));
|
|
|
|
|
+ verify(values, never()).setIfAbsent(any(), any(), anyLong(), any());
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
@Test
|
|
@Test
|
|
|
void expiredSnapshotAtIsRejectedInsteadOfLoadingCurrentRelations() {
|
|
void expiredSnapshotAtIsRejectedInsteadOfLoadingCurrentRelations() {
|
|
|
when(monitorPointService.list()).thenReturn(Collections.emptyList());
|
|
when(monitorPointService.list()).thenReturn(Collections.emptyList());
|
|
|
|
|
|
|
|
|
|
+ assertThrows(CockpitSnapshotExpiredException.class,
|
|
|
|
|
+ () -> adapter.load("2026-09-02T09:50:00+08:00"));
|
|
|
assertThrows(CockpitSnapshotExpiredException.class,
|
|
assertThrows(CockpitSnapshotExpiredException.class,
|
|
|
() -> adapter.load("2026-09-02T09:49:59+08:00"));
|
|
() -> adapter.load("2026-09-02T09:49:59+08:00"));
|
|
|
}
|
|
}
|