| | |
| | | |
| | | import com.zy.asrs.entity.BasDevp; |
| | | import com.zy.asrs.entity.WrkMast; |
| | | import com.zy.core.enums.WrkIoType; |
| | | import com.zy.core.move.StationMoveCoordinator; |
| | | import com.zy.core.move.StationMoveSession; |
| | | 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 org.junit.jupiter.api.Test; |
| | | import org.springframework.test.util.ReflectionTestUtils; |
| | | |
| | | import java.util.Collections; |
| | | import java.util.List; |
| | |
| | | import static org.junit.jupiter.api.Assertions.assertSame; |
| | | import static org.junit.jupiter.api.Assertions.assertTrue; |
| | | import static org.mockito.Mockito.mock; |
| | | import static org.mockito.Mockito.never; |
| | | import static org.mockito.Mockito.verify; |
| | | import static org.mockito.Mockito.when; |
| | | |
| | |
| | | assertEquals(20, watchCircleDecision.targetStationId()); |
| | | } |
| | | |
| | | @Test |
| | | void runBlockReroute_keepsDirectReassignAndNormalRerouteSeparate() { |
| | | StationOperateProcessUtils utils = new StationOperateProcessUtils(); |
| | | WrkMast inboundWrkMast = buildWrkMast(100, 20); |
| | | inboundWrkMast.setIoType(WrkIoType.IN.id); |
| | | |
| | | assertTrue(utils.shouldUseRunBlockDirectReassign(inboundWrkMast, 10, List.of(10))); |
| | | assertTrue(!utils.shouldUseRunBlockDirectReassign(inboundWrkMast, 11, List.of(10))); |
| | | } |
| | | |
| | | @Test |
| | | void idleRecover_skipsWhenLastDispatchIsTooRecent() { |
| | | 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.setCurrentStationId(10); |
| | | session.setDispatchStationId(10); |
| | | session.setLastIssuedAt(System.currentTimeMillis()); |
| | | when(coordinator.loadSession(100)).thenReturn(session); |
| | | |
| | | StationCommand command = new StationCommand(); |
| | | command.setTaskNo(100); |
| | | command.setStationId(10); |
| | | command.setTargetStaNo(20); |
| | | |
| | | StationOperateProcessUtils.RerouteContext context = StationOperateProcessUtils.RerouteContext.create( |
| | | StationOperateProcessUtils.RerouteSceneType.IDLE_RECOVER, |
| | | buildBasDevp(1), |
| | | mock(StationThread.class), |
| | | buildStationProtocol(10, 100, 10), |
| | | buildWrkMast(100, 20), |
| | | Collections.emptyList(), |
| | | 0.0d, |
| | | "checkStationIdleRecover" |
| | | ).withRecentDispatchGuard(); |
| | | |
| | | StationOperateProcessUtils.RerouteExecutionResult result = utils.executeReroutePlan( |
| | | context, |
| | | StationOperateProcessUtils.RerouteCommandPlan.dispatch( |
| | | command, |
| | | StationOperateProcessUtils.RerouteDecision.proceed(20), |
| | | "checkStationIdleRecover" |
| | | ) |
| | | ); |
| | | |
| | | assertTrue(result.skipped()); |
| | | assertEquals("recent-dispatch", result.skipReason()); |
| | | verify(coordinator, never()).cancelSession(100); |
| | | } |
| | | |
| | | private static BasDevp buildBasDevp(int devpNo) { |
| | | BasDevp basDevp = new BasDevp(); |
| | | basDevp.setDevpNo(devpNo); |