#
Junjie
20 小时以前 30ec656c41cbf3e552cfad409fe5b7e2c1f99ee6
src/test/java/com/zy/core/utils/StationOperateProcessUtilsReroutePipelineTest.java
@@ -219,7 +219,7 @@
    }
    @Test
    void checkStationOutOrder_skipsWhenBlockedSessionAlreadyOwnsCurrentStation() {
    void checkStationOutOrder_skipsWhenActiveSessionAlreadyOwnsCurrentStation() {
        StationOperateProcessUtils utils = new StationOperateProcessUtils();
        BasDevpService basDevpService = mock(BasDevpService.class);
        WrkMastService wrkMastService = mock(WrkMastService.class);
@@ -256,7 +256,7 @@
        StationMoveSession session = new StationMoveSession();
        session.setTaskNo(10337);
        session.setStatus(StationMoveSession.STATUS_BLOCKED);
        session.setStatus(StationMoveSession.STATUS_RUNNING);
        session.setDispatchMode(StationMoveDispatchMode.CIRCLE);
        session.setCurrentStationId(145);
        session.setCurrentRouteTargetStationId(148);
@@ -273,6 +273,68 @@
            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 checkStationOutOrder_restartsWhenBlockedSessionExistsButStationNoLongerRunBlock() {
        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);
        stationProtocol.setRunBlock(false);
        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();
            assertTrue(MessageQueue.peek(SlaveType.Devp, 1) != null);
            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);
@@ -330,7 +392,7 @@
    }
    @Test
    void executePlan_runBlockReroute_skipsWhenBlockedSessionMatchesCandidatePath() {
    void executePlan_runBlockReroute_reissuesWhenBlockedSessionMatchesCandidatePath() {
        StationOperateProcessUtils utils = new StationOperateProcessUtils();
        StationMoveCoordinator coordinator = mock(StationMoveCoordinator.class);
        ReflectionTestUtils.setField(utils, "stationMoveCoordinator", coordinator);
@@ -374,9 +436,8 @@
                    )
            );
            assertTrue(result.skipped());
            assertEquals("run-block-same-path", result.skipReason());
            verify(coordinator, never()).cancelSession(100);
            assertTrue(!result.skipped());
            verify(coordinator, times(1)).cancelSession(100);
        } finally {
            MessageQueue.clear(SlaveType.Devp, 1);
        }