| | |
| | | |
| | | import com.zy.asrs.entity.DeviceConfig; |
| | | import com.zy.common.utils.RedisUtil; |
| | | import com.zy.core.cache.MessageQueue; |
| | | import com.zy.core.enums.SlaveType; |
| | | import com.zy.core.model.Task; |
| | | import com.zy.core.model.command.StationCommand; |
| | | import com.zy.core.model.protocol.StationProtocol; |
| | | import com.zy.core.model.protocol.StationTaskBufferItem; |
| | | import com.zy.core.network.ZyStationConnectDriver; |
| | | import com.zy.core.thread.impl.v5.StationV5SegmentExecutor; |
| | | import com.zy.core.thread.impl.v5.StationV5StatusReader; |
| | | import org.junit.jupiter.api.Test; |
| | | import org.springframework.test.util.ReflectionTestUtils; |
| | | |
| | |
| | | import static org.mockito.ArgumentMatchers.eq; |
| | | import static org.mockito.Mockito.mock; |
| | | import static org.mockito.Mockito.never; |
| | | import static org.mockito.Mockito.timeout; |
| | | import static org.mockito.Mockito.verify; |
| | | import static org.mockito.Mockito.when; |
| | | |
| | | class ZyStationV5ThreadTest { |
| | | |
| | | @Test |
| | | void pollAndDispatchQueuedCommand_submitsQueuedMoveCommandToSegmentExecutor() { |
| | | DeviceConfig deviceConfig = new DeviceConfig(); |
| | | deviceConfig.setDeviceNo(1); |
| | | RedisUtil redisUtil = mock(RedisUtil.class); |
| | | StationCommand command = new StationCommand(); |
| | | StationV5SegmentExecutor segmentExecutor = mock(StationV5SegmentExecutor.class); |
| | | |
| | | ZyStationV5Thread thread = new ZyStationV5Thread(deviceConfig, redisUtil); |
| | | ReflectionTestUtils.setField(thread, "segmentExecutor", segmentExecutor); |
| | | |
| | | MessageQueue.init(SlaveType.Devp, 1); |
| | | try { |
| | | MessageQueue.offer(SlaveType.Devp, 1, new Task(2, command)); |
| | | |
| | | ReflectionTestUtils.invokeMethod(thread, "pollAndDispatchQueuedCommand"); |
| | | |
| | | verify(segmentExecutor, timeout(1000)).execute(command); |
| | | } finally { |
| | | MessageQueue.clear(SlaveType.Devp, 1); |
| | | thread.close(); |
| | | } |
| | | } |
| | | |
| | | @Test |
| | | void clearPath_delegatesPureSlotClearingToDriver() { |
| | |
| | | station10.setStationId(10); |
| | | station10.setTaskBufferItems(List.of(hitItem)); |
| | | |
| | | ReflectionTestUtils.setField(thread, "statusList", Arrays.asList(station20, station10)); |
| | | StationV5StatusReader statusReader = (StationV5StatusReader) ReflectionTestUtils.getField(thread, "statusReader"); |
| | | ReflectionTestUtils.setField(statusReader, "statusList", Arrays.asList(station20, station10)); |
| | | |
| | | boolean result = thread.clearPath(100); |
| | | |