| | |
| | | |
| | | import com.zy.asrs.entity.BasDevp; |
| | | import com.zy.asrs.entity.WrkMast; |
| | | import com.zy.asrs.service.BasDevpService; |
| | | import com.zy.asrs.service.WrkMastService; |
| | | import com.zy.core.cache.MessageQueue; |
| | | import com.zy.core.cache.SlaveConnection; |
| | | import com.zy.core.enums.SlaveType; |
| | | import com.zy.core.enums.WrkStsType; |
| | | import com.zy.core.enums.WrkIoType; |
| | | import com.zy.core.move.StationMoveCoordinator; |
| | | import com.zy.core.move.StationMoveDispatchMode; |
| | | import com.zy.core.move.StationMoveSession; |
| | | import com.zy.core.model.command.StationCommand; |
| | | import com.zy.core.model.protocol.StationProtocol; |
| | |
| | | |
| | | import java.util.Collections; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | import static org.junit.jupiter.api.Assertions.assertEquals; |
| | | import static org.junit.jupiter.api.Assertions.assertSame; |
| | | import static org.junit.jupiter.api.Assertions.assertTrue; |
| | | import static org.junit.jupiter.api.Assertions.assertNull; |
| | | import static org.mockito.ArgumentMatchers.any; |
| | | import static org.mockito.ArgumentMatchers.anyString; |
| | | import static org.mockito.ArgumentMatchers.eq; |
| | | import static org.mockito.Mockito.mock; |
| | | import static org.mockito.Mockito.never; |
| | | import static org.mockito.Mockito.verify; |
| | |
| | | verify(coordinator, never()).cancelSession(100); |
| | | } |
| | | |
| | | @Test |
| | | void checkStationOutOrder_skipsWhenBlockedSessionAlreadyOwnsCurrentStation() { |
| | | StationOperateProcessUtils utils = new StationOperateProcessUtils(); |
| | | BasDevpService basDevpService = mock(BasDevpService.class); |
| | | WrkMastService wrkMastService = mock(WrkMastService.class); |
| | | StationMoveCoordinator coordinator = mock(StationMoveCoordinator.class); |
| | | RedisUtil redisUtil = mock(RedisUtil.class); |
| | | StationThread stationThread = mock(StationThread.class); |
| | | |
| | | ReflectionTestUtils.setField(utils, "basDevpService", basDevpService); |
| | | ReflectionTestUtils.setField(utils, "wrkMastService", wrkMastService); |
| | | ReflectionTestUtils.setField(utils, "stationMoveCoordinator", coordinator); |
| | | ReflectionTestUtils.setField(utils, "redisUtil", redisUtil); |
| | | |
| | | BasDevp basDevp = buildBasDevp(1); |
| | | basDevp.setIsOutOrderList("[{\"deviceNo\":1,\"stationId\":145}]"); |
| | | when(basDevpService.list(any(com.baomidou.mybatisplus.core.conditions.Wrapper.class))) |
| | | .thenReturn(Collections.singletonList(basDevp)); |
| | | |
| | | StationProtocol stationProtocol = buildStationProtocol(145, 10337, 145); |
| | | stationProtocol.setAutoing(true); |
| | | stationProtocol.setLoading(true); |
| | | when(stationThread.getStatusMap()).thenReturn(Map.of(145, stationProtocol)); |
| | | |
| | | StationCommand command = new StationCommand(); |
| | | command.setTaskNo(10337); |
| | | command.setStationId(145); |
| | | command.setTargetStaNo(111); |
| | | when(stationThread.getCommand(eq(com.zy.core.enums.StationCommandType.MOVE), eq(10337), eq(145), eq(111), eq(0), eq(0.0d))) |
| | | .thenReturn(command); |
| | | |
| | | WrkMast wrkMast = buildWrkMast(10337, 111); |
| | | wrkMast.setWrkSts(WrkStsType.STATION_RUN.sts); |
| | | wrkMast.setIoType(WrkIoType.OUT.id); |
| | | when(wrkMastService.selectByWorkNo(10337)).thenReturn(wrkMast); |
| | | |
| | | StationMoveSession session = new StationMoveSession(); |
| | | session.setTaskNo(10337); |
| | | session.setStatus(StationMoveSession.STATUS_BLOCKED); |
| | | session.setDispatchMode(StationMoveDispatchMode.CIRCLE); |
| | | session.setCurrentStationId(145); |
| | | session.setCurrentRouteTargetStationId(148); |
| | | session.setNextDecisionStationId(148); |
| | | session.setFullPathStationIds(List.of(145, 148, 149, 151, 119, 118, 117, 115, 114, 111)); |
| | | when(coordinator.loadSession(10337)).thenReturn(session); |
| | | |
| | | when(redisUtil.get(anyString())).thenReturn(null); |
| | | |
| | | MessageQueue.init(SlaveType.Devp, 1); |
| | | SlaveConnection.put(SlaveType.Devp, 1, stationThread); |
| | | try { |
| | | utils.checkStationOutOrder(); |
| | | |
| | | assertNull(MessageQueue.peek(SlaveType.Devp, 1)); |
| | | verify(stationThread, never()).getCommand(eq(com.zy.core.enums.StationCommandType.MOVE), eq(10337), eq(145), eq(111), eq(0), eq(0.0d)); |
| | | } finally { |
| | | MessageQueue.clear(SlaveType.Devp, 1); |
| | | SlaveConnection.remove(SlaveType.Devp, 1); |
| | | } |
| | | } |
| | | |
| | | private static BasDevp buildBasDevp(int devpNo) { |
| | | BasDevp basDevp = new BasDevp(); |
| | | basDevp.setDevpNo(devpNo); |