From 7272158c8e133afcdf752ca09a70c0bd969d7393 Mon Sep 17 00:00:00 2001
From: Junjie <fallin.jie@qq.com>
Date: 星期三, 25 三月 2026 19:57:26 +0800
Subject: [PATCH] #
---
src/test/java/com/zy/core/utils/StationOperateProcessUtilsReroutePipelineTest.java | 172 +++++++++++++++++++++++++++++++++++++++++++++++++++++++--
1 files changed, 166 insertions(+), 6 deletions(-)
diff --git a/src/test/java/com/zy/core/utils/StationOperateProcessUtilsReroutePipelineTest.java b/src/test/java/com/zy/core/utils/StationOperateProcessUtilsReroutePipelineTest.java
index bb0740b..c67961e 100644
--- a/src/test/java/com/zy/core/utils/StationOperateProcessUtilsReroutePipelineTest.java
+++ b/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,107 @@
)
);
- 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);
+ }
+ }
+
+ @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);
}
--
Gitblit v1.9.1