#
Junjie
9 小时以前 c924d633253a13e01fac86e9fbcffbb7e334e257
src/test/java/com/zy/core/utils/StationOperateProcessUtilsReroutePipelineTest.java
@@ -219,6 +219,52 @@
    }
    @Test
    void idleRecover_skipsWhenCurrentStationIsStillInsideRecentlyIssuedActiveRoute() {
        StationOperateProcessUtils utils = new StationOperateProcessUtils();
        StationMoveCoordinator coordinator = mock(StationMoveCoordinator.class);
        RedisUtil redisUtil = mock(RedisUtil.class);
        ReflectionTestUtils.setField(utils, "stationMoveCoordinator", coordinator);
        ReflectionTestUtils.setField(utils, "redisUtil", redisUtil);
        StationMoveSession session = new StationMoveSession();
        session.setStatus(StationMoveSession.STATUS_RUNNING);
        session.setDispatchStationId(196);
        session.setCurrentStationId(189);
        session.setFullPathStationIds(List.of(196, 195, 189, 121, 124));
        session.setLastIssuedAt(System.currentTimeMillis());
        when(coordinator.loadSession(10510)).thenReturn(session);
        StationCommand command = new StationCommand();
        command.setTaskNo(10510);
        command.setStationId(121);
        command.setTargetStaNo(124);
        StationOperateProcessUtils.RerouteContext context = StationOperateProcessUtils.RerouteContext.create(
                StationOperateProcessUtils.RerouteSceneType.IDLE_RECOVER,
                buildBasDevp(1),
                mock(StationThread.class),
                buildStationProtocol(121, 10510, 121),
                buildWrkMast(10510, 124),
                Collections.emptyList(),
                0.0d,
                "checkStationIdleRecover"
        ).withRecentDispatchGuard();
        StationOperateProcessUtils.RerouteExecutionResult result = utils.executeReroutePlan(
                context,
                StationOperateProcessUtils.RerouteCommandPlan.dispatch(
                        command,
                        StationOperateProcessUtils.RerouteDecision.proceed(124),
                        "checkStationIdleRecover"
                )
        );
        assertTrue(result.skipped());
        assertEquals("recent-dispatch", result.skipReason());
        verify(coordinator, never()).cancelSession(10510);
    }
    @Test
    void checkStationOutOrder_skipsWhenActiveSessionAlreadyOwnsCurrentStation() {
        StationOperateProcessUtils utils = new StationOperateProcessUtils();
        BasDevpService basDevpService = mock(BasDevpService.class);
@@ -444,6 +490,105 @@
    }
    @Test
    void executePlan_runBlockReroute_ignoresCurrentTaskBufferAfterReset() {
        StationOperateProcessUtils utils = new StationOperateProcessUtils();
        StationMoveCoordinator coordinator = mock(StationMoveCoordinator.class);
        RedisUtil redisUtil = mock(RedisUtil.class);
        ReflectionTestUtils.setField(utils, "stationMoveCoordinator", coordinator);
        ReflectionTestUtils.setField(utils, "redisUtil", redisUtil);
        StationCommand command = new StationCommand();
        command.setTaskNo(10388);
        command.setStationId(186);
        command.setTargetStaNo(124);
        command.setNavigatePath(List.of(186, 189, 121, 124));
        command.setOriginalNavigatePath(List.of(186, 189, 121, 124));
        StationTaskBufferItem bufferItem = new StationTaskBufferItem();
        bufferItem.setTaskNo(10388);
        when(redisUtil.get(anyString())).thenReturn(null);
        StationOperateProcessUtils.RerouteContext context = StationOperateProcessUtils.RerouteContext.create(
                StationOperateProcessUtils.RerouteSceneType.RUN_BLOCK_REROUTE,
                buildBasDevp(1),
                mock(StationThread.class),
                buildStationProtocol(186, 10388, 189, Collections.singletonList(bufferItem)),
                buildWrkMast(10388, 124),
                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(124),
                            "checkStationRunBlock_reroute"
                    )
            );
            assertTrue(!result.skipped());
            verify(coordinator, times(1)).cancelSession(10388);
        } finally {
            MessageQueue.clear(SlaveType.Devp, 1);
        }
    }
    @Test
    void executePlan_runBlockReroute_bypassesSuppressDispatchAfterReset() {
        StationOperateProcessUtils utils = new StationOperateProcessUtils();
        StationMoveCoordinator coordinator = mock(StationMoveCoordinator.class);
        RedisUtil redisUtil = mock(RedisUtil.class);
        ReflectionTestUtils.setField(utils, "stationMoveCoordinator", coordinator);
        ReflectionTestUtils.setField(utils, "redisUtil", redisUtil);
        StationCommand command = new StationCommand();
        command.setTaskNo(10388);
        command.setStationId(186);
        command.setTargetStaNo(124);
        command.setNavigatePath(List.of(186, 124));
        command.setOriginalNavigatePath(List.of(186, 124));
        when(redisUtil.get(anyString())).thenReturn(null);
        when(coordinator.shouldSuppressDispatch(10388, 186, command)).thenReturn(true);
        StationOperateProcessUtils.RerouteContext context = StationOperateProcessUtils.RerouteContext.create(
                StationOperateProcessUtils.RerouteSceneType.RUN_BLOCK_REROUTE,
                buildBasDevp(1),
                mock(StationThread.class),
                buildStationProtocol(186, 10388, 186),
                buildWrkMast(10388, 124),
                Collections.emptyList(),
                0.0d,
                "checkStationRunBlock_reroute"
        ).withSuppressDispatchGuard()
                .withCancelSessionBeforeDispatch()
                .withResetSegmentCommandsBeforeDispatch();
        MessageQueue.init(SlaveType.Devp, 1);
        try {
            StationOperateProcessUtils.RerouteExecutionResult result = utils.executeReroutePlan(
                    context,
                    StationOperateProcessUtils.RerouteCommandPlan.dispatch(
                            command,
                            StationOperateProcessUtils.RerouteDecision.proceed(124),
                            "checkStationRunBlock_reroute"
                    )
            );
            assertTrue(!result.skipped());
            verify(coordinator, times(1)).cancelSession(10388);
        } finally {
            MessageQueue.clear(SlaveType.Devp, 1);
        }
    }
    @Test
    void stationInExecute_recordsDispatchSessionAfterIssuingMoveCommand() {
        StationOperateProcessUtils utils = new StationOperateProcessUtils();
        BasDevpService basDevpService = mock(BasDevpService.class);