| | |
| | | import com.zy.asrs.entity.WrkMast; |
| | | import com.zy.asrs.service.BasDevpService; |
| | | import com.zy.asrs.service.WrkMastService; |
| | | import com.zy.asrs.service.WrkAnalysisService; |
| | | import com.zy.asrs.utils.NotifyUtils; |
| | | import com.zy.common.entity.FindCrnNoResult; |
| | | import com.zy.common.service.CommonService; |
| | | 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.enums.RedisKeyType; |
| | | import com.zy.core.move.StationMoveCoordinator; |
| | | import com.zy.core.move.StationMoveDispatchMode; |
| | | import com.zy.core.move.StationMoveSession; |
| | |
| | | import java.util.Collections; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.Objects; |
| | | |
| | | import static org.junit.jupiter.api.Assertions.assertEquals; |
| | | import static org.junit.jupiter.api.Assertions.assertSame; |
| | |
| | | import static org.mockito.ArgumentMatchers.any; |
| | | import static org.mockito.ArgumentMatchers.anyString; |
| | | import static org.mockito.ArgumentMatchers.eq; |
| | | import static org.mockito.ArgumentMatchers.same; |
| | | import static org.mockito.Mockito.mock; |
| | | import static org.mockito.Mockito.times; |
| | | import static org.mockito.Mockito.never; |
| | | import static org.mockito.Mockito.verify; |
| | | import static org.mockito.Mockito.when; |
| | |
| | | } |
| | | } |
| | | |
| | | @Test |
| | | void checkStationOutOrder_skipsRunBlockStationBeforePlanning() { |
| | | StationOperateProcessUtils utils = new StationOperateProcessUtils(); |
| | | BasDevpService basDevpService = mock(BasDevpService.class); |
| | | WrkMastService wrkMastService = mock(WrkMastService.class); |
| | | RedisUtil redisUtil = mock(RedisUtil.class); |
| | | StationThread stationThread = mock(StationThread.class); |
| | | |
| | | ReflectionTestUtils.setField(utils, "basDevpService", basDevpService); |
| | | ReflectionTestUtils.setField(utils, "wrkMastService", wrkMastService); |
| | | 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); |
| | | stationProtocol.setRunBlock(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); |
| | | |
| | | 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); |
| | | } |
| | | } |
| | | |
| | | @Test |
| | | void executePlan_runBlockReroute_skipsWhenBlockedSessionMatchesCandidatePath() { |
| | | StationOperateProcessUtils utils = new StationOperateProcessUtils(); |
| | | StationMoveCoordinator coordinator = mock(StationMoveCoordinator.class); |
| | | ReflectionTestUtils.setField(utils, "stationMoveCoordinator", coordinator); |
| | | |
| | | StationCommand command = new StationCommand(); |
| | | command.setTaskNo(100); |
| | | command.setStationId(145); |
| | | command.setTargetStaNo(111); |
| | | command.setNavigatePath(List.of(145, 113, 112, 111)); |
| | | command.setOriginalNavigatePath(List.of(145, 113, 112, 111)); |
| | | |
| | | StationMoveSession session = new StationMoveSession(); |
| | | session.setTaskNo(100); |
| | | session.setStatus(StationMoveSession.STATUS_BLOCKED); |
| | | session.setCurrentStationId(145); |
| | | session.setDispatchStationId(145); |
| | | session.setPathSignature("same-path"); |
| | | when(coordinator.loadSession(100)).thenReturn(session); |
| | | when(coordinator.buildPathSignature(command)).thenReturn("same-path"); |
| | | |
| | | StationOperateProcessUtils.RerouteContext context = StationOperateProcessUtils.RerouteContext.create( |
| | | StationOperateProcessUtils.RerouteSceneType.RUN_BLOCK_REROUTE, |
| | | buildBasDevp(1), |
| | | mock(StationThread.class), |
| | | buildStationProtocol(145, 100, 145), |
| | | buildWrkMast(100, 111), |
| | | Collections.emptyList(), |
| | | 0.0d, |
| | | "checkStationRunBlock_reroute" |
| | | ).withCancelSessionBeforeDispatch() |
| | | .withResetSegmentCommandsBeforeDispatch(); |
| | | |
| | | MessageQueue.init(SlaveType.Devp, 1); |
| | | try { |
| | | StationOperateProcessUtils.RerouteExecutionResult result = utils.executeReroutePlan( |
| | | context, |
| | | StationOperateProcessUtils.RerouteCommandPlan.dispatch( |
| | | command, |
| | | StationOperateProcessUtils.RerouteDecision.proceed(111), |
| | | "checkStationRunBlock_reroute" |
| | | ) |
| | | ); |
| | | |
| | | assertTrue(result.skipped()); |
| | | assertEquals("run-block-same-path", result.skipReason()); |
| | | verify(coordinator, never()).cancelSession(100); |
| | | } finally { |
| | | MessageQueue.clear(SlaveType.Devp, 1); |
| | | } |
| | | } |
| | | |
| | | @Test |
| | | void stationInExecute_recordsDispatchSessionAfterIssuingMoveCommand() { |
| | | StationOperateProcessUtils utils = new StationOperateProcessUtils(); |
| | | BasDevpService basDevpService = mock(BasDevpService.class); |
| | | WrkMastService wrkMastService = mock(WrkMastService.class); |
| | | CommonService commonService = mock(CommonService.class); |
| | | RedisUtil redisUtil = mock(RedisUtil.class); |
| | | WrkAnalysisService wrkAnalysisService = mock(WrkAnalysisService.class); |
| | | StationMoveCoordinator coordinator = mock(StationMoveCoordinator.class); |
| | | StationThread stationThread = mock(StationThread.class); |
| | | |
| | | ReflectionTestUtils.setField(utils, "basDevpService", basDevpService); |
| | | ReflectionTestUtils.setField(utils, "wrkMastService", wrkMastService); |
| | | ReflectionTestUtils.setField(utils, "commonService", commonService); |
| | | ReflectionTestUtils.setField(utils, "redisUtil", redisUtil); |
| | | ReflectionTestUtils.setField(utils, "wrkAnalysisService", wrkAnalysisService); |
| | | ReflectionTestUtils.setField(utils, "stationMoveCoordinator", coordinator); |
| | | |
| | | BasDevp basDevp = buildBasDevp(1); |
| | | basDevp.setBarcodeStationList("[{\"deviceNo\":1,\"stationId\":101}]"); |
| | | when(basDevpService.list(any(com.baomidou.mybatisplus.core.conditions.Wrapper.class))) |
| | | .thenReturn(Collections.singletonList(basDevp)); |
| | | |
| | | StationProtocol stationProtocol = buildStationProtocol(101, 500670, 101); |
| | | stationProtocol.setAutoing(true); |
| | | stationProtocol.setLoading(true); |
| | | stationProtocol.setBarcode("GSL110005"); |
| | | when(stationThread.getStatusMap()).thenReturn(Map.of(101, stationProtocol)); |
| | | when(stationThread.getStatus()).thenReturn(Collections.singletonList(stationProtocol)); |
| | | |
| | | WrkMast wrkMast = buildWrkMast(500670, 102); |
| | | wrkMast.setWrkSts(WrkStsType.NEW_INBOUND.sts); |
| | | wrkMast.setLocNo("8-4-1"); |
| | | when(wrkMastService.getOne(any(com.baomidou.mybatisplus.core.conditions.Wrapper.class))).thenReturn(wrkMast); |
| | | when(wrkMastService.updateById(wrkMast)).thenReturn(true); |
| | | |
| | | FindCrnNoResult findCrnNoResult = new FindCrnNoResult(); |
| | | findCrnNoResult.setCrnNo(4); |
| | | findCrnNoResult.setCrnType(SlaveType.Crn); |
| | | when(commonService.findCrnNoByLocNo("8-4-1")).thenReturn(findCrnNoResult); |
| | | when(commonService.findInStationId(findCrnNoResult, 101)).thenReturn(102); |
| | | |
| | | StationCommand command = new StationCommand(); |
| | | command.setTaskNo(500670); |
| | | command.setStationId(101); |
| | | command.setTargetStaNo(102); |
| | | when(stationThread.getCommand(com.zy.core.enums.StationCommandType.MOVE, 500670, 101, 102, 0)) |
| | | .thenReturn(command); |
| | | when(redisUtil.get(anyString())).thenReturn(null); |
| | | |
| | | MessageQueue.init(SlaveType.Devp, 1); |
| | | SlaveConnection.put(SlaveType.Devp, 1, stationThread); |
| | | try { |
| | | utils.stationInExecute(); |
| | | |
| | | verify(coordinator, times(1)).recordDispatch(eq(500670), eq(101), eq("stationInExecute"), same(command), eq(false)); |
| | | } finally { |
| | | MessageQueue.clear(SlaveType.Devp, 1); |
| | | SlaveConnection.remove(SlaveType.Devp, 1); |
| | | } |
| | | } |
| | | |
| | | @Test |
| | | void dualCrnStationOutExecute_recordsDispatchSessionAfterIssuingMoveCommand() { |
| | | StationOperateProcessUtils utils = new StationOperateProcessUtils(); |
| | | WrkMastService wrkMastService = mock(WrkMastService.class); |
| | | RedisUtil redisUtil = mock(RedisUtil.class); |
| | | NotifyUtils notifyUtils = mock(NotifyUtils.class); |
| | | StationMoveCoordinator coordinator = mock(StationMoveCoordinator.class); |
| | | StationThread stationThread = mock(StationThread.class); |
| | | |
| | | ReflectionTestUtils.setField(utils, "wrkMastService", wrkMastService); |
| | | ReflectionTestUtils.setField(utils, "redisUtil", redisUtil); |
| | | ReflectionTestUtils.setField(utils, "notifyUtils", notifyUtils); |
| | | ReflectionTestUtils.setField(utils, "stationMoveCoordinator", coordinator); |
| | | |
| | | WrkMast wrkMast = buildWrkMast(10335, 145); |
| | | wrkMast.setDualCrnNo(1); |
| | | wrkMast.setWrkSts(WrkStsType.OUTBOUND_RUN_COMPLETE.sts); |
| | | when(wrkMastService.list(any(com.baomidou.mybatisplus.core.conditions.Wrapper.class))) |
| | | .thenReturn(Collections.singletonList(wrkMast)); |
| | | when(wrkMastService.updateById(wrkMast)).thenReturn(true); |
| | | |
| | | when(redisUtil.get(anyString())).thenAnswer(invocation -> { |
| | | String key = invocation.getArgument(0); |
| | | if (Objects.equals(key, RedisKeyType.DUAL_CRN_OUT_TASK_STATION_INFO.key + 10335)) { |
| | | return "{\"deviceNo\":1,\"stationId\":198}"; |
| | | } |
| | | return null; |
| | | }); |
| | | |
| | | StationProtocol stationProtocol = buildStationProtocol(198, 0, 198); |
| | | stationProtocol.setAutoing(true); |
| | | stationProtocol.setLoading(true); |
| | | when(stationThread.getStatusMap()).thenReturn(Map.of(198, stationProtocol)); |
| | | |
| | | StationCommand command = new StationCommand(); |
| | | command.setTaskNo(10335); |
| | | command.setStationId(198); |
| | | command.setTargetStaNo(145); |
| | | when(stationThread.getCommand(eq(com.zy.core.enums.StationCommandType.MOVE), eq(10335), eq(198), eq(145), eq(0), eq(0.0d))) |
| | | .thenReturn(command); |
| | | |
| | | MessageQueue.init(SlaveType.Devp, 1); |
| | | SlaveConnection.put(SlaveType.Devp, 1, stationThread); |
| | | try { |
| | | utils.dualCrnStationOutExecute(); |
| | | |
| | | verify(coordinator, times(1)).recordDispatch(eq(10335), eq(198), eq("dualCrnStationOutExecute"), same(command), eq(false)); |
| | | } finally { |
| | | MessageQueue.clear(SlaveType.Devp, 1); |
| | | SlaveConnection.remove(SlaveType.Devp, 1); |
| | | } |
| | | } |
| | | |
| | | @Test |
| | | void watchCircleStation_usesSessionArrivalStateWhenLegacyCommandMissing() { |
| | | 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); |
| | | when(basDevpService.list(any(com.baomidou.mybatisplus.core.conditions.Wrapper.class))) |
| | | .thenReturn(Collections.singletonList(basDevp)); |
| | | |
| | | StationProtocol stationProtocol = buildStationProtocol(145, 10337, 148); |
| | | stationProtocol.setAutoing(true); |
| | | stationProtocol.setLoading(true); |
| | | when(stationThread.getStatus()).thenReturn(Collections.singletonList(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_RUNNING); |
| | | session.setDispatchMode(StationMoveDispatchMode.CIRCLE); |
| | | session.setCurrentStationId(145); |
| | | session.setDispatchStationId(145); |
| | | session.setNextDecisionStationId(145); |
| | | 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.watchCircleStation(); |
| | | |
| | | verify(stationThread, times(1)).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); |