| | |
| | | |
| | | import com.zy.asrs.entity.BasStationOpt; |
| | | import com.zy.asrs.entity.BasDevp; |
| | | import com.zy.asrs.entity.BasStation; |
| | | import com.zy.asrs.entity.WrkMast; |
| | | import com.zy.asrs.service.BasDevpService; |
| | | import com.zy.asrs.service.BasStationService; |
| | | import com.zy.asrs.service.BasStationOptService; |
| | | import com.zy.asrs.service.WrkMastService; |
| | | import com.zy.asrs.service.WrkAnalysisService; |
| | |
| | | import com.zy.core.move.StationMoveCoordinator; |
| | | import com.zy.core.move.StationMoveDispatchMode; |
| | | import com.zy.core.move.StationMoveSession; |
| | | import com.zy.core.dispatch.StationCommandDispatchResult; |
| | | import com.zy.core.dispatch.StationCommandDispatcher; |
| | | import com.zy.core.model.command.StationCommand; |
| | | import com.zy.core.model.protocol.StationProtocol; |
| | | import com.zy.core.model.protocol.StationTaskBufferItem; |
| | | import com.zy.core.thread.StationThread; |
| | | import com.zy.common.utils.RedisUtil; |
| | | import com.zy.core.utils.station.StationDispatchLoadSupport; |
| | | import com.zy.core.utils.station.StationDispatchRuntimeStateSupport; |
| | | import com.zy.core.utils.station.StationOutboundDecisionSupport; |
| | | import com.zy.core.utils.station.StationOutboundDispatchProcessor; |
| | | import com.zy.core.utils.station.StationRegularDispatchProcessor; |
| | | import com.zy.core.utils.station.StationRerouteProcessor; |
| | | import com.zy.core.utils.station.model.DispatchLimitConfig; |
| | | import com.zy.core.utils.station.model.LoadGuardState; |
| | | import com.zy.core.utils.station.model.LoopHitResult; |
| | | import com.zy.core.utils.station.model.RerouteCommandPlan; |
| | | import com.zy.core.utils.station.model.RerouteContext; |
| | | import com.zy.core.utils.station.model.RerouteDecision; |
| | | import com.zy.core.utils.station.model.RerouteExecutionResult; |
| | | import com.zy.core.utils.station.model.RerouteSceneType; |
| | | import org.junit.jupiter.api.Test; |
| | | import org.springframework.test.util.ReflectionTestUtils; |
| | | |
| | | import java.util.Date; |
| | | import java.util.Collections; |
| | | import java.util.HashMap; |
| | | import java.util.IdentityHashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.Objects; |
| | |
| | | import static org.mockito.Mockito.when; |
| | | |
| | | class StationOperateProcessUtilsReroutePipelineTest { |
| | | private final Map<StationOperateProcessUtils, Map<String, Object>> dependencyOverrides = new IdentityHashMap<>(); |
| | | |
| | | private StationOperateProcessUtils newUtils() { |
| | | StationOperateProcessUtils utils = new StationOperateProcessUtils(); |
| | | stash(utils, "stationOutboundDecisionSupport", new StationOutboundDecisionSupport()); |
| | | wireRerouteProcessor(utils); |
| | | return utils; |
| | | } |
| | | |
| | | private void wireOutboundSupport(StationOperateProcessUtils utils) { |
| | | StationOutboundDecisionSupport support = new StationOutboundDecisionSupport(); |
| | | copyIfPresent(utils, support, "wrkMastService"); |
| | | copyIfPresent(utils, support, "basDevpService"); |
| | | copyIfPresent(utils, support, "basStationService"); |
| | | copyIfPresent(utils, support, "navigateUtils"); |
| | | copyIfPresent(utils, support, "redisUtil"); |
| | | copyIfPresent(utils, support, "stationTaskLoopService"); |
| | | copyIfPresent(utils, support, "stationMoveCoordinator"); |
| | | StationDispatchRuntimeStateSupport runtimeStateSupport = new StationDispatchRuntimeStateSupport(); |
| | | copyIfPresent(utils, runtimeStateSupport, "redisUtil"); |
| | | copyIfPresent(utils, runtimeStateSupport, "basStationOptService"); |
| | | ReflectionTestUtils.setField(support, "stationDispatchRuntimeStateSupport", runtimeStateSupport); |
| | | stash(utils, "stationOutboundDecisionSupport", support); |
| | | } |
| | | |
| | | private void wireRerouteProcessor(StationOperateProcessUtils utils) { |
| | | StationRerouteProcessor processor = new StationRerouteProcessor(); |
| | | copyIfPresent(utils, processor, "basDevpService"); |
| | | copyIfPresent(utils, processor, "wrkMastService"); |
| | | copyIfPresent(utils, processor, "commonService"); |
| | | copyIfPresent(utils, processor, "redisUtil"); |
| | | copyIfPresent(utils, processor, "locMastService"); |
| | | copyIfPresent(utils, processor, "wmsOperateUtils"); |
| | | copyIfPresent(utils, processor, "basStationOptService"); |
| | | copyIfPresent(utils, processor, "stationMoveCoordinator"); |
| | | Object dispatcher = readIfPresent(utils, "stationCommandDispatcher"); |
| | | if (dispatcher == null) { |
| | | dispatcher = new StationCommandDispatcher( |
| | | (RedisUtil) readIfPresent(utils, "redisUtil"), |
| | | (StationMoveCoordinator) readIfPresent(utils, "stationMoveCoordinator") |
| | | ); |
| | | } |
| | | ReflectionTestUtils.setField(processor, "stationCommandDispatcher", dispatcher); |
| | | Object outboundSupport = readIfPresent(utils, "stationOutboundDecisionSupport"); |
| | | if (outboundSupport == null) { |
| | | wireOutboundSupport(utils); |
| | | outboundSupport = readIfPresent(utils, "stationOutboundDecisionSupport"); |
| | | } |
| | | if (outboundSupport != null) { |
| | | ReflectionTestUtils.setField(processor, "stationOutboundDecisionSupport", outboundSupport); |
| | | } |
| | | StationDispatchRuntimeStateSupport runtimeStateSupport = new StationDispatchRuntimeStateSupport(); |
| | | copyIfPresent(utils, runtimeStateSupport, "redisUtil"); |
| | | copyIfPresent(utils, runtimeStateSupport, "basStationOptService"); |
| | | ReflectionTestUtils.setField(processor, "stationDispatchRuntimeStateSupport", runtimeStateSupport); |
| | | ReflectionTestUtils.setField(utils, "stationRerouteProcessor", processor); |
| | | } |
| | | |
| | | private void stash(StationOperateProcessUtils utils, String fieldName, Object value) { |
| | | dependencyOverrides.computeIfAbsent(utils, key -> new HashMap<>()).put(fieldName, value); |
| | | } |
| | | |
| | | private Object readIfPresent(Object source, String fieldName) { |
| | | try { |
| | | return ReflectionTestUtils.getField(source, fieldName); |
| | | } catch (IllegalArgumentException ignore) { |
| | | if (source instanceof StationOperateProcessUtils) { |
| | | Map<String, Object> values = dependencyOverrides.get(source); |
| | | return values == null ? null : values.get(fieldName); |
| | | } |
| | | return null; |
| | | } |
| | | } |
| | | |
| | | private void copyIfPresent(Object source, Object target, String fieldName) { |
| | | Object value = readIfPresent(source, fieldName); |
| | | if (value != null) { |
| | | try { |
| | | ReflectionTestUtils.setField(target, fieldName, value); |
| | | } catch (IllegalArgumentException ignore) { |
| | | } |
| | | } |
| | | } |
| | | |
| | | @SuppressWarnings("unchecked") |
| | | private void stubTaskDispatchLock(StationMoveCoordinator coordinator) { |
| | |
| | | |
| | | @Test |
| | | void choosesRunBlockCommandBuilderForRunBlockRerouteScene() { |
| | | StationOperateProcessUtils.RerouteSceneType scene = |
| | | StationOperateProcessUtils.RerouteSceneType.RUN_BLOCK_REROUTE; |
| | | RerouteSceneType scene = RerouteSceneType.RUN_BLOCK_REROUTE; |
| | | |
| | | assertSame(StationOperateProcessUtils.RerouteSceneType.RUN_BLOCK_REROUTE, scene); |
| | | assertSame(RerouteSceneType.RUN_BLOCK_REROUTE, scene); |
| | | } |
| | | |
| | | @Test |
| | | void resolveExecutionTarget_skipsWhenTargetEqualsCurrentStation() { |
| | | StationOperateProcessUtils.RerouteDecision decision = |
| | | StationOperateProcessUtils.RerouteDecision.skip("same-station"); |
| | | RerouteDecision decision = RerouteDecision.skip("same-station"); |
| | | |
| | | assertTrue(decision.skip()); |
| | | assertEquals("same-station", decision.skipReason()); |
| | |
| | | |
| | | @Test |
| | | void buildCommandPlan_usesRunBlockCommandBuilderForRunBlockScene() { |
| | | StationOperateProcessUtils utils = new StationOperateProcessUtils(); |
| | | StationOperateProcessUtils utils = newUtils(); |
| | | StationThread stationThread = mock(StationThread.class); |
| | | StationCommand command = new StationCommand(); |
| | | command.setTaskNo(100); |
| | |
| | | command.setTargetStaNo(20); |
| | | when(stationThread.getRunBlockRerouteCommand(100, 10, 20, 0, 0.25d)).thenReturn(command); |
| | | |
| | | StationOperateProcessUtils.RerouteContext context = StationOperateProcessUtils.RerouteContext.create( |
| | | StationOperateProcessUtils.RerouteSceneType.RUN_BLOCK_REROUTE, |
| | | RerouteContext context = RerouteContext.create( |
| | | RerouteSceneType.RUN_BLOCK_REROUTE, |
| | | buildBasDevp(1), |
| | | stationThread, |
| | | buildStationProtocol(10, 100, 10), |
| | |
| | | .withCancelSessionBeforeDispatch() |
| | | .withResetSegmentCommandsBeforeDispatch(); |
| | | |
| | | StationOperateProcessUtils.RerouteCommandPlan plan = utils.buildRerouteCommandPlan( |
| | | RerouteCommandPlan plan = utils.buildRerouteCommandPlan( |
| | | context, |
| | | StationOperateProcessUtils.RerouteDecision.proceed(20) |
| | | RerouteDecision.proceed(20) |
| | | ); |
| | | |
| | | verify(stationThread).getRunBlockRerouteCommand(100, 10, 20, 0, 0.25d); |
| | |
| | | |
| | | @Test |
| | | void executePlan_skipsWhenCurrentTaskStillExistsInBuffer() { |
| | | StationOperateProcessUtils utils = new StationOperateProcessUtils(); |
| | | StationOperateProcessUtils utils = newUtils(); |
| | | StationCommand command = new StationCommand(); |
| | | command.setTaskNo(100); |
| | | command.setStationId(10); |
| | |
| | | StationTaskBufferItem bufferItem = new StationTaskBufferItem(); |
| | | bufferItem.setTaskNo(100); |
| | | |
| | | StationOperateProcessUtils.RerouteContext context = StationOperateProcessUtils.RerouteContext.create( |
| | | StationOperateProcessUtils.RerouteSceneType.OUT_ORDER, |
| | | RerouteContext context = RerouteContext.create( |
| | | RerouteSceneType.OUT_ORDER, |
| | | buildBasDevp(1), |
| | | mock(StationThread.class), |
| | | buildStationProtocol(10, 100, 10, Collections.singletonList(bufferItem)), |
| | |
| | | "checkStationOutOrder" |
| | | ); |
| | | |
| | | StationOperateProcessUtils.RerouteExecutionResult result = utils.executeReroutePlan( |
| | | RerouteExecutionResult result = utils.executeReroutePlan( |
| | | context, |
| | | StationOperateProcessUtils.RerouteCommandPlan.dispatch( |
| | | RerouteCommandPlan.dispatch( |
| | | command, |
| | | StationOperateProcessUtils.RerouteDecision.proceed(20), |
| | | RerouteDecision.proceed(20), |
| | | "checkStationOutOrder" |
| | | ) |
| | | ); |
| | |
| | | |
| | | @Test |
| | | void outOrderAndWatchCircle_shareDecisionFlow() { |
| | | StationOperateProcessUtils utils = new StationOperateProcessUtils(); |
| | | StationOperateProcessUtils utils = newUtils(); |
| | | WrkMast wrkMast = buildWrkMast(100, 20); |
| | | |
| | | StationOperateProcessUtils.RerouteContext outOrderContext = StationOperateProcessUtils.RerouteContext.create( |
| | | StationOperateProcessUtils.RerouteSceneType.OUT_ORDER, |
| | | RerouteContext outOrderContext = RerouteContext.create( |
| | | RerouteSceneType.OUT_ORDER, |
| | | buildBasDevp(1), |
| | | mock(StationThread.class), |
| | | buildStationProtocol(10, 100, 10), |
| | |
| | | 0.0d, |
| | | "checkStationOutOrder" |
| | | ); |
| | | StationOperateProcessUtils.RerouteContext watchCircleContext = StationOperateProcessUtils.RerouteContext.create( |
| | | StationOperateProcessUtils.RerouteSceneType.WATCH_CIRCLE, |
| | | RerouteContext watchCircleContext = RerouteContext.create( |
| | | RerouteSceneType.WATCH_CIRCLE, |
| | | buildBasDevp(1), |
| | | mock(StationThread.class), |
| | | buildStationProtocol(10, 100, 10), |
| | |
| | | "watchCircleStation" |
| | | ); |
| | | |
| | | StationOperateProcessUtils.RerouteDecision outOrderDecision = utils.resolveSharedRerouteDecision(outOrderContext); |
| | | StationOperateProcessUtils.RerouteDecision watchCircleDecision = utils.resolveSharedRerouteDecision(watchCircleContext); |
| | | RerouteDecision outOrderDecision = utils.resolveSharedRerouteDecision(outOrderContext); |
| | | RerouteDecision watchCircleDecision = utils.resolveSharedRerouteDecision(watchCircleContext); |
| | | |
| | | assertEquals(20, outOrderDecision.targetStationId()); |
| | | assertEquals(20, watchCircleDecision.targetStationId()); |
| | |
| | | |
| | | @Test |
| | | void runBlockReroute_keepsDirectReassignAndNormalRerouteSeparate() { |
| | | StationOperateProcessUtils utils = new StationOperateProcessUtils(); |
| | | StationOperateProcessUtils utils = newUtils(); |
| | | WrkMast inboundWrkMast = buildWrkMast(100, 20); |
| | | inboundWrkMast.setIoType(WrkIoType.IN.id); |
| | | |
| | |
| | | |
| | | @Test |
| | | void idleRecover_skipsWhenLastDispatchIsTooRecent() { |
| | | StationOperateProcessUtils utils = new StationOperateProcessUtils(); |
| | | StationOperateProcessUtils utils = newUtils(); |
| | | StationMoveCoordinator coordinator = mock(StationMoveCoordinator.class); |
| | | RedisUtil redisUtil = mock(RedisUtil.class); |
| | | stubTaskDispatchLock(coordinator); |
| | | ReflectionTestUtils.setField(utils, "stationMoveCoordinator", coordinator); |
| | | ReflectionTestUtils.setField(utils, "redisUtil", redisUtil); |
| | | stash(utils, "stationMoveCoordinator", coordinator); |
| | | stash(utils, "redisUtil", redisUtil); |
| | | wireRerouteProcessor(utils); |
| | | |
| | | StationMoveSession session = new StationMoveSession(); |
| | | session.setStatus(StationMoveSession.STATUS_RUNNING); |
| | |
| | | command.setStationId(10); |
| | | command.setTargetStaNo(20); |
| | | |
| | | StationOperateProcessUtils.RerouteContext context = StationOperateProcessUtils.RerouteContext.create( |
| | | StationOperateProcessUtils.RerouteSceneType.IDLE_RECOVER, |
| | | RerouteContext context = RerouteContext.create( |
| | | RerouteSceneType.IDLE_RECOVER, |
| | | buildBasDevp(1), |
| | | mock(StationThread.class), |
| | | buildStationProtocol(10, 100, 10), |
| | |
| | | "checkStationIdleRecover" |
| | | ).withRecentDispatchGuard(); |
| | | |
| | | StationOperateProcessUtils.RerouteExecutionResult result = utils.executeReroutePlan( |
| | | RerouteExecutionResult result = utils.executeReroutePlan( |
| | | context, |
| | | StationOperateProcessUtils.RerouteCommandPlan.dispatch( |
| | | RerouteCommandPlan.dispatch( |
| | | command, |
| | | StationOperateProcessUtils.RerouteDecision.proceed(20), |
| | | RerouteDecision.proceed(20), |
| | | "checkStationIdleRecover" |
| | | ) |
| | | ); |
| | |
| | | |
| | | @Test |
| | | void idleRecover_skipsWhenCurrentStationIsStillInsideRecentlyIssuedActiveRoute() { |
| | | StationOperateProcessUtils utils = new StationOperateProcessUtils(); |
| | | StationOperateProcessUtils utils = newUtils(); |
| | | StationMoveCoordinator coordinator = mock(StationMoveCoordinator.class); |
| | | RedisUtil redisUtil = mock(RedisUtil.class); |
| | | stubTaskDispatchLock(coordinator); |
| | | ReflectionTestUtils.setField(utils, "stationMoveCoordinator", coordinator); |
| | | ReflectionTestUtils.setField(utils, "redisUtil", redisUtil); |
| | | stash(utils, "stationMoveCoordinator", coordinator); |
| | | stash(utils, "redisUtil", redisUtil); |
| | | wireRerouteProcessor(utils); |
| | | |
| | | StationMoveSession session = new StationMoveSession(); |
| | | session.setStatus(StationMoveSession.STATUS_RUNNING); |
| | |
| | | command.setStationId(121); |
| | | command.setTargetStaNo(124); |
| | | |
| | | StationOperateProcessUtils.RerouteContext context = StationOperateProcessUtils.RerouteContext.create( |
| | | StationOperateProcessUtils.RerouteSceneType.IDLE_RECOVER, |
| | | RerouteContext context = RerouteContext.create( |
| | | RerouteSceneType.IDLE_RECOVER, |
| | | buildBasDevp(1), |
| | | mock(StationThread.class), |
| | | buildStationProtocol(121, 10510, 121), |
| | |
| | | "checkStationIdleRecover" |
| | | ).withRecentDispatchGuard(); |
| | | |
| | | StationOperateProcessUtils.RerouteExecutionResult result = utils.executeReroutePlan( |
| | | RerouteExecutionResult result = utils.executeReroutePlan( |
| | | context, |
| | | StationOperateProcessUtils.RerouteCommandPlan.dispatch( |
| | | RerouteCommandPlan.dispatch( |
| | | command, |
| | | StationOperateProcessUtils.RerouteDecision.proceed(124), |
| | | RerouteDecision.proceed(124), |
| | | "checkStationIdleRecover" |
| | | ) |
| | | ); |
| | |
| | | |
| | | @Test |
| | | void idleRecover_skipsWhenStationCommandLogShowsRecentIssuedMove() { |
| | | StationOperateProcessUtils utils = new StationOperateProcessUtils(); |
| | | StationOperateProcessUtils utils = newUtils(); |
| | | StationMoveCoordinator coordinator = mock(StationMoveCoordinator.class); |
| | | BasStationOptService basStationOptService = mock(BasStationOptService.class); |
| | | RedisUtil redisUtil = mock(RedisUtil.class); |
| | | stubTaskDispatchLock(coordinator); |
| | | ReflectionTestUtils.setField(utils, "stationMoveCoordinator", coordinator); |
| | | ReflectionTestUtils.setField(utils, "basStationOptService", basStationOptService); |
| | | ReflectionTestUtils.setField(utils, "redisUtil", redisUtil); |
| | | stash(utils, "stationMoveCoordinator", coordinator); |
| | | stash(utils, "basStationOptService", basStationOptService); |
| | | stash(utils, "redisUtil", redisUtil); |
| | | wireRerouteProcessor(utils); |
| | | |
| | | StationMoveSession session = new StationMoveSession(); |
| | | session.setStatus(StationMoveSession.STATUS_RUNNING); |
| | |
| | | |
| | | @Test |
| | | void checkStationOutOrder_skipsWhenActiveSessionAlreadyOwnsCurrentStation() { |
| | | StationOperateProcessUtils utils = new StationOperateProcessUtils(); |
| | | StationOperateProcessUtils utils = newUtils(); |
| | | BasDevpService basDevpService = mock(BasDevpService.class); |
| | | WrkMastService wrkMastService = mock(WrkMastService.class); |
| | | StationMoveCoordinator coordinator = mock(StationMoveCoordinator.class); |
| | |
| | | StationThread stationThread = mock(StationThread.class); |
| | | stubTaskDispatchLock(coordinator); |
| | | |
| | | ReflectionTestUtils.setField(utils, "basDevpService", basDevpService); |
| | | stash(utils, "basDevpService", basDevpService); |
| | | ReflectionTestUtils.setField(utils, "wrkMastService", wrkMastService); |
| | | ReflectionTestUtils.setField(utils, "stationMoveCoordinator", coordinator); |
| | | ReflectionTestUtils.setField(utils, "redisUtil", redisUtil); |
| | | stash(utils, "stationMoveCoordinator", coordinator); |
| | | stash(utils, "redisUtil", redisUtil); |
| | | wireOutboundSupport(utils); |
| | | wireRerouteProcessor(utils); |
| | | |
| | | BasDevp basDevp = buildBasDevp(1); |
| | | basDevp.setIsOutOrderList("[{\"deviceNo\":1,\"stationId\":145}]"); |
| | |
| | | |
| | | @Test |
| | | void checkStationOutOrder_restartsWhenBlockedSessionExistsButStationNoLongerRunBlock() { |
| | | StationOperateProcessUtils utils = new StationOperateProcessUtils(); |
| | | StationOperateProcessUtils utils = newUtils(); |
| | | BasDevpService basDevpService = mock(BasDevpService.class); |
| | | WrkMastService wrkMastService = mock(WrkMastService.class); |
| | | StationMoveCoordinator coordinator = mock(StationMoveCoordinator.class); |
| | |
| | | StationThread stationThread = mock(StationThread.class); |
| | | stubTaskDispatchLock(coordinator); |
| | | |
| | | ReflectionTestUtils.setField(utils, "basDevpService", basDevpService); |
| | | stash(utils, "basDevpService", basDevpService); |
| | | ReflectionTestUtils.setField(utils, "wrkMastService", wrkMastService); |
| | | ReflectionTestUtils.setField(utils, "stationMoveCoordinator", coordinator); |
| | | ReflectionTestUtils.setField(utils, "redisUtil", redisUtil); |
| | | stash(utils, "stationMoveCoordinator", coordinator); |
| | | stash(utils, "redisUtil", redisUtil); |
| | | wireOutboundSupport(utils); |
| | | wireRerouteProcessor(utils); |
| | | |
| | | BasDevp basDevp = buildBasDevp(1); |
| | | basDevp.setIsOutOrderList("[{\"deviceNo\":1,\"stationId\":145}]"); |
| | |
| | | |
| | | @Test |
| | | void checkStationOutOrder_skipsRunBlockStationBeforePlanning() { |
| | | StationOperateProcessUtils utils = new StationOperateProcessUtils(); |
| | | StationOperateProcessUtils utils = newUtils(); |
| | | 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); |
| | | stash(utils, "basDevpService", basDevpService); |
| | | ReflectionTestUtils.setField(utils, "wrkMastService", wrkMastService); |
| | | ReflectionTestUtils.setField(utils, "redisUtil", redisUtil); |
| | | stash(utils, "redisUtil", redisUtil); |
| | | wireOutboundSupport(utils); |
| | | wireRerouteProcessor(utils); |
| | | |
| | | BasDevp basDevp = buildBasDevp(1); |
| | | basDevp.setIsOutOrderList("[{\"deviceNo\":1,\"stationId\":145}]"); |
| | |
| | | |
| | | @Test |
| | | void executePlan_runBlockReroute_reissuesWhenBlockedSessionMatchesCandidatePath() { |
| | | StationOperateProcessUtils utils = new StationOperateProcessUtils(); |
| | | StationOperateProcessUtils utils = newUtils(); |
| | | StationMoveCoordinator coordinator = mock(StationMoveCoordinator.class); |
| | | RedisUtil redisUtil = mock(RedisUtil.class); |
| | | stubTaskDispatchLock(coordinator); |
| | | ReflectionTestUtils.setField(utils, "stationMoveCoordinator", coordinator); |
| | | ReflectionTestUtils.setField(utils, "redisUtil", redisUtil); |
| | | stash(utils, "stationMoveCoordinator", coordinator); |
| | | stash(utils, "redisUtil", redisUtil); |
| | | wireRerouteProcessor(utils); |
| | | |
| | | StationCommand command = new StationCommand(); |
| | | command.setTaskNo(100); |
| | |
| | | when(coordinator.loadSession(100)).thenReturn(session); |
| | | when(coordinator.buildPathSignature(command)).thenReturn("same-path"); |
| | | |
| | | StationOperateProcessUtils.RerouteContext context = StationOperateProcessUtils.RerouteContext.create( |
| | | StationOperateProcessUtils.RerouteSceneType.RUN_BLOCK_REROUTE, |
| | | RerouteContext context = RerouteContext.create( |
| | | RerouteSceneType.RUN_BLOCK_REROUTE, |
| | | buildBasDevp(1), |
| | | mock(StationThread.class), |
| | | buildStationProtocol(145, 100, 145), |
| | |
| | | |
| | | MessageQueue.init(SlaveType.Devp, 1); |
| | | try { |
| | | StationOperateProcessUtils.RerouteExecutionResult result = utils.executeReroutePlan( |
| | | RerouteExecutionResult result = utils.executeReroutePlan( |
| | | context, |
| | | StationOperateProcessUtils.RerouteCommandPlan.dispatch( |
| | | RerouteCommandPlan.dispatch( |
| | | command, |
| | | StationOperateProcessUtils.RerouteDecision.proceed(111), |
| | | RerouteDecision.proceed(111), |
| | | "checkStationRunBlock_reroute" |
| | | ) |
| | | ); |
| | |
| | | |
| | | @Test |
| | | void executePlan_runBlockReroute_ignoresCurrentTaskBufferAfterReset() { |
| | | StationOperateProcessUtils utils = new StationOperateProcessUtils(); |
| | | StationOperateProcessUtils utils = newUtils(); |
| | | StationMoveCoordinator coordinator = mock(StationMoveCoordinator.class); |
| | | RedisUtil redisUtil = mock(RedisUtil.class); |
| | | stubTaskDispatchLock(coordinator); |
| | | ReflectionTestUtils.setField(utils, "stationMoveCoordinator", coordinator); |
| | | ReflectionTestUtils.setField(utils, "redisUtil", redisUtil); |
| | | stash(utils, "stationMoveCoordinator", coordinator); |
| | | stash(utils, "redisUtil", redisUtil); |
| | | wireRerouteProcessor(utils); |
| | | |
| | | StationCommand command = new StationCommand(); |
| | | command.setTaskNo(10388); |
| | |
| | | |
| | | when(redisUtil.get(anyString())).thenReturn(null); |
| | | |
| | | StationOperateProcessUtils.RerouteContext context = StationOperateProcessUtils.RerouteContext.create( |
| | | StationOperateProcessUtils.RerouteSceneType.RUN_BLOCK_REROUTE, |
| | | RerouteContext context = RerouteContext.create( |
| | | RerouteSceneType.RUN_BLOCK_REROUTE, |
| | | buildBasDevp(1), |
| | | mock(StationThread.class), |
| | | buildStationProtocol(186, 10388, 189, Collections.singletonList(bufferItem)), |
| | |
| | | |
| | | MessageQueue.init(SlaveType.Devp, 1); |
| | | try { |
| | | StationOperateProcessUtils.RerouteExecutionResult result = utils.executeReroutePlan( |
| | | RerouteExecutionResult result = utils.executeReroutePlan( |
| | | context, |
| | | StationOperateProcessUtils.RerouteCommandPlan.dispatch( |
| | | RerouteCommandPlan.dispatch( |
| | | command, |
| | | StationOperateProcessUtils.RerouteDecision.proceed(124), |
| | | RerouteDecision.proceed(124), |
| | | "checkStationRunBlock_reroute" |
| | | ) |
| | | ); |
| | |
| | | |
| | | @Test |
| | | void executePlan_runBlockReroute_bypassesSuppressDispatchAfterReset() { |
| | | StationOperateProcessUtils utils = new StationOperateProcessUtils(); |
| | | StationOperateProcessUtils utils = newUtils(); |
| | | StationMoveCoordinator coordinator = mock(StationMoveCoordinator.class); |
| | | RedisUtil redisUtil = mock(RedisUtil.class); |
| | | stubTaskDispatchLock(coordinator); |
| | | ReflectionTestUtils.setField(utils, "stationMoveCoordinator", coordinator); |
| | | ReflectionTestUtils.setField(utils, "redisUtil", redisUtil); |
| | | stash(utils, "stationMoveCoordinator", coordinator); |
| | | stash(utils, "redisUtil", redisUtil); |
| | | wireRerouteProcessor(utils); |
| | | |
| | | StationCommand command = new StationCommand(); |
| | | command.setTaskNo(10388); |
| | |
| | | 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, |
| | | RerouteContext context = RerouteContext.create( |
| | | RerouteSceneType.RUN_BLOCK_REROUTE, |
| | | buildBasDevp(1), |
| | | mock(StationThread.class), |
| | | buildStationProtocol(186, 10388, 186), |
| | |
| | | |
| | | MessageQueue.init(SlaveType.Devp, 1); |
| | | try { |
| | | StationOperateProcessUtils.RerouteExecutionResult result = utils.executeReroutePlan( |
| | | RerouteExecutionResult result = utils.executeReroutePlan( |
| | | context, |
| | | StationOperateProcessUtils.RerouteCommandPlan.dispatch( |
| | | RerouteCommandPlan.dispatch( |
| | | command, |
| | | StationOperateProcessUtils.RerouteDecision.proceed(124), |
| | | RerouteDecision.proceed(124), |
| | | "checkStationRunBlock_reroute" |
| | | ) |
| | | ); |
| | |
| | | |
| | | @Test |
| | | void stationInExecute_recordsDispatchSessionAfterIssuingMoveCommand() { |
| | | StationOperateProcessUtils utils = new StationOperateProcessUtils(); |
| | | StationOperateProcessUtils utils = newUtils(); |
| | | 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); |
| | | StationCommandDispatcher dispatcher = mock(StationCommandDispatcher.class); |
| | | StationDispatchLoadSupport loadSupport = mock(StationDispatchLoadSupport.class); |
| | | StationThread stationThread = mock(StationThread.class); |
| | | stubTaskDispatchLock(coordinator); |
| | | |
| | | 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); |
| | | StationRegularDispatchProcessor processor = new StationRegularDispatchProcessor(); |
| | | ReflectionTestUtils.setField(processor, "basDevpService", basDevpService); |
| | | ReflectionTestUtils.setField(processor, "wrkMastService", wrkMastService); |
| | | ReflectionTestUtils.setField(processor, "commonService", commonService); |
| | | ReflectionTestUtils.setField(processor, "redisUtil", redisUtil); |
| | | ReflectionTestUtils.setField(processor, "wrkAnalysisService", wrkAnalysisService); |
| | | ReflectionTestUtils.setField(processor, "stationMoveCoordinator", coordinator); |
| | | ReflectionTestUtils.setField(processor, "stationCommandDispatcher", dispatcher); |
| | | ReflectionTestUtils.setField(processor, "stationDispatchLoadSupport", loadSupport); |
| | | ReflectionTestUtils.setField(utils, "stationRegularDispatchProcessor", processor); |
| | | |
| | | BasDevp basDevp = buildBasDevp(1); |
| | | basDevp.setBarcodeStationList("[{\"deviceNo\":1,\"stationId\":101}]"); |
| | |
| | | when(stationThread.getCommand(com.zy.core.enums.StationCommandType.MOVE, 500670, 101, 102, 0)) |
| | | .thenReturn(command); |
| | | when(redisUtil.get(anyString())).thenReturn(null); |
| | | when(dispatcher.dispatch(1, command, "station-operate-process", "stationInExecute")) |
| | | .thenReturn(StationCommandDispatchResult.accepted("accepted", 1, "station-operate-process", "stationInExecute")); |
| | | |
| | | DispatchLimitConfig baseConfig = new DispatchLimitConfig(); |
| | | LoadGuardState loadGuardState = new LoadGuardState(); |
| | | LoopHitResult noHit = LoopHitResult.noHit(); |
| | | when(loadSupport.getDispatchLimitConfig(null, null)).thenReturn(baseConfig); |
| | | when(loadSupport.countCurrentStationTask()).thenReturn(0); |
| | | when(loadSupport.buildLoadGuardState(baseConfig)).thenReturn(loadGuardState); |
| | | when(loadSupport.getDispatchLimitConfig(101, 102)).thenReturn(baseConfig); |
| | | when(loadSupport.findPathLoopHit(baseConfig, 101, 102, loadGuardState)).thenReturn(noHit); |
| | | when(loadSupport.isDispatchBlocked(baseConfig, 0, loadGuardState, false)).thenReturn(false); |
| | | |
| | | MessageQueue.init(SlaveType.Devp, 1); |
| | | SlaveConnection.put(SlaveType.Devp, 1, stationThread); |
| | |
| | | } |
| | | |
| | | @Test |
| | | void dualCrnStationOutExecute_recordsDispatchSessionAfterIssuingMoveCommand() { |
| | | StationOperateProcessUtils utils = new StationOperateProcessUtils(); |
| | | void dualCrnStationOutExecute_delegatesToOutboundProcessor() { |
| | | StationOperateProcessUtils utils = newUtils(); |
| | | StationOutboundDispatchProcessor processor = mock(StationOutboundDispatchProcessor.class); |
| | | ReflectionTestUtils.setField(utils, "stationOutboundDispatchProcessor", processor); |
| | | |
| | | utils.dualCrnStationOutExecute(); |
| | | |
| | | verify(processor, times(1)).dualCrnStationOutExecute(); |
| | | } |
| | | |
| | | @Test |
| | | void stationOutExecuteFinish_attemptsClearPathBeforeCompletingTask() { |
| | | StationOperateProcessUtils utils = newUtils(); |
| | | WrkMastService wrkMastService = mock(WrkMastService.class); |
| | | RedisUtil redisUtil = mock(RedisUtil.class); |
| | | BasStationService basStationService = mock(BasStationService.class); |
| | | WrkAnalysisService wrkAnalysisService = mock(WrkAnalysisService.class); |
| | | NotifyUtils notifyUtils = mock(NotifyUtils.class); |
| | | RedisUtil redisUtil = mock(RedisUtil.class); |
| | | StationMoveCoordinator coordinator = mock(StationMoveCoordinator.class); |
| | | StationThread stationThread = mock(StationThread.class); |
| | | stubTaskDispatchLock(coordinator); |
| | | |
| | | ReflectionTestUtils.setField(utils, "wrkMastService", wrkMastService); |
| | | ReflectionTestUtils.setField(utils, "redisUtil", redisUtil); |
| | | ReflectionTestUtils.setField(utils, "notifyUtils", notifyUtils); |
| | | ReflectionTestUtils.setField(utils, "stationMoveCoordinator", coordinator); |
| | | StationRegularDispatchProcessor processor = new StationRegularDispatchProcessor(); |
| | | ReflectionTestUtils.setField(processor, "wrkMastService", wrkMastService); |
| | | ReflectionTestUtils.setField(processor, "basStationService", basStationService); |
| | | ReflectionTestUtils.setField(processor, "wrkAnalysisService", wrkAnalysisService); |
| | | ReflectionTestUtils.setField(processor, "notifyUtils", notifyUtils); |
| | | ReflectionTestUtils.setField(processor, "redisUtil", redisUtil); |
| | | ReflectionTestUtils.setField(processor, "stationMoveCoordinator", coordinator); |
| | | ReflectionTestUtils.setField(utils, "stationRegularDispatchProcessor", processor); |
| | | |
| | | WrkMast wrkMast = buildWrkMast(10335, 145); |
| | | wrkMast.setDualCrnNo(1); |
| | | wrkMast.setWrkSts(WrkStsType.OUTBOUND_RUN_COMPLETE.sts); |
| | | wrkMast.setWrkSts(WrkStsType.STATION_RUN.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; |
| | | }); |
| | | BasStation basStation = new BasStation(); |
| | | basStation.setStationId(145); |
| | | basStation.setDeviceNo(1); |
| | | when(basStationService.getOne(any(com.baomidou.mybatisplus.core.conditions.Wrapper.class))) |
| | | .thenReturn(basStation); |
| | | |
| | | StationProtocol stationProtocol = buildStationProtocol(198, 0, 198); |
| | | stationProtocol.setAutoing(true); |
| | | stationProtocol.setLoading(true); |
| | | when(stationThread.getStatusMap()).thenReturn(Map.of(198, stationProtocol)); |
| | | StationProtocol stationProtocol = buildStationProtocol(145, 10335, 145); |
| | | when(stationThread.getStatusMap()).thenReturn(Map.of(145, stationProtocol)); |
| | | when(stationThread.clearPath(10335)).thenReturn(true); |
| | | |
| | | 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(); |
| | | utils.stationOutExecuteFinish(); |
| | | |
| | | verify(coordinator, times(1)).recordDispatch(eq(10335), eq(198), eq("dualCrnStationOutExecute"), same(command), eq(false)); |
| | | verify(stationThread, times(1)).clearPath(10335); |
| | | verify(coordinator, times(1)).finishSession(10335); |
| | | verify(wrkMastService, times(1)).updateById(wrkMast); |
| | | assertEquals(WrkStsType.STATION_RUN_COMPLETE.sts, wrkMast.getWrkSts()); |
| | | } finally { |
| | | MessageQueue.clear(SlaveType.Devp, 1); |
| | | SlaveConnection.remove(SlaveType.Devp, 1); |
| | | } |
| | | } |
| | | |
| | | @Test |
| | | void watchCircleStation_usesSessionArrivalStateWhenLegacyCommandMissing() { |
| | | StationOperateProcessUtils utils = new StationOperateProcessUtils(); |
| | | StationOperateProcessUtils utils = newUtils(); |
| | | BasDevpService basDevpService = mock(BasDevpService.class); |
| | | WrkMastService wrkMastService = mock(WrkMastService.class); |
| | | StationMoveCoordinator coordinator = mock(StationMoveCoordinator.class); |
| | |
| | | StationThread stationThread = mock(StationThread.class); |
| | | stubTaskDispatchLock(coordinator); |
| | | |
| | | ReflectionTestUtils.setField(utils, "basDevpService", basDevpService); |
| | | stash(utils, "basDevpService", basDevpService); |
| | | ReflectionTestUtils.setField(utils, "wrkMastService", wrkMastService); |
| | | ReflectionTestUtils.setField(utils, "stationMoveCoordinator", coordinator); |
| | | ReflectionTestUtils.setField(utils, "redisUtil", redisUtil); |
| | | stash(utils, "stationMoveCoordinator", coordinator); |
| | | stash(utils, "redisUtil", redisUtil); |
| | | wireOutboundSupport(utils); |
| | | wireRerouteProcessor(utils); |
| | | |
| | | BasDevp basDevp = buildBasDevp(1); |
| | | when(basDevpService.list(any(com.baomidou.mybatisplus.core.conditions.Wrapper.class))) |