| | |
| | | import com.alibaba.fastjson2.JSONObject; |
| | | import com.ruoyi.device.model.DeviceWorkStatus; |
| | | import com.ruoyi.device.simulator.BtsSimulatorStateStore.ChannelState; |
| | | import com.ruoyi.device.simulator.BtsSimulatorStateStore.ChannelTombstone; |
| | | import com.ruoyi.device.simulator.BtsSimulatorStateStore.CollectorState; |
| | | import com.ruoyi.device.simulator.BtsSimulatorStateStore.DeviceState; |
| | | import com.ruoyi.device.simulator.BtsSimulatorStateStore.SimulatorState; |
| | | import com.ruoyi.device.discovery.DeviceDiscoveryCandidateStore.CabinetCandidate; |
| | |
| | | } |
| | | |
| | | @Test |
| | | void restoresNestedSimulatorStateFromRedisSerializer() |
| | | { |
| | | SimulatorState expected = new SimulatorState(1, |
| | | List.of(new DeviceState(2, "127.0.0.3", false, |
| | | List.of(new ChannelState(1, true, DeviceWorkStatus.WORKING)))), |
| | | List.of(new CollectorState(3, "dev-sim-collector-3", "127.0.1.3", |
| | | "02:43:00:00:00:03", "模拟采集器", "开发模拟器", |
| | | "Virtual Collector", 3, true)), |
| | | 3, 4, List.of(new ChannelTombstone(1, "127.0.0.2", 4, 2))); |
| | | FastJson2JsonRedisSerializer<Object> serializer = new FastJson2JsonRedisSerializer<>(Object.class); |
| | | AtomicReference<Object> stored = new AtomicReference<>( |
| | | serializer.deserialize(serializer.serialize(JSON.toJSONString(expected)))); |
| | | |
| | | SimulatorState restored = store(stored).loadOrInitialize(state(1, "127.0.0.2")); |
| | | |
| | | assertEquals(expected, restored); |
| | | assertEquals(DeviceWorkStatus.WORKING, restored.devices().get(0).channels().get(0).workStatus()); |
| | | } |
| | | |
| | | @Test |
| | | void rejectsIncompatibleVersionWithoutOverwritingIt() |
| | | { |
| | | AtomicReference<Object> stored = new AtomicReference<>("{\"version\":2,\"devices\":[]," |