From 9c5b9144ed8ed3190a21c4cb66b80e1ed9b7c954 Mon Sep 17 00:00:00 2001
From: Junjie <fallin.jie@qq.com>
Date: 星期五, 03 四月 2026 15:19:06 +0800
Subject: [PATCH] #预调度优化
---
/dev/null | 49 ------------
src/main/java/com/zy/core/utils/CrnOperateProcessUtils.java | 140 +++++++++++-----------------------
2 files changed, 47 insertions(+), 142 deletions(-)
diff --git a/src/main/java/com/zy/core/utils/CrnOperateProcessUtils.java b/src/main/java/com/zy/core/utils/CrnOperateProcessUtils.java
index 9a230d8..4be2698 100644
--- a/src/main/java/com/zy/core/utils/CrnOperateProcessUtils.java
+++ b/src/main/java/com/zy/core/utils/CrnOperateProcessUtils.java
@@ -77,14 +77,13 @@
private static final String CRN_OUT_REQUIRE_STATION_OUT_ENABLE_CONFIG = "crnOutRequireStationOutEnable";
public synchronized void crnIoExecute() {
- Set<Integer> crnMoveBlockedCrnNos = executeCrnMoveTask();
List<BasCrnp> basCrnps = basCrnpService.list(new QueryWrapper<>());
for (BasCrnp basCrnp : basCrnps) {
- crnIoExecute(basCrnp, crnMoveBlockedCrnNos);
+ crnIoExecute(basCrnp);
}
}
- public void crnIoExecute(BasCrnp basCrnp, Set<Integer> crnMoveBlockedCrnNos) {
+ public void crnIoExecute(BasCrnp basCrnp) {
if (basCrnp == null || basCrnp.getCrnNo() == null) {
return;
}
@@ -92,16 +91,16 @@
if (systemConfigMapObj != null) {
HashMap<String, String> systemConfigMap = (HashMap<String, String>) systemConfigMapObj;
if (systemConfigMap.get("crnRunMethod").equals("solver")) {
- plannerExecute(basCrnp, crnMoveBlockedCrnNos);
+ plannerExecute(basCrnp);
}else {
- crnIoExecuteNormal(basCrnp, crnMoveBlockedCrnNos);
+ crnIoExecuteNormal(basCrnp);
}
}
}
//鍏ュ嚭搴� ===>> 鍫嗗灈鏈哄叆鍑哄簱浣滀笟涓嬪彂
- private void crnIoExecuteNormal(BasCrnp currentCrn, Set<Integer> crnMoveBlockedCrnNos) {
- if (currentCrn == null || currentCrn.getCrnNo() == null || crnMoveBlockedCrnNos.contains(currentCrn.getCrnNo())) {
+ private void crnIoExecuteNormal(BasCrnp currentCrn) {
+ if (currentCrn == null || currentCrn.getCrnNo() == null) {
return;
}
@@ -118,7 +117,12 @@
long runningCount = wrkMastService.count(new QueryWrapper<WrkMast>()
.eq("crn_no", crnNo)
- .in("wrk_sts", WrkStsType.INBOUND_RUN.sts, WrkStsType.OUTBOUND_RUN.sts, WrkStsType.LOC_MOVE_RUN.sts, WrkStsType.CRN_MOVE_RUN.sts));
+ .in("wrk_sts",
+ WrkStsType.INBOUND_RUN.sts
+ , WrkStsType.OUTBOUND_RUN.sts
+ , WrkStsType.LOC_MOVE_RUN.sts
+ , WrkStsType.CRN_MOVE_RUN.sts
+ ));
if (runningCount > 0) {
return;
}
@@ -135,6 +139,12 @@
Object clearLock = redisUtil.get(RedisKeyType.CLEAR_CRN_TASK_LIMIT.key + crnNo);
if (clearLock != null) {
+ return;
+ }
+
+ //鎵ц绉诲姩浠诲姟
+ boolean executed = executeCrnMoveTask(crnThread, crnProtocol);
+ if (executed) {
return;
}
@@ -745,16 +755,15 @@
}
public synchronized void plannerExecute() {
- Set<Integer> crnMoveBlockedCrnNos = executeCrnMoveTask();
List<BasCrnp> basCrnps = basCrnpService.list(new QueryWrapper<>());
for (BasCrnp basCrnp : basCrnps) {
- plannerExecute(basCrnp, crnMoveBlockedCrnNos);
+ plannerExecute(basCrnp);
}
}
- private void plannerExecute(BasCrnp basCrnp, Set<Integer> crnMoveBlockedCrnNos) {
+ private void plannerExecute(BasCrnp basCrnp) {
int nowSec = (int) (System.currentTimeMillis() / 1000);
- if (basCrnp == null || basCrnp.getCrnNo() == null || crnMoveBlockedCrnNos.contains(basCrnp.getCrnNo())) {
+ if (basCrnp == null || basCrnp.getCrnNo() == null) {
return;
}
String key = RedisKeyType.PLANNER_SCHEDULE.key + "CRN-" + basCrnp.getCrnNo();
@@ -903,76 +912,20 @@
return false;
}
- private Set<Integer> executeCrnMoveTask() {
- List<WrkMast> pendingTaskQueue = wrkMastService.list(new QueryWrapper<WrkMast>()
- .eq("io_type", WrkIoType.CRN_MOVE.id)
- .eq("wrk_sts", WrkStsType.NEW_CRN_MOVE.sts)
- .orderByAsc("appe_time")
- .orderByAsc("wrk_no"));
- Set<Integer> blockedCrnNoSet = new HashSet<>();
- for (WrkMast wrkMast : pendingTaskQueue) {
- if (wrkMast != null && wrkMast.getCrnNo() != null) {
- blockedCrnNoSet.add(wrkMast.getCrnNo());
- }
- }
- if (blockedCrnNoSet.isEmpty()) {
- return blockedCrnNoSet;
- }
-
- List<BasCrnp> basCrnps = basCrnpService.list(new QueryWrapper<>());
- Map<Integer, CrnThread> dispatchThreadMap = new HashMap<>();
- Map<Integer, CrnProtocol> dispatchProtocolMap = new HashMap<>();
- for (BasCrnp basCrnp : basCrnps) {
- if (basCrnp == null || basCrnp.getCrnNo() == null) {
- continue;
- }
-
- Integer crnNo = basCrnp.getCrnNo();
- CrnThread crnThread = (CrnThread) SlaveConnection.get(SlaveType.Crn, crnNo);
- if (crnThread == null) {
- continue;
- }
-
- CrnProtocol crnProtocol = crnThread.getStatus();
- if (crnProtocol == null) {
- continue;
- }
-
- long runningCount = wrkMastService.count(new QueryWrapper<WrkMast>()
- .eq("crn_no", crnNo)
- .in("wrk_sts",
- WrkStsType.INBOUND_RUN.sts,
- WrkStsType.OUTBOUND_RUN.sts,
- WrkStsType.LOC_MOVE_RUN.sts,
- WrkStsType.CRN_MOVE_RUN.sts));
- if (runningCount > 0) {
- continue;
- }
-
- if (!Objects.equals(crnProtocol.getMode(), CrnModeType.AUTO.id)
- || !Objects.equals(crnProtocol.getTaskNo(), 0)
- || !Objects.equals(crnProtocol.getStatus(), CrnStatusType.IDLE.id)
- || !Objects.equals(crnProtocol.getLoaded(), 0)
- || !Objects.equals(crnProtocol.getForkPos(), 0)
- || !Objects.equals(crnProtocol.getAlarm(), 0)) {
- continue;
- }
-
- Object clearLock = redisUtil.get(RedisKeyType.CLEAR_CRN_TASK_LIMIT.key + crnNo);
- if (clearLock != null) {
- continue;
- }
-
- dispatchThreadMap.put(crnNo, crnThread);
- dispatchProtocolMap.put(crnNo, crnProtocol);
- }
-
- if (dispatchThreadMap.isEmpty()) {
- return blockedCrnNoSet;
+ private boolean executeCrnMoveTask(CrnThread crnThread, CrnProtocol crnProtocol) {
+ long runningCount = wrkMastService.count(new QueryWrapper<WrkMast>()
+ .eq("crn_no", crnProtocol.getCrnNo())
+ .in("wrk_sts",
+ WrkStsType.INBOUND_RUN.sts,
+ WrkStsType.OUTBOUND_RUN.sts,
+ WrkStsType.LOC_MOVE_RUN.sts,
+ WrkStsType.CRN_MOVE_RUN.sts));
+ if (runningCount > 0) {
+ return false;
}
List<WrkMast> taskQueue = wrkMastService.list(new QueryWrapper<WrkMast>()
- .in("crn_no", new ArrayList<>(dispatchThreadMap.keySet()))
+ .eq("crn_no", crnProtocol.getCrnNo())
.eq("io_type", WrkIoType.CRN_MOVE.id)
.eq("wrk_sts", WrkStsType.NEW_CRN_MOVE.sts)
.orderByAsc("appe_time")
@@ -983,36 +936,38 @@
continue;
}
- Integer crnNo = wrkMast.getCrnNo();
- CrnThread crnThread = dispatchThreadMap.get(crnNo);
- if (crnThread == null || dispatchProtocolMap.get(crnNo) == null) {
+ if (crnProtocol.getBay() == Utils.getBay(wrkMast.getLocNo())) {
+ Date now = new Date();
+ wrkMast.setWrkSts(WrkStsType.COMPLETE_CRN_MOVE.sts);
+ wrkMast.setSystemMsg("鍫嗗灈鏈哄凡鍦ㄧ洰鏍囩偣锛屼换鍔$洿鎺ュ畬鎴�");
+ wrkMast.setIoTime(now);
+ wrkMast.setModiTime(now);
+ if (wrkMastService.updateById(wrkMast)) {
+ wrkAnalysisService.markCraneStart(wrkMast, now);
+ }
continue;
}
- CrnCommand moveCommand = crnThread.getMoveCommand(wrkMast.getLocNo(), wrkMast.getWrkNo(), crnNo);
+ CrnCommand moveCommand = crnThread.getMoveCommand(wrkMast.getLocNo(), wrkMast.getWrkNo(), crnProtocol.getCrnNo());
if (moveCommand == null) {
continue;
}
Date now = new Date();
wrkMast.setWrkSts(WrkStsType.CRN_MOVE_RUN.sts);
- wrkMast.setCrnNo(crnNo);
wrkMast.setSystemMsg("");
wrkMast.setIoTime(now);
wrkMast.setModiTime(now);
if (wrkMastService.updateById(wrkMast)) {
wrkAnalysisService.markCraneStart(wrkMast, now);
- MessageQueue.offer(SlaveType.Crn, crnNo, new Task(2, moveCommand));
+ MessageQueue.offer(SlaveType.Crn, crnProtocol.getCrnNo(), new Task(2, moveCommand));
News.info("鍫嗗灈鏈虹Щ鍔ㄥ懡浠や笅鍙戞垚鍔燂紝鍫嗗灈鏈哄彿={}锛屽伐浣滃彿={}锛岀洰鏍囦綅={}锛屼换鍔℃暟鎹�={}",
- crnNo, wrkMast.getWrkNo(), wrkMast.getLocNo(), JSON.toJSON(moveCommand));
- return blockedCrnNoSet;
+ crnProtocol.getCrnNo(), wrkMast.getWrkNo(), wrkMast.getLocNo(), JSON.toJSON(moveCommand));
+ return true;
}
}
- return blockedCrnNoSet;
- }
- public Set<Integer> executeCrnMoveTaskAndGetBlockedCrnNos() {
- return executeCrnMoveTask();
+ return false;
}
public void submitCrnIoTasks(long minIntervalMs) {
@@ -1020,7 +975,6 @@
}
public void submitCrnIoTasks(MainProcessLane lane, long minIntervalMs) {
- Set<Integer> blockedCrnNos = executeCrnMoveTaskAndGetBlockedCrnNos();
List<BasCrnp> basCrnps = basCrnpService.list(new QueryWrapper<>());
for (BasCrnp basCrnp : basCrnps) {
Integer crnNo = basCrnp == null ? null : basCrnp.getCrnNo();
@@ -1032,7 +986,7 @@
crnNo,
"crnIoExecute",
minIntervalMs,
- () -> crnIoExecute(basCrnp, blockedCrnNos)
+ () -> crnIoExecute(basCrnp)
);
}
}
diff --git a/src/test/java/com/zy/asrs/controller/StationControllerTest.java b/src/test/java/com/zy/asrs/controller/StationControllerTest.java
deleted file mode 100644
index c6dcd32..0000000
--- a/src/test/java/com/zy/asrs/controller/StationControllerTest.java
+++ /dev/null
@@ -1,99 +0,0 @@
-package com.zy.asrs.controller;
-
-import com.core.common.R;
-import com.zy.asrs.domain.param.StationCommandMoveParam;
-import com.zy.asrs.entity.BasDevp;
-import com.zy.asrs.service.BasDevpService;
-import com.zy.core.dispatch.StationCommandDispatchResult;
-import com.zy.core.dispatch.StationCommandDispatcher;
-import com.zy.core.cache.SlaveConnection;
-import com.zy.core.enums.SlaveType;
-import com.zy.core.enums.StationCommandType;
-import com.zy.core.model.command.StationCommand;
-import com.zy.core.thread.StationThread;
-import org.junit.jupiter.api.Test;
-import org.springframework.test.util.ReflectionTestUtils;
-
-import java.util.Collections;
-
-import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.junit.jupiter.api.Assertions.assertThrows;
-import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.ArgumentMatchers.eq;
-import static org.mockito.ArgumentMatchers.same;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
-
-class StationControllerTest {
-
- @Test
- void controller_noLongerKeepsDispatcherFallbackHelper() {
- assertThrows(NoSuchMethodException.class,
- () -> StationController.class.getDeclaredMethod("getStationCommandDispatcher"));
- }
-
- @Test
- void commandClearPath_callsThreadClearPath() {
- StationController controller = new StationController();
- BasDevpService basDevpService = mock(BasDevpService.class);
- StationThread stationThread = mock(StationThread.class);
-
- ReflectionTestUtils.setField(controller, "basDevpService", basDevpService);
-
- BasDevp basDevp = new BasDevp();
- basDevp.setStationList("[{\"deviceNo\":1,\"stationId\":145}]");
- when(basDevpService.list(any(com.baomidou.mybatisplus.core.conditions.Wrapper.class)))
- .thenReturn(Collections.singletonList(basDevp));
- when(stationThread.clearPath(10335)).thenReturn(true);
-
- StationCommandMoveParam param = new StationCommandMoveParam();
- param.setStationId(145);
- param.setTaskNo(10335);
-
- SlaveConnection.put(SlaveType.Devp, 1, stationThread);
- try {
- R result = controller.commandClearPath(param);
-
- assertEquals(200, result.get("code"));
- verify(stationThread).clearPath(10335);
- } finally {
- SlaveConnection.remove(SlaveType.Devp, 1);
- }
- }
-
- @Test
- void commandMove_dispatchesViaStationCommandDispatcher() {
- StationController controller = new StationController();
- BasDevpService basDevpService = mock(BasDevpService.class);
- StationThread stationThread = mock(StationThread.class);
- StationCommandDispatcher dispatcher = mock(StationCommandDispatcher.class);
- StationCommand command = new StationCommand();
-
- ReflectionTestUtils.setField(controller, "basDevpService", basDevpService);
- ReflectionTestUtils.setField(controller, "stationCommandDispatcher", dispatcher);
-
- BasDevp basDevp = new BasDevp();
- basDevp.setStationList("[{\"deviceNo\":1,\"stationId\":145}]");
- when(basDevpService.list(any(com.baomidou.mybatisplus.core.conditions.Wrapper.class)))
- .thenReturn(Collections.singletonList(basDevp));
- when(stationThread.getCommand(StationCommandType.MOVE, 10335, 145, 188, 0)).thenReturn(command);
- when(dispatcher.dispatch(1, command, "station-controller", "manual-move"))
- .thenReturn(StationCommandDispatchResult.accepted("accepted", 1, "station-controller", "manual-move"));
-
- StationCommandMoveParam param = new StationCommandMoveParam();
- param.setStationId(145);
- param.setTaskNo(10335);
- param.setTargetStationId(188);
-
- SlaveConnection.put(SlaveType.Devp, 1, stationThread);
- try {
- R result = controller.commandMove(param);
-
- assertEquals(200, result.get("code"));
- verify(dispatcher).dispatch(eq(1), same(command), eq("station-controller"), eq("manual-move"));
- } finally {
- SlaveConnection.remove(SlaveType.Devp, 1);
- }
- }
-}
diff --git a/src/test/java/com/zy/asrs/service/impl/BasMapEditorServiceImplTest.java b/src/test/java/com/zy/asrs/service/impl/BasMapEditorServiceImplTest.java
deleted file mode 100644
index d3d470a..0000000
--- a/src/test/java/com/zy/asrs/service/impl/BasMapEditorServiceImplTest.java
+++ /dev/null
@@ -1,135 +0,0 @@
-package com.zy.asrs.service.impl;
-
-import com.alibaba.fastjson.JSON;
-import com.alibaba.fastjson.JSONObject;
-import com.zy.asrs.domain.BasMapEditorDoc;
-import com.zy.asrs.domain.BasMapEditorElement;
-import com.zy.common.model.NavigateNode;
-import com.zy.common.utils.NavigateSolution;
-import com.zy.core.enums.MapNodeType;
-import org.junit.jupiter.api.Test;
-import org.springframework.test.util.ReflectionTestUtils;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-
-import static org.junit.jupiter.api.Assertions.assertFalse;
-import static org.junit.jupiter.api.Assertions.assertNotNull;
-import static org.junit.jupiter.api.Assertions.assertTrue;
-
-class BasMapEditorServiceImplTest {
-
- @Test
- void compileToStoredMapData_bridgesNearlyAlignedDevpElements() {
- BasMapEditorServiceImpl service = new BasMapEditorServiceImpl();
- BasMapEditorDoc doc = buildDoc(
- createDevp("left", 0.0d, 0.0d, 10.0d, 10.0d, 101, 1),
- createDevp("right", 11.0d, 0.5d, 10.0d, 10.0d, 102, 2)
- );
-
- List<List<HashMap<String, Object>>> storedData = compileStoredMapData(service, doc);
- List<List<NavigateNode>> stationMap = buildStationMap(storedData);
- NavigateSolution navigateSolution = new NavigateSolution();
-
- NavigateNode startNode = navigateSolution.findStationNavigateNode(stationMap, 101);
- NavigateNode endNode = navigateSolution.findStationNavigateNode(stationMap, 102);
- assertNotNull(startNode);
- assertNotNull(endNode);
-
- List<List<NavigateNode>> paths = navigateSolution.allSimplePaths(stationMap, startNode, endNode, 40, 20, 200);
- assertFalse(paths.isEmpty(), "杞诲井閿欎綅浣嗘帴瑙﹁竟楂樺害閲嶅悎鏃跺簲鑷姩鍒ゅ畾涓鸿仈閫�");
- }
-
- @Test
- void compileToStoredMapData_doesNotBridgeClearlyMisalignedDevpElements() {
- BasMapEditorServiceImpl service = new BasMapEditorServiceImpl();
- BasMapEditorDoc doc = buildDoc(
- createDevp("left", 0.0d, 0.0d, 10.0d, 10.0d, 101, 1),
- createDevp("right", 11.0d, 4.5d, 10.0d, 10.0d, 102, 2)
- );
-
- List<List<HashMap<String, Object>>> storedData = compileStoredMapData(service, doc);
- List<List<NavigateNode>> stationMap = buildStationMap(storedData);
- NavigateSolution navigateSolution = new NavigateSolution();
-
- NavigateNode startNode = navigateSolution.findStationNavigateNode(stationMap, 101);
- NavigateNode endNode = navigateSolution.findStationNavigateNode(stationMap, 102);
- assertNotNull(startNode);
- assertNotNull(endNode);
-
- List<List<NavigateNode>> paths = navigateSolution.allSimplePaths(stationMap, startNode, endNode, 40, 20, 200);
- assertTrue(paths.isEmpty(), "鏄庢樉閿欎綅鏃朵笉搴旇鑷姩妗ユ帴涓鸿仈閫�");
- }
-
- @SuppressWarnings("unchecked")
- private List<List<HashMap<String, Object>>> compileStoredMapData(BasMapEditorServiceImpl service, BasMapEditorDoc doc) {
- return (List<List<HashMap<String, Object>>>) ReflectionTestUtils.invokeMethod(service, "compileToStoredMapData", doc);
- }
-
- private BasMapEditorDoc buildDoc(BasMapEditorElement... elements) {
- BasMapEditorDoc doc = new BasMapEditorDoc();
- doc.setLev(1);
- doc.setEditorMode("free-v1");
- doc.setCanvasWidth(80.0d);
- doc.setCanvasHeight(40.0d);
- doc.setElements(List.of(elements));
- return doc;
- }
-
- private BasMapEditorElement createDevp(String id,
- double x,
- double y,
- double width,
- double height,
- int stationId,
- int deviceNo) {
- BasMapEditorElement element = new BasMapEditorElement();
- element.setId(id);
- element.setType("devp");
- element.setX(x);
- element.setY(y);
- element.setWidth(width);
- element.setHeight(height);
-
- JSONObject value = new JSONObject();
- value.put("stationId", stationId);
- value.put("deviceNo", deviceNo);
- value.put("direction", List.of("left", "right"));
- element.setValue(value.toJSONString());
- return element;
- }
-
- private List<List<NavigateNode>> buildStationMap(List<List<HashMap<String, Object>>> storedData) {
- List<List<NavigateNode>> stationMap = new ArrayList<>();
- for (int rowIndex = 0; rowIndex < storedData.size(); rowIndex++) {
- List<HashMap<String, Object>> row = storedData.get(rowIndex);
- List<NavigateNode> navigateNodeRow = new ArrayList<>();
- for (int colIndex = 0; colIndex < row.size(); colIndex++) {
- HashMap<String, Object> cell = row.get(colIndex);
- NavigateNode node = new NavigateNode(rowIndex, colIndex);
- String nodeType = cell == null ? null : String.valueOf(cell.get("type"));
- String mergeType = cell == null ? null : stringValue(cell.get("mergeType"));
- String nodeValue = cell == null ? null : stringValue(cell.get("value"));
-
- if ("devp".equals(nodeType) || ("merge".equals(nodeType) && "devp".equals(mergeType))) {
- node.setValue(MapNodeType.NORMAL_PATH.id);
- JSONObject valueObject = JSON.parseObject(nodeValue);
- node.setDirectionList(valueObject == null ? new ArrayList<>() : valueObject.getJSONArray("direction").toJavaList(String.class));
- } else {
- node.setValue(MapNodeType.DISABLE.id);
- }
-
- node.setNodeType(nodeType);
- node.setNodeValue(nodeValue);
- navigateNodeRow.add(node);
- }
- stationMap.add(navigateNodeRow);
- }
- return stationMap;
- }
-
- private String stringValue(Object value) {
- return value == null ? null : String.valueOf(value);
- }
-}
diff --git a/src/test/java/com/zy/asrs/service/impl/WrkAnalysisServiceImplTest.java b/src/test/java/com/zy/asrs/service/impl/WrkAnalysisServiceImplTest.java
deleted file mode 100644
index aec6435..0000000
--- a/src/test/java/com/zy/asrs/service/impl/WrkAnalysisServiceImplTest.java
+++ /dev/null
@@ -1,75 +0,0 @@
-package com.zy.asrs.service.impl;
-
-import com.zy.asrs.entity.WrkAnalysis;
-import com.zy.asrs.service.BasCrnpErrLogService;
-import com.zy.asrs.service.BasDualCrnpErrLogService;
-import com.zy.asrs.service.BasRgvErrLogService;
-import com.zy.asrs.service.BasStationErrLogService;
-import com.zy.asrs.service.BasStationService;
-import com.zy.asrs.service.BasWrkStatusService;
-import com.zy.asrs.service.WrkMastLogService;
-import com.zy.asrs.service.WrkMastService;
-import org.junit.jupiter.api.Test;
-import org.springframework.test.util.ReflectionTestUtils;
-
-import java.text.ParseException;
-import java.text.SimpleDateFormat;
-import java.util.Arrays;
-import java.util.Date;
-import java.util.Map;
-
-import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-
-class WrkAnalysisServiceImplTest {
-
- @Test
- @SuppressWarnings("unchecked")
- void buildAnalysisResult_calculatesAverageTaskPerHour() {
- BasWrkStatusService basWrkStatusService = mock(BasWrkStatusService.class);
- when(basWrkStatusService.getById(org.mockito.ArgumentMatchers.any())).thenReturn(null);
- WrkAnalysisServiceImpl service = new WrkAnalysisServiceImpl(
- mock(WrkMastLogService.class),
- mock(BasCrnpErrLogService.class),
- mock(BasDualCrnpErrLogService.class),
- mock(BasRgvErrLogService.class),
- mock(BasStationErrLogService.class),
- mock(BasStationService.class),
- basWrkStatusService,
- mock(WrkMastService.class)
- );
-
- Map<String, Object> result = ReflectionTestUtils.invokeMethod(
- service,
- "buildAnalysisResult",
- Arrays.asList(
- analysis(1001, date("2026-03-27 13:00:00"), date("2026-03-27 13:10:00"), 600_000L),
- analysis(1002, date("2026-03-27 13:15:00"), date("2026-03-27 13:30:00"), 900_000L)
- ),
- "finish_time"
- );
-
- Map<String, Object> summary = (Map<String, Object>) result.get("summary");
- assertEquals(4.0d, ((Number) summary.get("avgTaskPerHour")).doubleValue(), 0.0001d);
- }
-
- private WrkAnalysis analysis(int wrkNo, Date appeTime, Date finishTime, long totalDurationMs) {
- WrkAnalysis item = new WrkAnalysis();
- item.setWrkNo(wrkNo);
- item.setAppeTime(appeTime);
- item.setFinishTime(finishTime);
- item.setTotalDurationMs(totalDurationMs);
- item.setFinalWrkSts(80L);
- item.setMetricCompleteness("COMPLETE");
- return item;
- }
-
- private Date date(String value) {
- try {
- return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(value);
- } catch (ParseException e) {
- throw new IllegalArgumentException(e);
- }
- }
-}
diff --git a/src/test/java/com/zy/asrs/task/WrkMastSchedulerCrnMoveTest.java b/src/test/java/com/zy/asrs/task/WrkMastSchedulerCrnMoveTest.java
deleted file mode 100644
index d08297b..0000000
--- a/src/test/java/com/zy/asrs/task/WrkMastSchedulerCrnMoveTest.java
+++ /dev/null
@@ -1,54 +0,0 @@
-package com.zy.asrs.task;
-
-import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
-import com.zy.asrs.entity.WrkMast;
-import com.zy.asrs.service.LocMastService;
-import com.zy.asrs.service.WrkAnalysisService;
-import com.zy.asrs.service.WrkMastLogService;
-import com.zy.asrs.service.WrkMastService;
-import com.zy.asrs.utils.NotifyUtils;
-import com.zy.core.enums.WrkIoType;
-import com.zy.core.enums.WrkStsType;
-import org.junit.jupiter.api.Test;
-
-import java.util.List;
-
-import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
-
-class WrkMastSchedulerCrnMoveTest {
-
- @Test
- void executeCrnMove_archivesAndRemovesCompletedCrnMoveTask() {
- WrkMastService wrkMastService = mock(WrkMastService.class);
- WrkMastLogService wrkMastLogService = mock(WrkMastLogService.class);
- WrkAnalysisService wrkAnalysisService = mock(WrkAnalysisService.class);
- LocMastService locMastService = mock(LocMastService.class);
- NotifyUtils notifyUtils = mock(NotifyUtils.class);
-
- WrkMastScheduler scheduler = new WrkMastScheduler(
- wrkMastService,
- wrkMastLogService,
- wrkAnalysisService,
- locMastService,
- notifyUtils
- );
-
- WrkMast wrkMast = new WrkMast();
- wrkMast.setWrkNo(30001);
- wrkMast.setIoType(WrkIoType.CRN_MOVE.id);
- wrkMast.setWrkSts(WrkStsType.COMPLETE_CRN_MOVE.sts);
-
- when(wrkMastService.list(any(QueryWrapper.class))).thenReturn(List.of(wrkMast));
- when(wrkMastLogService.save(30001)).thenReturn(true);
- when(wrkMastService.removeById(30001)).thenReturn(true);
-
- scheduler.executeCrnMove();
-
- verify(wrkMastLogService).save(30001);
- verify(wrkAnalysisService).finishTask(any(WrkMast.class), any());
- verify(wrkMastService).removeById(30001);
- }
-}
diff --git a/src/test/java/com/zy/common/utils/NavigatePerformanceBenchmarkTest.java b/src/test/java/com/zy/common/utils/NavigatePerformanceBenchmarkTest.java
deleted file mode 100644
index 9735b59..0000000
--- a/src/test/java/com/zy/common/utils/NavigatePerformanceBenchmarkTest.java
+++ /dev/null
@@ -1,354 +0,0 @@
-package com.zy.common.utils;
-
-import com.alibaba.fastjson.JSON;
-import com.alibaba.fastjson.JSONObject;
-import com.zy.asrs.service.impl.BasMapEditorServiceImpl;
-import com.zy.asrs.utils.MapExcelUtils;
-import com.zy.common.model.NavigateNode;
-import com.zy.core.enums.MapNodeType;
-import org.junit.jupiter.api.Assumptions;
-import org.junit.jupiter.api.Test;
-import org.springframework.test.util.ReflectionTestUtils;
-
-import java.io.IOException;
-import java.nio.file.Files;
-import java.nio.file.Path;
-import java.util.ArrayList;
-import java.util.Comparator;
-import java.util.HashMap;
-import java.util.LinkedHashMap;
-import java.util.LinkedHashSet;
-import java.util.List;
-import java.util.Locale;
-import java.util.Map;
-import java.util.Set;
-import java.util.stream.Collectors;
-import java.util.stream.Stream;
-
-import static org.junit.jupiter.api.Assertions.assertFalse;
-
-class NavigatePerformanceBenchmarkTest {
-
- private static final int CALC_MAX_DEPTH = 120;
- private static final int CALC_MAX_PATHS = 500;
- private static final int CALC_MAX_COST = 300;
-
- @Test
- void benchmarkExcelMaps() throws Exception {
- // 鎵嬪伐鍘嬫祴鍏ュ彛锛岄伩鍏嶉粯璁ゆ祴璇曞浠惰鎬ц兘娴嬭瘯鎷栨參銆�
- Assumptions.assumeTrue(Boolean.getBoolean("manualBench"));
-
- Path mapDir = Path.of("src/main/resources/map");
- List<Path> mapFileList;
- try (Stream<Path> stream = Files.list(mapDir)) {
- mapFileList = stream
- .filter(path -> path.getFileName().toString().endsWith(".xlsx"))
- .sorted(Comparator.comparing(path -> path.getFileName().toString()))
- .collect(Collectors.toList());
- }
-
- List<String> reportLineList = new ArrayList<>();
- for (Path mapFile : mapFileList) {
- reportLineList.addAll(benchmarkMapFile(mapFile));
- }
-
- reportLineList.forEach(System.out::println);
- assertFalse(reportLineList.isEmpty(), "鏈敓鎴愪换浣曞湴鍥炬�ц兘鎶ュ憡");
- }
-
- private List<String> benchmarkMapFile(Path mapFile) throws IOException {
- MapExcelUtils mapExcelUtils = new MapExcelUtils();
- BasMapEditorServiceImpl editorService = new BasMapEditorServiceImpl();
-
- HashMap<Integer, List<List<HashMap<String, Object>>>> rawDataMap = mapExcelUtils.readExcel(mapFile.toString());
- List<Integer> levList = rawDataMap.keySet().stream().sorted().collect(Collectors.toList());
-
- List<String> reportLineList = new ArrayList<>();
- for (Integer lev : levList) {
- @SuppressWarnings("unchecked")
- List<List<HashMap<String, Object>>> storedData =
- (List<List<HashMap<String, Object>>>) ReflectionTestUtils.invokeMethod(
- editorService,
- "convertRawExcelData",
- rawDataMap.get(lev)
- );
- List<List<NavigateNode>> stationMap = buildStationMap(storedData);
- Map<Integer, NavigateNode> stationNodeMap = collectStationNodeMap(stationMap);
- if (stationNodeMap.size() < 2) {
- continue;
- }
-
- BenchmarkSummary summary = benchmarkStationPairs(stationMap, stationNodeMap);
- reportLineList.add(summary.format(mapFile.getFileName().toString(), lev));
- }
- return reportLineList;
- }
-
- private BenchmarkSummary benchmarkStationPairs(List<List<NavigateNode>> stationMap,
- Map<Integer, NavigateNode> stationNodeMap) {
- NavigateSolution navigateSolution = new NavigateSolution();
- List<Integer> stationIdList = new ArrayList<>(stationNodeMap.keySet());
- stationIdList.sort(Integer::compareTo);
-
- BenchmarkSummary summary = new BenchmarkSummary(stationIdList.size());
- warmup(navigateSolution, stationMap, stationNodeMap, stationIdList);
-
- for (int i = 0; i < stationIdList.size(); i++) {
- for (int j = i + 1; j < stationIdList.size(); j++) {
- Integer startStationId = stationIdList.get(i);
- Integer endStationId = stationIdList.get(j);
-
- NavigateNode startNode = stationNodeMap.get(startStationId);
- NavigateNode endNode = stationNodeMap.get(endStationId);
- if (startNode == null || endNode == null) {
- continue;
- }
-
- resetMapSearchState(stationMap);
- long astarStartNs = System.nanoTime();
- NavigateNode astarResult = navigateSolution.astarSearchJava(stationMap, startNode, endNode);
- long astarElapsedNs = System.nanoTime() - astarStartNs;
- int astarPathLen = calcBacktrackPathLength(astarResult, stationMap);
-
- long allPathsStartNs = System.nanoTime();
- List<List<NavigateNode>> candidatePathList = navigateSolution.allSimplePaths(
- stationMap,
- startNode,
- endNode,
- CALC_MAX_DEPTH,
- CALC_MAX_PATHS,
- CALC_MAX_COST
- );
- long allPathsElapsedNs = System.nanoTime() - allPathsStartNs;
-
- summary.record(
- startStationId,
- endStationId,
- astarElapsedNs,
- allPathsElapsedNs,
- astarPathLen,
- candidatePathList == null ? 0 : candidatePathList.size()
- );
- }
- }
- return summary;
- }
-
- private void warmup(NavigateSolution navigateSolution,
- List<List<NavigateNode>> stationMap,
- Map<Integer, NavigateNode> stationNodeMap,
- List<Integer> stationIdList) {
- int warmupPairCount = Math.min(5, Math.max(0, stationIdList.size() - 1));
- for (int i = 0; i < warmupPairCount; i++) {
- Integer startStationId = stationIdList.get(i);
- Integer endStationId = stationIdList.get(stationIdList.size() - 1 - i);
- NavigateNode startNode = stationNodeMap.get(startStationId);
- NavigateNode endNode = stationNodeMap.get(endStationId);
- if (startNode == null || endNode == null) {
- continue;
- }
- resetMapSearchState(stationMap);
- navigateSolution.astarSearchJava(stationMap, startNode, endNode);
- navigateSolution.allSimplePaths(
- stationMap,
- startNode,
- endNode,
- CALC_MAX_DEPTH,
- CALC_MAX_PATHS,
- CALC_MAX_COST
- );
- }
- }
-
- private Map<Integer, NavigateNode> collectStationNodeMap(List<List<NavigateNode>> stationMap) {
- NavigateSolution navigateSolution = new NavigateSolution();
- Set<Integer> stationIdSet = new LinkedHashSet<>();
- for (List<NavigateNode> row : stationMap) {
- for (NavigateNode node : row) {
- Integer stationId = extractStationId(node);
- if (stationId != null) {
- stationIdSet.add(stationId);
- }
- }
- }
-
- Map<Integer, NavigateNode> stationNodeMap = new LinkedHashMap<>();
- for (Integer stationId : stationIdSet) {
- NavigateNode node = navigateSolution.findStationNavigateNode(stationMap, stationId);
- if (node != null) {
- stationNodeMap.put(stationId, node);
- }
- }
- return stationNodeMap;
- }
-
- private Integer extractStationId(NavigateNode node) {
- if (node == null || node.getNodeValue() == null || node.getNodeValue().trim().isEmpty()) {
- return null;
- }
- try {
- JSONObject valueObject = JSON.parseObject(node.getNodeValue());
- return valueObject == null ? null : valueObject.getInteger("stationId");
- } catch (Exception ignore) {
- return null;
- }
- }
-
- private void resetMapSearchState(List<List<NavigateNode>> stationMap) {
- for (List<NavigateNode> row : stationMap) {
- for (NavigateNode node : row) {
- node.setFather(null);
- node.setF(0);
- node.setG(0);
- node.setH(0);
- node.setIsInflectionPoint(false);
- node.setDirection(null);
- }
- }
- }
-
- private int calcBacktrackPathLength(NavigateNode endNode, List<List<NavigateNode>> stationMap) {
- if (endNode == null) {
- return 0;
- }
- int maxDepth = stationMap.size() * stationMap.get(0).size() + 5;
- int length = 0;
- Set<String> visited = new LinkedHashSet<>();
- NavigateNode current = endNode;
- while (current != null && visited.add(current.getX() + "_" + current.getY()) && length < maxDepth) {
- length++;
- current = current.getFather();
- }
- return length;
- }
-
- private List<List<NavigateNode>> buildStationMap(List<List<HashMap<String, Object>>> storedData) {
- List<List<NavigateNode>> stationMap = new ArrayList<>();
- for (int rowIndex = 0; rowIndex < storedData.size(); rowIndex++) {
- List<HashMap<String, Object>> row = storedData.get(rowIndex);
- List<NavigateNode> navigateNodeRow = new ArrayList<>();
- for (int colIndex = 0; colIndex < row.size(); colIndex++) {
- HashMap<String, Object> cell = row.get(colIndex);
- NavigateNode node = new NavigateNode(rowIndex, colIndex);
- String nodeType = cell == null ? null : stringValue(cell.get("type"));
- String mergeType = cell == null ? null : stringValue(cell.get("mergeType"));
- String nodeValue = cell == null ? null : stringValue(cell.get("value"));
-
- if ("devp".equals(nodeType) || ("merge".equals(nodeType) && "devp".equals(mergeType))) {
- node.setValue(MapNodeType.NORMAL_PATH.id);
- JSONObject valueObject = JSON.parseObject(nodeValue);
- node.setDirectionList(valueObject == null
- ? new ArrayList<>()
- : valueObject.getJSONArray("direction").toJavaList(String.class));
- } else {
- node.setValue(MapNodeType.DISABLE.id);
- }
-
- node.setNodeType(nodeType);
- node.setNodeValue(nodeValue);
- navigateNodeRow.add(node);
- }
- stationMap.add(navigateNodeRow);
- }
- return stationMap;
- }
-
- private String stringValue(Object value) {
- return value == null ? null : String.valueOf(value);
- }
-
- private static class BenchmarkSummary {
- private final int stationCount;
- private int pairCount;
- private long astarTotalNs;
- private long allPathsTotalNs;
- private final List<Long> astarElapsedNsList = new ArrayList<>();
- private final List<Long> allPathsElapsedNsList = new ArrayList<>();
- private int maxCandidateCount;
- private int maxAstarPathLen;
- private int worstAstarStartStationId;
- private int worstAstarEndStationId;
- private long worstAstarElapsedNs;
- private int worstAllPathsStartStationId;
- private int worstAllPathsEndStationId;
- private long worstAllPathsElapsedNs;
- private int worstAllPathsCandidateCount;
-
- private BenchmarkSummary(int stationCount) {
- this.stationCount = stationCount;
- }
-
- private void record(int startStationId,
- int endStationId,
- long astarElapsedNs,
- long allPathsElapsedNs,
- int astarPathLen,
- int candidateCount) {
- pairCount++;
- astarTotalNs += astarElapsedNs;
- allPathsTotalNs += allPathsElapsedNs;
- astarElapsedNsList.add(astarElapsedNs);
- allPathsElapsedNsList.add(allPathsElapsedNs);
- maxCandidateCount = Math.max(maxCandidateCount, candidateCount);
- maxAstarPathLen = Math.max(maxAstarPathLen, astarPathLen);
-
- if (astarElapsedNs > worstAstarElapsedNs) {
- worstAstarElapsedNs = astarElapsedNs;
- worstAstarStartStationId = startStationId;
- worstAstarEndStationId = endStationId;
- }
- if (allPathsElapsedNs > worstAllPathsElapsedNs) {
- worstAllPathsElapsedNs = allPathsElapsedNs;
- worstAllPathsStartStationId = startStationId;
- worstAllPathsEndStationId = endStationId;
- worstAllPathsCandidateCount = candidateCount;
- }
- }
-
- private String format(String mapFileName, Integer lev) {
- return String.format(
- Locale.ROOT,
- "map=%s lev=%d stations=%d pairs=%d | A*=avg %.3fms p95 %.3fms max %.3fms pair=%d->%d | allSimplePaths=avg %.3fms p95 %.3fms max %.3fms pair=%d->%d candidates=%d | maxPathLen=%d maxCandidates=%d",
- mapFileName,
- lev,
- stationCount,
- pairCount,
- toMillis(avg(astarTotalNs, pairCount)),
- toMillis(percentile(astarElapsedNsList, 0.95d)),
- toMillis(worstAstarElapsedNs),
- worstAstarStartStationId,
- worstAstarEndStationId,
- toMillis(avg(allPathsTotalNs, pairCount)),
- toMillis(percentile(allPathsElapsedNsList, 0.95d)),
- toMillis(worstAllPathsElapsedNs),
- worstAllPathsStartStationId,
- worstAllPathsEndStationId,
- worstAllPathsCandidateCount,
- maxAstarPathLen,
- maxCandidateCount
- );
- }
-
- private double avg(long totalNs, int count) {
- if (count <= 0) {
- return 0.0d;
- }
- return (double) totalNs / count;
- }
-
- private double percentile(List<Long> valueList, double percentile) {
- if (valueList == null || valueList.isEmpty()) {
- return 0.0d;
- }
- List<Long> sortedList = new ArrayList<>(valueList);
- sortedList.sort(Long::compareTo);
- int index = (int) Math.ceil(percentile * sortedList.size()) - 1;
- index = Math.max(0, Math.min(index, sortedList.size() - 1));
- return sortedList.get(index);
- }
-
- private double toMillis(double nanos) {
- return nanos / 1_000_000.0d;
- }
- }
-}
diff --git a/src/test/java/com/zy/common/utils/NavigateUtilsTest.java b/src/test/java/com/zy/common/utils/NavigateUtilsTest.java
deleted file mode 100644
index 2318053..0000000
--- a/src/test/java/com/zy/common/utils/NavigateUtilsTest.java
+++ /dev/null
@@ -1,49 +0,0 @@
-package com.zy.common.utils;
-
-import com.alibaba.fastjson.JSONObject;
-import com.zy.common.model.NavigateNode;
-import org.junit.jupiter.api.Test;
-import org.springframework.test.util.ReflectionTestUtils;
-
-import java.util.List;
-import java.util.stream.Collectors;
-
-import static org.junit.jupiter.api.Assertions.assertEquals;
-
-class NavigateUtilsTest {
-
- @Test
- void normalizeStationPath_keepsLoopRevisitStationsWhileCompressingAdjacentDuplicates() {
- NavigateUtils navigateUtils = new NavigateUtils();
-
- @SuppressWarnings("unchecked")
- List<NavigateNode> normalizedPath = (List<NavigateNode>) ReflectionTestUtils.invokeMethod(
- navigateUtils,
- "normalizeStationPath",
- List.of(
- buildNode(121, 0, 0),
- buildNode(121, 0, 1),
- buildNode(124, 0, 2),
- buildNode(186, 0, 3),
- buildNode(189, 0, 4),
- buildNode(121, 0, 5),
- buildNode(124, 0, 6),
- buildNode(124, 0, 7),
- buildNode(125, 0, 8),
- buildNode(127, 0, 9)
- )
- );
-
- List<Integer> stationIdList = normalizedPath.stream()
- .map(node -> JSONObject.parseObject(node.getNodeValue()).getInteger("stationId"))
- .collect(Collectors.toList());
-
- assertEquals(List.of(121, 124, 186, 189, 121, 124, 125, 127), stationIdList);
- }
-
- private NavigateNode buildNode(int stationId, int x, int y) {
- NavigateNode node = new NavigateNode(x, y);
- node.setNodeValue("{\"stationId\":" + stationId + "}");
- return node;
- }
-}
diff --git a/src/test/java/com/zy/core/dispatch/StationCommandDispatcherTest.java b/src/test/java/com/zy/core/dispatch/StationCommandDispatcherTest.java
deleted file mode 100644
index aab4866..0000000
--- a/src/test/java/com/zy/core/dispatch/StationCommandDispatcherTest.java
+++ /dev/null
@@ -1,100 +0,0 @@
-package com.zy.core.dispatch;
-
-import com.zy.common.utils.RedisUtil;
-import com.zy.core.cache.MessageQueue;
-import com.zy.core.enums.SlaveType;
-import com.zy.core.enums.StationCommandType;
-import com.zy.core.model.command.StationCommand;
-import com.zy.core.move.StationMoveCoordinator;
-import org.junit.jupiter.api.Test;
-
-import java.util.HashMap;
-import java.util.Map;
-
-import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.junit.jupiter.api.Assertions.assertFalse;
-import static org.junit.jupiter.api.Assertions.assertTrue;
-import static org.mockito.ArgumentMatchers.anyLong;
-import static org.mockito.ArgumentMatchers.anyString;
-import static org.mockito.ArgumentMatchers.eq;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-
-class StationCommandDispatcherTest {
-
- @Test
- void dispatch_acceptsMoveCommandAndReturnsQueueDepth() {
- StationCommandDispatcher dispatcher = new StationCommandDispatcher();
-
- StationCommand command = new StationCommand();
- command.setCommandType(StationCommandType.MOVE);
- command.setTaskNo(100);
- command.setStationId(10);
- command.setTargetStaNo(20);
-
- MessageQueue.init(SlaveType.Devp, 1);
- try {
- StationCommandDispatchResult result = dispatcher.dispatch(1, command, "unit-test", "move");
-
- assertTrue(result.isAccepted());
- assertEquals("accepted", result.getReason());
- assertEquals(1, result.getQueueDepth());
- assertEquals("unit-test", result.getSource());
- assertEquals("move", result.getScene());
- } finally {
- MessageQueue.clear(SlaveType.Devp, 1);
- }
- }
-
- @Test
- void dispatch_suppressesDuplicateMoveCommandWithinDedupWindow() {
- RedisUtil redisUtil = mock(RedisUtil.class);
- StationMoveCoordinator coordinator = mock(StationMoveCoordinator.class);
- StationCommandDispatcher dispatcher = new StationCommandDispatcher(redisUtil, coordinator);
- Map<String, Object> dedupStore = new HashMap<>();
-
- when(redisUtil.get(anyString())).thenAnswer(invocation -> dedupStore.get(invocation.getArgument(0)));
- when(redisUtil.set(anyString(), eq("lock"), anyLong())).thenAnswer(invocation -> {
- dedupStore.put(invocation.getArgument(0), invocation.getArgument(1));
- return true;
- });
- when(coordinator.buildPathSignatureHash(org.mockito.ArgumentMatchers.any(StationCommand.class)))
- .thenReturn("same-path");
-
- StationCommand command = new StationCommand();
- command.setCommandType(StationCommandType.MOVE);
- command.setTaskNo(100);
- command.setStationId(10);
- command.setTargetStaNo(20);
-
- MessageQueue.init(SlaveType.Devp, 1);
- try {
- StationCommandDispatchResult first = dispatcher.dispatch(1, command, "unit-test", "move");
- StationCommandDispatchResult second = dispatcher.dispatch(1, command, "unit-test", "move");
-
- assertTrue(first.isAccepted());
- assertFalse(second.isAccepted());
- assertEquals("dedup-suppressed", second.getReason());
- assertEquals(1, second.getQueueDepth());
- } finally {
- MessageQueue.clear(SlaveType.Devp, 1);
- }
- }
-
- @Test
- void dispatch_rejectsWhenDevpQueueIsNotInitialized() {
- StationCommandDispatcher dispatcher = new StationCommandDispatcher();
-
- StationCommand command = new StationCommand();
- command.setCommandType(StationCommandType.MOVE);
- command.setTaskNo(100);
- command.setStationId(10);
- command.setTargetStaNo(20);
-
- StationCommandDispatchResult result = dispatcher.dispatch(999, command, "unit-test", "move");
-
- assertFalse(result.isAccepted());
- assertEquals("queue-not-initialized", result.getReason());
- assertEquals(0, result.getQueueDepth());
- }
-}
diff --git a/src/test/java/com/zy/core/network/real/ZyStationV4RealConnectTest.java b/src/test/java/com/zy/core/network/real/ZyStationV4RealConnectTest.java
deleted file mode 100644
index f1bb5a1..0000000
--- a/src/test/java/com/zy/core/network/real/ZyStationV4RealConnectTest.java
+++ /dev/null
@@ -1,50 +0,0 @@
-package com.zy.core.network.real;
-
-import com.zy.core.model.StationObjModel;
-import org.junit.jupiter.api.Test;
-
-import java.util.Arrays;
-import java.util.List;
-
-import static org.junit.jupiter.api.Assertions.assertEquals;
-
-class ZyStationV4RealConnectTest {
-
- @Test
- void buildConveyorCommonAlarmMessageShouldMapDefinedBits() {
- String alarmMsg = ZyStationV4RealConnect.buildConveyorCommonAlarmMessage(
- new boolean[]{true, false, false, false, false, false, false, false},
- new boolean[]{false, false, true, false, false, false, false, false},
- new boolean[]{false, false, true, false, false, false, false, false},
- new boolean[]{true, true, false, false, false, false, false, false}
- );
-
- assertEquals("鎬ュ仠;鎵爜妫�楠屽紓甯�;楂樹綅鍙橀鍣ㄦ晠闅�;璺緞鏌ヨ寮傚父;", alarmMsg);
- }
-
- @Test
- void mergeAlarmMessagesShouldAppendToExistingBarcodeAlarm() {
- String merged = ZyStationV4RealConnect.mergeAlarmMessages("鎵爜寮傚父;", "鎬ュ仠;璺緞鏌ヨ寮傚父;");
-
- assertEquals("鎵爜寮傚父;鎬ュ仠;璺緞鏌ヨ寮傚父;", merged);
- }
-
- @Test
- void sortStationObjModelsByStationIdShouldSortAscending() {
- List<StationObjModel> sorted = ZyStationV4RealConnect.sortStationObjModelsByStationId(Arrays.asList(
- station(107),
- station(101),
- station(104)
- ));
-
- assertEquals(101, sorted.get(0).getStationId());
- assertEquals(104, sorted.get(1).getStationId());
- assertEquals(107, sorted.get(2).getStationId());
- }
-
- private static StationObjModel station(Integer stationId) {
- StationObjModel model = new StationObjModel();
- model.setStationId(stationId);
- return model;
- }
-}
diff --git a/src/test/java/com/zy/core/plugin/store/StoreInTaskPolicyTest.java b/src/test/java/com/zy/core/plugin/store/StoreInTaskPolicyTest.java
deleted file mode 100644
index 6f71255..0000000
--- a/src/test/java/com/zy/core/plugin/store/StoreInTaskPolicyTest.java
+++ /dev/null
@@ -1,104 +0,0 @@
-package com.zy.core.plugin.store;
-
-import com.zy.asrs.entity.BasDevp;
-import com.zy.core.model.CommandResponse;
-import com.zy.core.model.StationObjModel;
-import com.zy.core.model.command.StationCommand;
-import com.zy.core.model.protocol.StationProtocol;
-import com.zy.core.thread.StationThread;
-import org.junit.jupiter.api.Test;
-
-import java.util.List;
-import java.util.Map;
-
-import static org.junit.jupiter.api.Assertions.assertEquals;
-
-class StoreInTaskPolicyTest {
-
- private final StoreInTaskPolicy policy = context -> true;
-
- @Test
- void onApplyFailed_propagatesWarningToBackStation() {
- StationProtocol barcodeStation = new StationProtocol();
- barcodeStation.setStationId(102);
- StationProtocol backStation = new StationProtocol();
- backStation.setStationId(101);
- StationThread stationThread = new FixedStationThread(Map.of(
- 102, barcodeStation,
- 101, backStation
- ));
-
- StationObjModel backStationModel = new StationObjModel();
- backStationModel.setStationId(101);
- StationObjModel barcodeStationModel = new StationObjModel();
- barcodeStationModel.setStationId(102);
- barcodeStationModel.setBackStation(backStationModel);
-
- StoreInTaskContext context = new StoreInTaskContext(new BasDevp(), stationThread, barcodeStationModel, barcodeStation);
- InTaskApplyResult result = new InTaskApplyResult();
- result.setMessage("WMS寮傚父");
-
- policy.onApplyFailed(context, result);
-
- assertEquals("璇锋眰鍏ュ簱澶辫触锛學MS杩斿洖=WMS寮傚父", barcodeStation.getSystemWarning());
- assertEquals("璇锋眰鍏ュ簱澶辫触锛學MS杩斿洖=WMS寮傚父", backStation.getSystemWarning());
- }
-
- private static class FixedStationThread implements StationThread {
-
- private final Map<Integer, StationProtocol> statusMap;
-
- private FixedStationThread(Map<Integer, StationProtocol> statusMap) {
- this.statusMap = statusMap;
- }
-
- @Override
- public List<StationProtocol> getStatus() {
- return List.copyOf(statusMap.values());
- }
-
- @Override
- public Map<Integer, StationProtocol> getStatusMap() {
- return statusMap;
- }
-
- @Override
- public StationCommand getCommand(com.zy.core.enums.StationCommandType commandType, Integer taskNo,
- Integer stationId, Integer targetStationId, Integer palletSize) {
- return null;
- }
-
- @Override
- public boolean clearPath(Integer taskNo) {
- return false;
- }
-
- @Override
- public CommandResponse sendCommand(StationCommand command) {
- return null;
- }
-
- @Override
- public CommandResponse sendOriginCommand(String address, short[] data) {
- return null;
- }
-
- @Override
- public byte[] readOriginCommand(String address, int length) {
- return new byte[0];
- }
-
- @Override
- public void run() {
- }
-
- @Override
- public boolean connect() {
- return true;
- }
-
- @Override
- public void close() {
- }
- }
-}
diff --git a/src/test/java/com/zy/core/thread/impl/ZyStationV5ThreadTest.java b/src/test/java/com/zy/core/thread/impl/ZyStationV5ThreadTest.java
deleted file mode 100644
index ad2ac25..0000000
--- a/src/test/java/com/zy/core/thread/impl/ZyStationV5ThreadTest.java
+++ /dev/null
@@ -1,92 +0,0 @@
-package com.zy.core.thread.impl;
-
-import com.zy.asrs.entity.DeviceConfig;
-import com.zy.common.utils.RedisUtil;
-import com.zy.core.cache.MessageQueue;
-import com.zy.core.enums.SlaveType;
-import com.zy.core.model.Task;
-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.network.ZyStationConnectDriver;
-import com.zy.core.thread.impl.v5.StationV5SegmentExecutor;
-import com.zy.core.thread.impl.v5.StationV5StatusReader;
-import org.junit.jupiter.api.Test;
-import org.springframework.test.util.ReflectionTestUtils;
-
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.List;
-
-import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.junit.jupiter.api.Assertions.assertTrue;
-import static org.mockito.ArgumentMatchers.eq;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.never;
-import static org.mockito.Mockito.timeout;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
-
-class ZyStationV5ThreadTest {
-
- @Test
- void pollAndDispatchQueuedCommand_submitsQueuedMoveCommandToSegmentExecutor() {
- DeviceConfig deviceConfig = new DeviceConfig();
- deviceConfig.setDeviceNo(1);
- RedisUtil redisUtil = mock(RedisUtil.class);
- StationCommand command = new StationCommand();
- StationV5SegmentExecutor segmentExecutor = mock(StationV5SegmentExecutor.class);
-
- ZyStationV5Thread thread = new ZyStationV5Thread(deviceConfig, redisUtil);
- ReflectionTestUtils.setField(thread, "segmentExecutor", segmentExecutor);
-
- MessageQueue.init(SlaveType.Devp, 1);
- try {
- MessageQueue.offer(SlaveType.Devp, 1, new Task(2, command));
-
- ReflectionTestUtils.invokeMethod(thread, "pollAndDispatchQueuedCommand");
-
- verify(segmentExecutor, timeout(1000)).execute(command);
- } finally {
- MessageQueue.clear(SlaveType.Devp, 1);
- thread.close();
- }
- }
-
- @Test
- void clearPath_delegatesPureSlotClearingToDriver() {
- DeviceConfig deviceConfig = new DeviceConfig();
- deviceConfig.setDeviceNo(1);
- RedisUtil redisUtil = mock(RedisUtil.class);
- ZyStationConnectDriver connectDriver = mock(ZyStationConnectDriver.class);
- when(connectDriver.clearTaskBufferSlot(10, 2)).thenReturn(true);
-
- ZyStationV5Thread thread = new ZyStationV5Thread(deviceConfig, redisUtil);
- ReflectionTestUtils.setField(thread, "zyStationConnectDriver", connectDriver);
-
- StationTaskBufferItem hitItem = new StationTaskBufferItem();
- hitItem.setSlotIdx(2);
- hitItem.setTaskNo(100);
- hitItem.setTargetStaNo(88);
-
- StationProtocol station20 = new StationProtocol();
- station20.setStationId(20);
- station20.setTaskBufferItems(Collections.emptyList());
-
- StationProtocol station10 = new StationProtocol();
- station10.setStationId(10);
- station10.setTaskBufferItems(List.of(hitItem));
-
- StationV5StatusReader statusReader = (StationV5StatusReader) ReflectionTestUtils.getField(thread, "statusReader");
- ReflectionTestUtils.setField(statusReader, "statusList", Arrays.asList(station20, station10));
-
- boolean result = thread.clearPath(100);
-
- assertTrue(result);
- verify(connectDriver).clearTaskBufferSlot(eq(10), eq(2));
- verify(redisUtil, never()).set(org.mockito.ArgumentMatchers.anyString(), org.mockito.ArgumentMatchers.any(), org.mockito.ArgumentMatchers.anyLong());
- verify(redisUtil, never()).del(org.mockito.ArgumentMatchers.any(String[].class));
- assertEquals(0, hitItem.getTaskNo());
- assertEquals(0, hitItem.getTargetStaNo());
- }
-}
diff --git a/src/test/java/com/zy/core/thread/impl/station/StationSegmentExecutorTest.java b/src/test/java/com/zy/core/thread/impl/station/StationSegmentExecutorTest.java
deleted file mode 100644
index 8722170..0000000
--- a/src/test/java/com/zy/core/thread/impl/station/StationSegmentExecutorTest.java
+++ /dev/null
@@ -1,106 +0,0 @@
-package com.zy.core.thread.impl.station;
-
-import com.alibaba.fastjson.JSON;
-import com.core.common.SpringUtils;
-import com.zy.asrs.entity.DeviceConfig;
-import com.zy.common.utils.RedisUtil;
-import com.zy.core.enums.RedisKeyType;
-import com.zy.core.model.CommandResponse;
-import com.zy.core.model.command.StationCommand;
-import com.zy.core.move.StationMoveCoordinator;
-import com.zy.core.move.StationMoveSessionRegistry;
-import com.zy.core.move.StationMoveSession;
-import org.junit.jupiter.api.Test;
-import org.springframework.context.ApplicationContext;
-import org.springframework.test.util.ReflectionTestUtils;
-
-import java.util.List;
-import java.util.function.Function;
-
-import static org.junit.jupiter.api.Assertions.assertFalse;
-import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.never;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
-
-class StationSegmentExecutorTest {
-
- @Test
- void resolveCurrentPathIndex_prefersForwardOccurrenceForLoopRevisitStations() {
- StationSegmentExecutor executor = new StationSegmentExecutor(new DeviceConfig(), mock(RedisUtil.class), command -> null);
-
- Integer second121Index = ReflectionTestUtils.invokeMethod(
- executor,
- "resolveCurrentPathIndex",
- List.of(121, 124, 186, 189, 121, 124, 125, 127),
- 121,
- 3
- );
- Integer second124Index = ReflectionTestUtils.invokeMethod(
- executor,
- "resolveCurrentPathIndex",
- List.of(121, 124, 186, 189, 121, 124, 125, 127),
- 124,
- 4
- );
- Integer same124Index = ReflectionTestUtils.invokeMethod(
- executor,
- "resolveCurrentPathIndex",
- List.of(121, 124, 186, 189, 121, 124, 125, 127),
- 124,
- 5
- );
-
- assertEquals(Integer.valueOf(4), second121Index);
- assertEquals(Integer.valueOf(5), second124Index);
- assertEquals(Integer.valueOf(5), same124Index);
- }
-
- @Test
- void sendSegmentWithRetry_skipsWhenRouteIsCancelPending() {
- ApplicationContext applicationContext = mock(ApplicationContext.class);
- StationMoveCoordinator coordinator = new StationMoveCoordinator();
- StationMoveSessionRegistry sessionRegistry = new StationMoveSessionRegistry();
- RedisUtil redisUtil = mock(RedisUtil.class);
- @SuppressWarnings("unchecked")
- Function<StationCommand, CommandResponse> commandSender = mock(Function.class);
-
- ReflectionTestUtils.setField(coordinator, "sessionRegistry", sessionRegistry);
- ReflectionTestUtils.setField(coordinator, "redisUtil", redisUtil);
- ReflectionTestUtils.setField(sessionRegistry, "redisUtil", redisUtil);
- when(applicationContext.getBean(StationMoveCoordinator.class)).thenReturn(coordinator);
- SpringUtils.init(applicationContext);
-
- StationSegmentExecutor executor = new StationSegmentExecutor(new DeviceConfig(), redisUtil, commandSender);
-
- StationCommand command = new StationCommand();
- command.setTaskNo(10492);
- command.setStationId(186);
- command.setTargetStaNo(124);
- command.setRouteVersion(23);
-
- StationMoveSession session = new StationMoveSession();
- session.setTaskNo(10492);
- session.setRouteVersion(23);
- session.setStatus(StationMoveSession.STATUS_CANCEL_PENDING);
-
- when(redisUtil.get(RedisKeyType.STATION_MOVE_SESSION_.key + 10492))
- .thenReturn(JSON.toJSONString(session));
- when(redisUtil.get(RedisKeyType.DEVICE_STATION_MOVE_RESET.key + 10492)).thenReturn(null);
- when(commandSender.apply(any())).thenReturn(new CommandResponse(true));
-
- Boolean result = ReflectionTestUtils.invokeMethod(
- executor,
- "sendSegmentWithRetry",
- command,
- null,
- null,
- 186
- );
-
- assertFalse(Boolean.TRUE.equals(result));
- verify(commandSender, never()).apply(any());
- }
-}
diff --git a/src/test/java/com/zy/core/thread/impl/station/StationSegmentPlannerTest.java b/src/test/java/com/zy/core/thread/impl/station/StationSegmentPlannerTest.java
deleted file mode 100644
index 440a574..0000000
--- a/src/test/java/com/zy/core/thread/impl/station/StationSegmentPlannerTest.java
+++ /dev/null
@@ -1,49 +0,0 @@
-package com.zy.core.thread.impl.station;
-
-import com.zy.core.enums.StationCommandType;
-import com.zy.core.model.command.StationCommand;
-import org.junit.jupiter.api.Test;
-
-import java.util.List;
-import java.util.stream.Collectors;
-
-import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.junit.jupiter.api.Assertions.assertTrue;
-
-class StationSegmentPlannerTest {
-
- @Test
- void buildPlan_usesLaterLiftTransferOccurrencesWhenLoopPathRevisitsStations() {
- StationSegmentPlanner planner = new StationSegmentPlanner();
-
- StationCommand original = new StationCommand();
- original.setTaskNo(11017);
- original.setCommandType(StationCommandType.MOVE);
- original.setStationId(121);
- original.setTargetStaNo(127);
- original.setNavigatePath(List.of(121, 124, 186, 189, 121, 124, 125, 127));
- original.setLiftTransferPath(List.of(121, 124, 186, 189, 121, 124, 127));
-
- StationSegmentExecutionPlan plan = planner.buildPlan(original);
-
- assertEquals(
- List.of(
- List.of(121, 124),
- List.of(124, 186),
- List.of(186, 189),
- List.of(189, 121),
- List.of(121, 124),
- List.of(124, 125, 127)
- ),
- plan.getSegmentCommands().stream()
- .map(StationCommand::getNavigatePath)
- .collect(Collectors.toList())
- );
- assertEquals(List.of(1, 2, 3, 4, 5, 6),
- plan.getSegmentCommands().stream()
- .map(StationCommand::getSegmentNo)
- .collect(Collectors.toList()));
- assertTrue(plan.getSegmentCommands().stream()
- .allMatch(command -> Integer.valueOf(6).equals(command.getSegmentCount())));
- }
-}
diff --git a/src/test/java/com/zy/core/thread/impl/v5/StationV5RunBlockReroutePlannerTest.java b/src/test/java/com/zy/core/thread/impl/v5/StationV5RunBlockReroutePlannerTest.java
deleted file mode 100644
index be14570..0000000
--- a/src/test/java/com/zy/core/thread/impl/v5/StationV5RunBlockReroutePlannerTest.java
+++ /dev/null
@@ -1,110 +0,0 @@
-package com.zy.core.thread.impl.v5;
-
-import com.alibaba.fastjson.JSON;
-import com.alibaba.fastjson.JSONObject;
-import com.zy.common.utils.RedisUtil;
-import com.zy.core.enums.RedisKeyType;
-import com.zy.core.model.command.StationCommand;
-import com.zy.core.service.StationTaskLoopService;
-import org.junit.jupiter.api.Test;
-
-import java.util.HashSet;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.junit.jupiter.api.Assertions.assertSame;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-
-class StationV5RunBlockReroutePlannerTest {
-
- @Test
- void plan_prefersLongerCandidateWhenShortestPathIsOverusedInsideTriggeredLoop() {
- RedisUtil redisUtil = mock(RedisUtil.class);
- String stateKey = RedisKeyType.STATION_RUN_BLOCK_REROUTE_STATE_.key + "100_10";
- when(redisUtil.get(stateKey)).thenReturn(JSON.toJSONString(seedState(
- 100,
- 10,
- 2,
- List.of(),
- Map.of("10->11->20", 2)
- )));
-
- StationV5RunBlockReroutePlanner planner = new StationV5RunBlockReroutePlanner(redisUtil);
- StationCommand shortest = moveCommand(100, 10, 20, 10, 11, 20);
- StationCommand longer = moveCommand(100, 10, 20, 10, 31, 32, 20);
-
- StationTaskLoopService.LoopIdentitySnapshot loopIdentity =
- new StationTaskLoopService.LoopIdentitySnapshot("10|11|20", new HashSet<>(List.of(10, 11, 20)), 3, 3, "wholeLoop");
- StationTaskLoopService.LoopEvaluation loopEvaluation =
- new StationTaskLoopService.LoopEvaluation(100, 10, loopIdentity, 2, 3, true);
-
- StationV5RunBlockReroutePlanner.PlanResult result = planner.plan(
- 100,
- 10,
- loopEvaluation,
- List.of(shortest, longer)
- );
-
- assertSame(longer, result.getCommand());
- assertEquals(3, result.getPlanCount());
- }
-
- @Test
- void plan_resetsIssuedRoutesWhenAllCandidatesHaveBeenTried() {
- RedisUtil redisUtil = mock(RedisUtil.class);
- String stateKey = RedisKeyType.STATION_RUN_BLOCK_REROUTE_STATE_.key + "100_10";
- when(redisUtil.get(stateKey)).thenReturn(JSON.toJSONString(seedState(
- 100,
- 10,
- 1,
- List.of(List.of(10, 11, 20), List.of(10, 31, 32, 20)),
- Map.of("10->11->20", 1, "10->31->32->20", 1)
- )));
-
- StationV5RunBlockReroutePlanner planner = new StationV5RunBlockReroutePlanner(redisUtil);
- StationCommand first = moveCommand(100, 10, 20, 10, 11, 20);
- StationCommand second = moveCommand(100, 10, 20, 10, 31, 32, 20);
-
- StationTaskLoopService.LoopEvaluation loopEvaluation =
- new StationTaskLoopService.LoopEvaluation(100, 10, StationTaskLoopService.LoopIdentitySnapshot.empty(), 0, 0, false);
-
- StationV5RunBlockReroutePlanner.PlanResult result = planner.plan(
- 100,
- 10,
- loopEvaluation,
- List.of(first, second)
- );
-
- assertSame(first, result.getCommand());
- assertEquals(2, result.getPlanCount());
- }
-
- private static StationCommand moveCommand(Integer taskNo,
- Integer stationId,
- Integer targetStationId,
- Integer... path) {
- StationCommand command = new StationCommand();
- command.setTaskNo(taskNo);
- command.setStationId(stationId);
- command.setTargetStaNo(targetStationId);
- command.setNavigatePath(List.of(path));
- return command;
- }
-
- private static JSONObject seedState(Integer taskNo,
- Integer blockStationId,
- Integer planCount,
- List<List<Integer>> issuedRoutePathList,
- Map<String, Integer> routeIssueCountMap) {
- JSONObject state = new JSONObject();
- state.put("taskNo", taskNo);
- state.put("blockStationId", blockStationId);
- state.put("planCount", planCount);
- state.put("issuedRoutePathList", issuedRoutePathList);
- state.put("routeIssueCountMap", new HashMap<>(routeIssueCountMap));
- return state;
- }
-}
diff --git a/src/test/java/com/zy/core/thread/support/RecentStationArrivalTrackerTest.java b/src/test/java/com/zy/core/thread/support/RecentStationArrivalTrackerTest.java
deleted file mode 100644
index 96b85ad..0000000
--- a/src/test/java/com/zy/core/thread/support/RecentStationArrivalTrackerTest.java
+++ /dev/null
@@ -1,44 +0,0 @@
-package com.zy.core.thread.support;
-
-import com.zy.common.utils.RedisUtil;
-import org.junit.jupiter.api.Test;
-
-import static org.junit.jupiter.api.Assertions.assertFalse;
-import static org.junit.jupiter.api.Assertions.assertTrue;
-import static org.mockito.ArgumentMatchers.eq;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
-
-class RecentStationArrivalTrackerTest {
-
- @Test
- void observe_writesRedisKeyOnlyOnFirstSightingOfLoadedTask() {
- RedisUtil redisUtil = mock(RedisUtil.class);
- RecentStationArrivalTracker tracker = new RecentStationArrivalTracker(redisUtil, 10_000L);
-
- tracker.observe(12, 1001, true);
- tracker.observe(12, 1001, true);
-
- verify(redisUtil).set(eq("station_recent_arrival_12_1001"), eq("1"), eq(10L));
- }
-
- @Test
- void hasRecentArrival_returnsFalseAfterRedisKeyExpires() {
- RedisUtil redisUtil = mock(RedisUtil.class);
- RecentStationArrivalTracker tracker = new RecentStationArrivalTracker(redisUtil, 10_000L);
-
- when(redisUtil.get("station_recent_arrival_12_1001")).thenReturn(null);
- assertFalse(tracker.hasRecentArrival(12, 1001));
- }
-
- @Test
- void hasRecentArrival_returnsTrueWhenRedisKeyExists() {
- RedisUtil redisUtil = mock(RedisUtil.class);
- RecentStationArrivalTracker tracker = new RecentStationArrivalTracker(redisUtil, 10_000L);
-
- when(redisUtil.get("station_recent_arrival_12_1001")).thenReturn("1");
-
- assertTrue(tracker.hasRecentArrival(12, 1001));
- }
-}
diff --git a/src/test/java/com/zy/core/utils/StationOperateProcessUtilsReroutePipelineTest.java b/src/test/java/com/zy/core/utils/StationOperateProcessUtilsReroutePipelineTest.java
deleted file mode 100644
index f5350e2..0000000
--- a/src/test/java/com/zy/core/utils/StationOperateProcessUtilsReroutePipelineTest.java
+++ /dev/null
@@ -1,995 +0,0 @@
-package com.zy.core.utils;
-
-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.asrs.utils.NotifyUtils;
-import com.zy.common.entity.FindCrnNoResult;
-import com.zy.common.service.CommonService;
-import com.zy.core.cache.MessageQueue;
-import com.zy.core.cache.SlaveConnection;
-import com.zy.core.enums.SlaveType;
-import com.zy.core.enums.WrkStsType;
-import com.zy.core.enums.WrkIoType;
-import com.zy.core.enums.RedisKeyType;
-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.junit.jupiter.api.Assertions.assertEquals;
-import static org.junit.jupiter.api.Assertions.assertSame;
-import static org.junit.jupiter.api.Assertions.assertTrue;
-import static org.junit.jupiter.api.Assertions.assertNull;
-import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.ArgumentMatchers.anyString;
-import static org.mockito.ArgumentMatchers.eq;
-import static org.mockito.ArgumentMatchers.same;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.inOrder;
-import static org.mockito.Mockito.times;
-import static org.mockito.Mockito.never;
-import static org.mockito.Mockito.verify;
-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) {
- when(coordinator.withTaskDispatchLock(any(), any())).thenAnswer(invocation -> {
- java.util.function.Supplier<Object> supplier = invocation.getArgument(1);
- return supplier == null ? null : supplier.get();
- });
- }
-
- @Test
- void choosesRunBlockCommandBuilderForRunBlockRerouteScene() {
- RerouteSceneType scene = RerouteSceneType.RUN_BLOCK_REROUTE;
-
- assertSame(RerouteSceneType.RUN_BLOCK_REROUTE, scene);
- }
-
- @Test
- void resolveExecutionTarget_skipsWhenTargetEqualsCurrentStation() {
- RerouteDecision decision = RerouteDecision.skip("same-station");
-
- assertTrue(decision.skip());
- assertEquals("same-station", decision.skipReason());
- }
-
- @Test
- void buildCommandPlan_usesRunBlockCommandBuilderForRunBlockScene() {
- StationOperateProcessUtils utils = newUtils();
- StationThread stationThread = mock(StationThread.class);
- StationCommand command = new StationCommand();
- command.setTaskNo(100);
- command.setStationId(10);
- command.setTargetStaNo(20);
- when(stationThread.getRunBlockRerouteCommand(100, 10, 20, 0, 0.25d)).thenReturn(command);
-
- RerouteContext context = RerouteContext.create(
- RerouteSceneType.RUN_BLOCK_REROUTE,
- buildBasDevp(1),
- stationThread,
- buildStationProtocol(10, 100, 10),
- buildWrkMast(100, 99),
- Collections.emptyList(),
- 0.25d,
- "checkStationRunBlock_reroute"
- ).withRunBlockCommand()
- .withCancelSessionBeforeDispatch()
- .withResetSegmentCommandsBeforeDispatch();
-
- RerouteCommandPlan plan = utils.buildRerouteCommandPlan(
- context,
- RerouteDecision.proceed(20)
- );
-
- verify(stationThread).getRunBlockRerouteCommand(100, 10, 20, 0, 0.25d);
- assertSame(command, plan.command());
- }
-
- @Test
- void executePlan_skipsWhenCurrentTaskStillExistsInBuffer() {
- StationOperateProcessUtils utils = newUtils();
- StationCommand command = new StationCommand();
- command.setTaskNo(100);
- command.setStationId(10);
- command.setTargetStaNo(20);
-
- StationTaskBufferItem bufferItem = new StationTaskBufferItem();
- bufferItem.setTaskNo(100);
-
- RerouteContext context = RerouteContext.create(
- RerouteSceneType.OUT_ORDER,
- buildBasDevp(1),
- mock(StationThread.class),
- buildStationProtocol(10, 100, 10, Collections.singletonList(bufferItem)),
- buildWrkMast(100, 20),
- List.of(10, 20),
- 0.0d,
- "checkStationOutOrder"
- );
-
- RerouteExecutionResult result = utils.executeReroutePlan(
- context,
- RerouteCommandPlan.dispatch(
- command,
- RerouteDecision.proceed(20),
- "checkStationOutOrder"
- )
- );
-
- assertTrue(result.skipped());
- assertEquals("buffer-has-current-task", result.skipReason());
- }
-
- @Test
- void outOrderAndWatchCircle_shareDecisionFlow() {
- StationOperateProcessUtils utils = newUtils();
- WrkMast wrkMast = buildWrkMast(100, 20);
-
- RerouteContext outOrderContext = RerouteContext.create(
- RerouteSceneType.OUT_ORDER,
- buildBasDevp(1),
- mock(StationThread.class),
- buildStationProtocol(10, 100, 10),
- wrkMast,
- Collections.emptyList(),
- 0.0d,
- "checkStationOutOrder"
- );
- RerouteContext watchCircleContext = RerouteContext.create(
- RerouteSceneType.WATCH_CIRCLE,
- buildBasDevp(1),
- mock(StationThread.class),
- buildStationProtocol(10, 100, 10),
- wrkMast,
- Collections.emptyList(),
- 0.0d,
- "watchCircleStation"
- );
-
- RerouteDecision outOrderDecision = utils.resolveSharedRerouteDecision(outOrderContext);
- RerouteDecision watchCircleDecision = utils.resolveSharedRerouteDecision(watchCircleContext);
-
- assertEquals(20, outOrderDecision.targetStationId());
- assertEquals(20, watchCircleDecision.targetStationId());
- }
-
- @Test
- void runBlockReroute_keepsDirectReassignAndNormalRerouteSeparate() {
- StationOperateProcessUtils utils = newUtils();
- 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 = newUtils();
- StationMoveCoordinator coordinator = mock(StationMoveCoordinator.class);
- RedisUtil redisUtil = mock(RedisUtil.class);
- stubTaskDispatchLock(coordinator);
- stash(utils, "stationMoveCoordinator", coordinator);
- stash(utils, "redisUtil", redisUtil);
- wireRerouteProcessor(utils);
-
- 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);
-
- RerouteContext context = RerouteContext.create(
- RerouteSceneType.IDLE_RECOVER,
- buildBasDevp(1),
- mock(StationThread.class),
- buildStationProtocol(10, 100, 10),
- buildWrkMast(100, 20),
- Collections.emptyList(),
- 0.0d,
- "checkStationIdleRecover"
- ).withRecentDispatchGuard();
-
- RerouteExecutionResult result = utils.executeReroutePlan(
- context,
- RerouteCommandPlan.dispatch(
- command,
- RerouteDecision.proceed(20),
- "checkStationIdleRecover"
- )
- );
-
- assertTrue(result.skipped());
- assertEquals("recent-dispatch", result.skipReason());
- verify(coordinator, never()).cancelSession(100);
- }
-
- @Test
- void idleRecover_skipsWhenCurrentStationIsStillInsideRecentlyIssuedActiveRoute() {
- StationOperateProcessUtils utils = newUtils();
- StationMoveCoordinator coordinator = mock(StationMoveCoordinator.class);
- RedisUtil redisUtil = mock(RedisUtil.class);
- stubTaskDispatchLock(coordinator);
- stash(utils, "stationMoveCoordinator", coordinator);
- stash(utils, "redisUtil", redisUtil);
- wireRerouteProcessor(utils);
-
- 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);
-
- RerouteContext context = RerouteContext.create(
- RerouteSceneType.IDLE_RECOVER,
- buildBasDevp(1),
- mock(StationThread.class),
- buildStationProtocol(121, 10510, 121),
- buildWrkMast(10510, 124),
- Collections.emptyList(),
- 0.0d,
- "checkStationIdleRecover"
- ).withRecentDispatchGuard();
-
- RerouteExecutionResult result = utils.executeReroutePlan(
- context,
- RerouteCommandPlan.dispatch(
- command,
- RerouteDecision.proceed(124),
- "checkStationIdleRecover"
- )
- );
-
- assertTrue(result.skipped());
- assertEquals("recent-dispatch", result.skipReason());
- verify(coordinator, never()).cancelSession(10510);
- }
-
- @Test
- void idleRecover_skipsWhenStationCommandLogShowsRecentIssuedMove() {
- StationOperateProcessUtils utils = newUtils();
- StationMoveCoordinator coordinator = mock(StationMoveCoordinator.class);
- BasStationOptService basStationOptService = mock(BasStationOptService.class);
- RedisUtil redisUtil = mock(RedisUtil.class);
- stubTaskDispatchLock(coordinator);
- stash(utils, "stationMoveCoordinator", coordinator);
- stash(utils, "basStationOptService", basStationOptService);
- stash(utils, "redisUtil", redisUtil);
- wireRerouteProcessor(utils);
-
- StationMoveSession session = new StationMoveSession();
- session.setStatus(StationMoveSession.STATUS_RUNNING);
- session.setDispatchStationId(136);
- session.setCurrentStationId(145);
- session.setFullPathStationIds(List.of(136, 137, 139, 142, 143, 145, 148, 149, 151));
- session.setLastIssuedAt(System.currentTimeMillis() - 20_000L);
- when(coordinator.loadSession(10493)).thenReturn(session);
-
- BasStationOpt recentOpt = new BasStationOpt();
- recentOpt.setTaskNo(10493);
- recentOpt.setStationId(148);
- recentOpt.setSend(1);
- recentOpt.setMode(String.valueOf(com.zy.core.enums.StationCommandType.MOVE));
- recentOpt.setSendTime(new Date());
- when(basStationOptService.list(any(com.baomidou.mybatisplus.core.conditions.Wrapper.class)))
- .thenReturn(Collections.singletonList(recentOpt));
-
- Boolean skipped = ReflectionTestUtils.invokeMethod(utils,
- "shouldSkipIdleRecoverForRecentDispatch",
- 10493,
- 148);
-
- assertTrue(Boolean.TRUE.equals(skipped));
- }
-
- @Test
- void checkStationOutOrder_skipsWhenActiveSessionAlreadyOwnsCurrentStation() {
- StationOperateProcessUtils utils = newUtils();
- 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);
- stubTaskDispatchLock(coordinator);
-
- stash(utils, "basDevpService", basDevpService);
- ReflectionTestUtils.setField(utils, "wrkMastService", wrkMastService);
- stash(utils, "stationMoveCoordinator", coordinator);
- stash(utils, "redisUtil", redisUtil);
- wireOutboundSupport(utils);
- wireRerouteProcessor(utils);
-
- 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);
- 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_RUNNING);
- 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();
-
- 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 = newUtils();
- 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);
- stubTaskDispatchLock(coordinator);
-
- stash(utils, "basDevpService", basDevpService);
- ReflectionTestUtils.setField(utils, "wrkMastService", wrkMastService);
- stash(utils, "stationMoveCoordinator", coordinator);
- stash(utils, "redisUtil", redisUtil);
- wireOutboundSupport(utils);
- wireRerouteProcessor(utils);
-
- 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);
- }
- }
-
- @Test
- void checkStationOutOrder_skipsRunBlockStationBeforePlanning() {
- StationOperateProcessUtils utils = newUtils();
- BasDevpService basDevpService = mock(BasDevpService.class);
- WrkMastService wrkMastService = mock(WrkMastService.class);
- RedisUtil redisUtil = mock(RedisUtil.class);
- StationThread stationThread = mock(StationThread.class);
-
- stash(utils, "basDevpService", basDevpService);
- ReflectionTestUtils.setField(utils, "wrkMastService", wrkMastService);
- stash(utils, "redisUtil", redisUtil);
- wireOutboundSupport(utils);
- wireRerouteProcessor(utils);
-
- 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(true);
- 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);
-
- when(redisUtil.get(anyString())).thenReturn(null);
-
- MessageQueue.init(SlaveType.Devp, 1);
- SlaveConnection.put(SlaveType.Devp, 1, stationThread);
- try {
- utils.checkStationOutOrder();
-
- 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 executePlan_runBlockReroute_reissuesWhenBlockedSessionMatchesCandidatePath() {
- StationOperateProcessUtils utils = newUtils();
- StationMoveCoordinator coordinator = mock(StationMoveCoordinator.class);
- RedisUtil redisUtil = mock(RedisUtil.class);
- stubTaskDispatchLock(coordinator);
- stash(utils, "stationMoveCoordinator", coordinator);
- stash(utils, "redisUtil", redisUtil);
- wireRerouteProcessor(utils);
-
- StationCommand command = new StationCommand();
- command.setTaskNo(100);
- command.setStationId(145);
- command.setTargetStaNo(111);
- command.setNavigatePath(List.of(145, 113, 112, 111));
- command.setOriginalNavigatePath(List.of(145, 113, 112, 111));
-
- StationMoveSession session = new StationMoveSession();
- session.setTaskNo(100);
- session.setStatus(StationMoveSession.STATUS_BLOCKED);
- session.setCurrentStationId(145);
- session.setDispatchStationId(145);
- session.setPathSignature("same-path");
- when(coordinator.loadSession(100)).thenReturn(session);
- when(coordinator.buildPathSignature(command)).thenReturn("same-path");
-
- RerouteContext context = RerouteContext.create(
- RerouteSceneType.RUN_BLOCK_REROUTE,
- buildBasDevp(1),
- mock(StationThread.class),
- buildStationProtocol(145, 100, 145),
- buildWrkMast(100, 111),
- Collections.emptyList(),
- 0.0d,
- "checkStationRunBlock_reroute"
- ).withCancelSessionBeforeDispatch()
- .withResetSegmentCommandsBeforeDispatch();
-
- MessageQueue.init(SlaveType.Devp, 1);
- try {
- RerouteExecutionResult result = utils.executeReroutePlan(
- context,
- RerouteCommandPlan.dispatch(
- command,
- RerouteDecision.proceed(111),
- "checkStationRunBlock_reroute"
- )
- );
-
- assertTrue(!result.skipped());
- org.mockito.InOrder inOrder = inOrder(coordinator);
- inOrder.verify(coordinator).markCancelPending(100, "reroute_pending");
- inOrder.verify(coordinator).cancelSession(100);
- verify(coordinator, times(1)).cancelSession(100);
- } finally {
- MessageQueue.clear(SlaveType.Devp, 1);
- }
- }
-
- @Test
- void executePlan_runBlockReroute_ignoresCurrentTaskBufferAfterReset() {
- StationOperateProcessUtils utils = newUtils();
- StationMoveCoordinator coordinator = mock(StationMoveCoordinator.class);
- RedisUtil redisUtil = mock(RedisUtil.class);
- stubTaskDispatchLock(coordinator);
- stash(utils, "stationMoveCoordinator", coordinator);
- stash(utils, "redisUtil", redisUtil);
- wireRerouteProcessor(utils);
-
- 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);
-
- RerouteContext context = RerouteContext.create(
- 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 {
- RerouteExecutionResult result = utils.executeReroutePlan(
- context,
- RerouteCommandPlan.dispatch(
- command,
- 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 = newUtils();
- StationMoveCoordinator coordinator = mock(StationMoveCoordinator.class);
- RedisUtil redisUtil = mock(RedisUtil.class);
- stubTaskDispatchLock(coordinator);
- stash(utils, "stationMoveCoordinator", coordinator);
- stash(utils, "redisUtil", redisUtil);
- wireRerouteProcessor(utils);
-
- 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);
-
- RerouteContext context = RerouteContext.create(
- 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 {
- RerouteExecutionResult result = utils.executeReroutePlan(
- context,
- RerouteCommandPlan.dispatch(
- command,
- 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 = 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);
-
- 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(basDevpService.list(any(com.baomidou.mybatisplus.core.conditions.Wrapper.class)))
- .thenReturn(Collections.singletonList(basDevp));
-
- StationProtocol stationProtocol = buildStationProtocol(101, 500670, 101);
- stationProtocol.setAutoing(true);
- stationProtocol.setLoading(true);
- stationProtocol.setBarcode("GSL110005");
- when(stationThread.getStatusMap()).thenReturn(Map.of(101, stationProtocol));
- when(stationThread.getStatus()).thenReturn(Collections.singletonList(stationProtocol));
-
- WrkMast wrkMast = buildWrkMast(500670, 102);
- wrkMast.setWrkSts(WrkStsType.NEW_INBOUND.sts);
- wrkMast.setLocNo("8-4-1");
- when(wrkMastService.getOne(any(com.baomidou.mybatisplus.core.conditions.Wrapper.class))).thenReturn(wrkMast);
- when(wrkMastService.updateById(wrkMast)).thenReturn(true);
-
- FindCrnNoResult findCrnNoResult = new FindCrnNoResult();
- findCrnNoResult.setCrnNo(4);
- findCrnNoResult.setCrnType(SlaveType.Crn);
- when(commonService.findCrnNoByLocNo("8-4-1")).thenReturn(findCrnNoResult);
- when(commonService.findInStationId(findCrnNoResult, 101)).thenReturn(102);
-
- StationCommand command = new StationCommand();
- command.setTaskNo(500670);
- command.setStationId(101);
- command.setTargetStaNo(102);
- 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);
- try {
- utils.stationInExecute();
-
- verify(coordinator, times(1)).recordDispatch(eq(500670), eq(101), eq("stationInExecute"), same(command), eq(false));
- } finally {
- MessageQueue.clear(SlaveType.Devp, 1);
- SlaveConnection.remove(SlaveType.Devp, 1);
- }
- }
-
- @Test
- 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);
- 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);
-
- 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.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);
-
- 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(145, 10335, 145);
- when(stationThread.getStatusMap()).thenReturn(Map.of(145, stationProtocol));
- when(stationThread.clearPath(10335)).thenReturn(true);
-
- SlaveConnection.put(SlaveType.Devp, 1, stationThread);
- try {
-
- 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 {
- SlaveConnection.remove(SlaveType.Devp, 1);
- }
- }
-
- @Test
- void watchCircleStation_usesSessionArrivalStateWhenLegacyCommandMissing() {
- StationOperateProcessUtils utils = newUtils();
- 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);
- stubTaskDispatchLock(coordinator);
-
- stash(utils, "basDevpService", basDevpService);
- ReflectionTestUtils.setField(utils, "wrkMastService", wrkMastService);
- 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)))
- .thenReturn(Collections.singletonList(basDevp));
-
- StationProtocol stationProtocol = buildStationProtocol(145, 10337, 148);
- stationProtocol.setAutoing(true);
- stationProtocol.setLoading(true);
- when(stationThread.getStatus()).thenReturn(Collections.singletonList(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_RUNNING);
- session.setDispatchMode(StationMoveDispatchMode.CIRCLE);
- session.setCurrentStationId(145);
- session.setDispatchStationId(145);
- session.setNextDecisionStationId(145);
- 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.watchCircleStation();
-
- 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);
- }
- }
-
- private static BasDevp buildBasDevp(int devpNo) {
- BasDevp basDevp = new BasDevp();
- basDevp.setDevpNo(devpNo);
- return basDevp;
- }
-
- private static WrkMast buildWrkMast(int wrkNo, int targetStationId) {
- WrkMast wrkMast = new WrkMast();
- wrkMast.setWrkNo(wrkNo);
- wrkMast.setStaNo(targetStationId);
- return wrkMast;
- }
-
- private static StationProtocol buildStationProtocol(int stationId,
- int taskNo,
- int targetStationId) {
- return buildStationProtocol(stationId, taskNo, targetStationId, Collections.emptyList());
- }
-
- private static StationProtocol buildStationProtocol(int stationId,
- int taskNo,
- int targetStationId,
- List<StationTaskBufferItem> taskBufferItems) {
- StationProtocol stationProtocol = new StationProtocol();
- stationProtocol.setStationId(stationId);
- stationProtocol.setTaskNo(taskNo);
- stationProtocol.setTargetStaNo(targetStationId);
- stationProtocol.setTaskBufferItems(taskBufferItems);
- return stationProtocol;
- }
-}
diff --git a/src/test/java/com/zy/core/utils/StationRerouteProcessorTest.java b/src/test/java/com/zy/core/utils/StationRerouteProcessorTest.java
deleted file mode 100644
index 744fcca..0000000
--- a/src/test/java/com/zy/core/utils/StationRerouteProcessorTest.java
+++ /dev/null
@@ -1,133 +0,0 @@
-package com.zy.core.utils;
-
-import com.zy.asrs.entity.BasDevp;
-import com.zy.asrs.entity.WrkMast;
-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.core.utils.station.StationRerouteProcessor;
-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 java.util.Collections;
-import java.util.List;
-
-import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.junit.jupiter.api.Assertions.assertSame;
-import static org.junit.jupiter.api.Assertions.assertThrows;
-import static org.junit.jupiter.api.Assertions.assertTrue;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
-
-class StationRerouteProcessorTest {
-
- @Test
- void rerouteProcessor_noLongerKeepsDispatcherFallbackHelper() {
- assertThrows(NoSuchMethodException.class,
- () -> StationRerouteProcessor.class.getDeclaredMethod("getStationCommandDispatcher"));
- }
-
- @Test
- void buildCommandPlan_usesRunBlockCommandBuilderForRunBlockScene() {
- StationRerouteProcessor processor = new StationRerouteProcessor();
- StationThread stationThread = mock(StationThread.class);
- StationCommand command = new StationCommand();
- command.setTaskNo(100);
- command.setStationId(10);
- command.setTargetStaNo(20);
- when(stationThread.getRunBlockRerouteCommand(100, 10, 20, 0, 0.25d)).thenReturn(command);
-
- RerouteContext context = RerouteContext.create(
- RerouteSceneType.RUN_BLOCK_REROUTE,
- buildBasDevp(1),
- stationThread,
- buildStationProtocol(10, 100, 10),
- buildWrkMast(100, 99),
- Collections.emptyList(),
- 0.25d,
- "checkStationRunBlock_reroute"
- ).withRunBlockCommand()
- .withCancelSessionBeforeDispatch()
- .withResetSegmentCommandsBeforeDispatch();
-
- RerouteCommandPlan plan = processor.buildRerouteCommandPlan(
- context,
- RerouteDecision.proceed(20)
- );
-
- verify(stationThread).getRunBlockRerouteCommand(100, 10, 20, 0, 0.25d);
- assertSame(command, plan.command());
- }
-
- @Test
- void executePlan_skipsWhenCurrentTaskStillExistsInBuffer() {
- StationRerouteProcessor processor = new StationRerouteProcessor();
- StationCommand command = new StationCommand();
- command.setTaskNo(100);
- command.setStationId(10);
- command.setTargetStaNo(20);
-
- StationTaskBufferItem bufferItem = new StationTaskBufferItem();
- bufferItem.setTaskNo(100);
-
- RerouteContext context = RerouteContext.create(
- RerouteSceneType.OUT_ORDER,
- buildBasDevp(1),
- mock(StationThread.class),
- buildStationProtocol(10, 100, 10, Collections.singletonList(bufferItem)),
- buildWrkMast(100, 20),
- List.of(10, 20),
- 0.0d,
- "checkStationOutOrder"
- );
-
- RerouteExecutionResult result = processor.executeReroutePlan(
- context,
- RerouteCommandPlan.dispatch(
- command,
- RerouteDecision.proceed(20),
- "checkStationOutOrder"
- )
- );
-
- assertTrue(result.skipped());
- assertEquals("buffer-has-current-task", result.skipReason());
- }
-
- private static BasDevp buildBasDevp(int devpNo) {
- BasDevp basDevp = new BasDevp();
- basDevp.setDevpNo(devpNo);
- return basDevp;
- }
-
- private static WrkMast buildWrkMast(int wrkNo, int targetStationId) {
- WrkMast wrkMast = new WrkMast();
- wrkMast.setWrkNo(wrkNo);
- wrkMast.setStaNo(targetStationId);
- return wrkMast;
- }
-
- private static StationProtocol buildStationProtocol(int stationId,
- int taskNo,
- int targetStationId) {
- return buildStationProtocol(stationId, taskNo, targetStationId, Collections.emptyList());
- }
-
- private static StationProtocol buildStationProtocol(int stationId,
- int taskNo,
- int targetStationId,
- List<StationTaskBufferItem> taskBufferItems) {
- StationProtocol stationProtocol = new StationProtocol();
- stationProtocol.setStationId(stationId);
- stationProtocol.setTaskNo(taskNo);
- stationProtocol.setTargetStaNo(targetStationId);
- stationProtocol.setTaskBufferItems(taskBufferItems);
- return stationProtocol;
- }
-}
diff --git a/src/test/java/com/zy/core/utils/station/StationDispatchRuntimeStateSupportTest.java b/src/test/java/com/zy/core/utils/station/StationDispatchRuntimeStateSupportTest.java
deleted file mode 100644
index 53d34ca..0000000
--- a/src/test/java/com/zy/core/utils/station/StationDispatchRuntimeStateSupportTest.java
+++ /dev/null
@@ -1,139 +0,0 @@
-package com.zy.core.utils.station;
-
-import com.alibaba.fastjson.JSON;
-import com.baomidou.mybatisplus.core.conditions.Wrapper;
-import com.zy.asrs.entity.BasStationOpt;
-import com.zy.asrs.service.BasStationOptService;
-import com.zy.common.utils.RedisUtil;
-import com.zy.core.enums.RedisKeyType;
-import com.zy.core.model.command.StationCommand;
-import org.junit.jupiter.api.Test;
-import org.springframework.test.util.ReflectionTestUtils;
-
-import java.util.Collections;
-import java.util.Date;
-import java.util.concurrent.atomic.AtomicReference;
-
-import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.junit.jupiter.api.Assertions.assertFalse;
-import static org.junit.jupiter.api.Assertions.assertNotNull;
-import static org.junit.jupiter.api.Assertions.assertTrue;
-import static org.mockito.ArgumentMatchers.eq;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
-
-class StationDispatchRuntimeStateSupportTest {
-
- @Test
- void idleTrack_isTimeoutUsesFirstSeenTime() {
- StationTaskIdleTrack track = new StationTaskIdleTrack(100, 145, System.currentTimeMillis() - 11_000L);
-
- assertTrue(track.isTimeout(10));
- }
-
- @Test
- void touchIdleTrack_replacesTrackWhenStationChanges() {
- StationDispatchRuntimeStateSupport support = new StationDispatchRuntimeStateSupport();
- RedisUtil redisUtil = mock(RedisUtil.class);
- ReflectionTestUtils.setField(support, "redisUtil", redisUtil);
- when(redisUtil.get(RedisKeyType.STATION_TASK_IDLE_TRACK_.key + 100))
- .thenReturn(JSON.toJSONString(new StationTaskIdleTrack(100, 145, System.currentTimeMillis() - 3_000L)));
-
- StationTaskIdleTrack track = support.touchIdleTrack(100, 146);
-
- assertEquals(146, track.getStationId());
- verify(redisUtil).set(eq(RedisKeyType.STATION_TASK_IDLE_TRACK_.key + 100), org.mockito.ArgumentMatchers.any(String.class), eq(3600L));
- }
-
- @Test
- void hasRecentIssuedMoveCommand_returnsTrueForRecentMoveLog() {
- StationDispatchRuntimeStateSupport support = new StationDispatchRuntimeStateSupport();
- BasStationOptService basStationOptService = mock(BasStationOptService.class);
- ReflectionTestUtils.setField(support, "basStationOptService", basStationOptService);
- when(basStationOptService.list(org.mockito.ArgumentMatchers.<Wrapper<BasStationOpt>>any()))
- .thenReturn(Collections.singletonList(new BasStationOpt()));
-
- boolean result = support.hasRecentIssuedMoveCommand(100, 145, 10_000L);
-
- assertTrue(result);
- }
-
- @Test
- void clearIssuedMoveCommandsDuringIdleStay_marksSendZeroAndAppendsMemo() {
- StationDispatchRuntimeStateSupport support = new StationDispatchRuntimeStateSupport();
- BasStationOptService basStationOptService = mock(BasStationOptService.class);
- ReflectionTestUtils.setField(support, "basStationOptService", basStationOptService);
- BasStationOpt opt = new BasStationOpt();
- opt.setId(1L);
- opt.setSend(1);
- opt.setMemo("existing");
- opt.setSendTime(new Date());
- when(basStationOptService.list(org.mockito.ArgumentMatchers.<Wrapper<BasStationOpt>>any()))
- .thenReturn(Collections.singletonList(opt));
-
- int clearedCount = support.clearIssuedMoveCommandsDuringIdleStay(
- new StationTaskIdleTrack(100, 145, System.currentTimeMillis() - 10_000L),
- 100,
- 145
- );
-
- assertEquals(1, clearedCount);
- assertEquals(0, opt.getSend());
- assertTrue(opt.getMemo().contains("existing"));
- assertTrue(opt.getMemo().contains("idleRecoverRerouteCleared(stationId=145)"));
- assertFalse(opt.getUpdateTime() == null);
- verify(basStationOptService).updateBatchById(Collections.singletonList(opt));
- }
-
- @Test
- void tryAcquireOutOrderDispatchLock_returnsFalseWhenKeyAlreadyExists() {
- StationDispatchRuntimeStateSupport support = new StationDispatchRuntimeStateSupport();
- RedisUtil redisUtil = mock(RedisUtil.class);
- ReflectionTestUtils.setField(support, "redisUtil", redisUtil);
- when(redisUtil.get(RedisKeyType.STATION_OUT_ORDER_DISPATCH_LIMIT_.key + "100_145")).thenReturn("lock");
-
- boolean acquired = support.tryAcquireOutOrderDispatchLock(100, 145, 2);
-
- assertFalse(acquired);
- }
-
- @Test
- void signalSegmentReset_setsAndClearsResetKey() {
- StationDispatchRuntimeStateSupport support = new StationDispatchRuntimeStateSupport();
- RedisUtil redisUtil = mock(RedisUtil.class);
- ReflectionTestUtils.setField(support, "redisUtil", redisUtil);
-
- support.signalSegmentReset(100, 0L);
-
- verify(redisUtil).set(RedisKeyType.DEVICE_STATION_MOVE_RESET.key + 100, "cancel", 3);
- verify(redisUtil).del(RedisKeyType.DEVICE_STATION_MOVE_RESET.key + 100);
- }
-
- @Test
- void watchCircleCommand_roundTripsThroughRedis() {
- StationDispatchRuntimeStateSupport support = new StationDispatchRuntimeStateSupport();
- RedisUtil redisUtil = mock(RedisUtil.class);
- ReflectionTestUtils.setField(support, "redisUtil", redisUtil);
- AtomicReference<Object> storedValue = new AtomicReference<>();
- when(redisUtil.get(RedisKeyType.WATCH_CIRCLE_STATION_.key + 100))
- .thenAnswer(invocation -> storedValue.get());
- when(redisUtil.set(eq(RedisKeyType.WATCH_CIRCLE_STATION_.key + 100), org.mockito.ArgumentMatchers.any(String.class), eq(60L * 60 * 24)))
- .thenAnswer(invocation -> {
- storedValue.set(invocation.getArgument(1));
- return true;
- });
-
- StationCommand command = new StationCommand();
- command.setTaskNo(100);
- command.setTargetStaNo(145);
-
- support.saveWatchCircleCommand(100, command);
- StationCommand loaded = support.loadWatchCircleCommand(100);
-
- assertNotNull(loaded);
- assertEquals(145, loaded.getTargetStaNo());
- support.clearWatchCircleCommand(100);
- verify(redisUtil).del(RedisKeyType.WATCH_CIRCLE_STATION_.key + 100);
- }
-}
diff --git a/src/test/java/com/zy/core/utils/station/StationOutboundDispatchProcessorTest.java b/src/test/java/com/zy/core/utils/station/StationOutboundDispatchProcessorTest.java
deleted file mode 100644
index b678efb..0000000
--- a/src/test/java/com/zy/core/utils/station/StationOutboundDispatchProcessorTest.java
+++ /dev/null
@@ -1,202 +0,0 @@
-package com.zy.core.utils.station;
-
-import com.zy.asrs.domain.enums.NotifyMsgType;
-import com.zy.asrs.entity.WrkMast;
-import com.zy.asrs.service.WrkAnalysisService;
-import com.zy.asrs.service.WrkMastService;
-import com.zy.asrs.utils.NotifyUtils;
-import com.zy.common.utils.RedisUtil;
-import com.zy.core.cache.SlaveConnection;
-import com.zy.core.dispatch.StationCommandDispatchResult;
-import com.zy.core.dispatch.StationCommandDispatcher;
-import com.zy.core.enums.RedisKeyType;
-import com.zy.core.enums.SlaveType;
-import com.zy.core.enums.WrkStsType;
-import com.zy.core.model.StationObjModel;
-import com.zy.core.model.command.StationCommand;
-import com.zy.core.model.protocol.StationProtocol;
-import com.zy.core.move.StationMoveCoordinator;
-import com.zy.core.thread.StationThread;
-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.OutOrderDispatchDecision;
-import org.junit.jupiter.api.Test;
-import org.springframework.test.util.ReflectionTestUtils;
-
-import java.util.Collections;
-import java.util.Date;
-import java.util.List;
-import java.util.Map;
-
-import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.ArgumentMatchers.anyString;
-import static org.mockito.ArgumentMatchers.eq;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.same;
-import static org.mockito.Mockito.times;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
-
-class StationOutboundDispatchProcessorTest {
-
- @Test
- void crnStationOutExecute_recordsDispatchSessionAndClearsStationCacheAfterIssuingMoveCommand() {
- StationOutboundDispatchProcessor processor = new StationOutboundDispatchProcessor();
- WrkMastService wrkMastService = mock(WrkMastService.class);
- WrkAnalysisService wrkAnalysisService = mock(WrkAnalysisService.class);
- RedisUtil redisUtil = mock(RedisUtil.class);
- StationMoveCoordinator coordinator = mock(StationMoveCoordinator.class);
- StationCommandDispatcher dispatcher = mock(StationCommandDispatcher.class);
- StationDispatchLoadSupport loadSupport = mock(StationDispatchLoadSupport.class);
- StationOutboundDecisionSupport decisionSupport = mock(StationOutboundDecisionSupport.class);
- StationThread stationThread = mock(StationThread.class);
-
- ReflectionTestUtils.setField(processor, "wrkMastService", wrkMastService);
- ReflectionTestUtils.setField(processor, "wrkAnalysisService", wrkAnalysisService);
- ReflectionTestUtils.setField(processor, "redisUtil", redisUtil);
- ReflectionTestUtils.setField(processor, "stationMoveCoordinator", coordinator);
- ReflectionTestUtils.setField(processor, "stationCommandDispatcher", dispatcher);
- ReflectionTestUtils.setField(processor, "stationDispatchLoadSupport", loadSupport);
- ReflectionTestUtils.setField(processor, "stationOutboundDecisionSupport", decisionSupport);
-
- WrkMast wrkMast = buildWrkMast(10001, 145);
- wrkMast.setWrkSts(WrkStsType.OUTBOUND_RUN_COMPLETE.sts);
- wrkMast.setCrnNo(4);
- when(wrkMastService.list(any(com.baomidou.mybatisplus.core.conditions.Wrapper.class)))
- .thenReturn(Collections.singletonList(wrkMast));
- when(wrkMastService.updateById(wrkMast)).thenReturn(true);
-
- StationObjModel stationObjModel = new StationObjModel();
- stationObjModel.setDeviceNo(1);
- stationObjModel.setStationId(101);
- when(redisUtil.get(RedisKeyType.CRN_OUT_TASK_COMPLETE_STATION_INFO.key + 10001))
- .thenReturn(com.alibaba.fastjson.JSON.toJSONString(stationObjModel));
- when(redisUtil.get(RedisKeyType.STATION_OUT_EXECUTE_LIMIT.key + 101)).thenReturn(null);
-
- StationProtocol stationProtocol = buildStationProtocol(101, 0, 101);
- stationProtocol.setAutoing(true);
- stationProtocol.setLoading(true);
- when(stationThread.getStatusMap()).thenReturn(Map.of(101, stationProtocol));
-
- DispatchLimitConfig limitConfig = new DispatchLimitConfig();
- LoadGuardState loadGuardState = new LoadGuardState();
- LoopHitResult noHit = LoopHitResult.noHit();
- OutOrderDispatchDecision decision = OutOrderDispatchDecision.direct(145);
- StationCommand command = buildCommand(10001, 101, 145);
-
- when(loadSupport.getDispatchLimitConfig(null, null)).thenReturn(limitConfig);
- when(loadSupport.countCurrentStationTask()).thenReturn(0);
- when(loadSupport.buildLoadGuardState(limitConfig)).thenReturn(loadGuardState);
- when(decisionSupport.getAllOutOrderList()).thenReturn(List.of(101, 121, 145));
- when(decisionSupport.resolveOutboundPathLenFactor(wrkMast)).thenReturn(0.25d);
- when(decisionSupport.resolveOutboundDispatchDecision(101, wrkMast, List.of(101, 121, 145), 0.25d)).thenReturn(decision);
- when(loadSupport.getDispatchLimitConfig(101, 145)).thenReturn(limitConfig);
- when(loadSupport.findPathLoopHit(limitConfig, 101, 145, loadGuardState, wrkMast, 0.25d)).thenReturn(noHit);
- when(loadSupport.isDispatchBlocked(limitConfig, 0, loadGuardState, false)).thenReturn(false);
- when(decisionSupport.buildOutboundMoveCommand(stationThread, wrkMast, 101, 145, 0.25d)).thenReturn(command);
- when(dispatcher.dispatch(1, command, "station-operate-process", "crnStationOutExecute"))
- .thenReturn(StationCommandDispatchResult.accepted("accepted", 1, "station-operate-process", "crnStationOutExecute"));
-
- SlaveConnection.put(SlaveType.Devp, 1, stationThread);
- try {
- processor.crnStationOutExecute();
-
- verify(wrkAnalysisService, times(1)).markOutboundStationStart(eq(wrkMast), any(Date.class));
- verify(coordinator, times(1)).recordDispatch(eq(10001), eq(101), eq("crnStationOutExecute"), same(command), eq(false));
- verify(redisUtil, times(1)).set(eq(RedisKeyType.STATION_OUT_EXECUTE_LIMIT.key + 101), eq("lock"), eq(5L));
- verify(redisUtil, times(1)).del(RedisKeyType.CRN_OUT_TASK_COMPLETE_STATION_INFO.key + 10001);
- verify(loadSupport, times(1)).saveLoopLoadReserve(10001, noHit);
- assertEquals(WrkStsType.STATION_RUN.sts, wrkMast.getWrkSts());
- } finally {
- SlaveConnection.remove(SlaveType.Devp, 1);
- }
- }
-
- @Test
- void dualCrnStationOutExecute_recordsDispatchSessionAndClearsDualCacheAfterIssuingMoveCommand() {
- StationOutboundDispatchProcessor processor = new StationOutboundDispatchProcessor();
- WrkMastService wrkMastService = mock(WrkMastService.class);
- RedisUtil redisUtil = mock(RedisUtil.class);
- StationMoveCoordinator coordinator = mock(StationMoveCoordinator.class);
- StationCommandDispatcher dispatcher = mock(StationCommandDispatcher.class);
- NotifyUtils notifyUtils = mock(NotifyUtils.class);
- StationOutboundDecisionSupport decisionSupport = mock(StationOutboundDecisionSupport.class);
- StationThread stationThread = mock(StationThread.class);
-
- ReflectionTestUtils.setField(processor, "wrkMastService", wrkMastService);
- ReflectionTestUtils.setField(processor, "redisUtil", redisUtil);
- ReflectionTestUtils.setField(processor, "stationMoveCoordinator", coordinator);
- ReflectionTestUtils.setField(processor, "stationCommandDispatcher", dispatcher);
- ReflectionTestUtils.setField(processor, "notifyUtils", notifyUtils);
- ReflectionTestUtils.setField(processor, "stationOutboundDecisionSupport", decisionSupport);
-
- WrkMast wrkMast = buildWrkMast(10002, 188);
- wrkMast.setWrkSts(WrkStsType.OUTBOUND_RUN_COMPLETE.sts);
- wrkMast.setDualCrnNo(2);
- when(wrkMastService.list(any(com.baomidou.mybatisplus.core.conditions.Wrapper.class)))
- .thenReturn(Collections.singletonList(wrkMast));
- when(wrkMastService.updateById(wrkMast)).thenReturn(true);
-
- StationObjModel stationObjModel = new StationObjModel();
- stationObjModel.setDeviceNo(1);
- stationObjModel.setStationId(121);
- when(redisUtil.get(RedisKeyType.DUAL_CRN_OUT_TASK_STATION_INFO.key + 10002))
- .thenReturn(com.alibaba.fastjson.JSON.toJSONString(stationObjModel));
- when(redisUtil.get(RedisKeyType.STATION_OUT_EXECUTE_LIMIT.key + 121)).thenReturn(null);
-
- StationProtocol stationProtocol = buildStationProtocol(121, 0, 121);
- stationProtocol.setAutoing(true);
- stationProtocol.setLoading(true);
- when(stationThread.getStatusMap()).thenReturn(Map.of(121, stationProtocol));
-
- StationCommand command = buildCommand(10002, 121, 188);
- when(decisionSupport.resolveOutboundPathLenFactor(wrkMast)).thenReturn(0.5d);
- when(decisionSupport.buildOutboundMoveCommand(stationThread, wrkMast, 121, 188, 0.5d)).thenReturn(command);
- when(dispatcher.dispatch(1, command, "station-operate-process", "dualCrnStationOutExecute"))
- .thenReturn(StationCommandDispatchResult.accepted("accepted", 1, "station-operate-process", "dualCrnStationOutExecute"));
-
- SlaveConnection.put(SlaveType.Devp, 1, stationThread);
- try {
- processor.dualCrnStationOutExecute();
-
- verify(coordinator, times(1)).recordDispatch(eq(10002), eq(121), eq("dualCrnStationOutExecute"), same(command), eq(false));
- verify(notifyUtils, times(1)).notify(String.valueOf(SlaveType.Devp), 1, "10002", wrkMast.getWmsWrkNo(), NotifyMsgType.STATION_OUT_TASK_RUN, null);
- verify(redisUtil, times(1)).set(eq(RedisKeyType.STATION_OUT_EXECUTE_LIMIT.key + 121), eq("lock"), eq(5L));
- verify(redisUtil, times(1)).del(RedisKeyType.DUAL_CRN_OUT_TASK_STATION_INFO.key + 10002);
- assertEquals(WrkStsType.STATION_RUN.sts, wrkMast.getWrkSts());
- } finally {
- SlaveConnection.remove(SlaveType.Devp, 1);
- }
- }
-
- private static WrkMast buildWrkMast(int wrkNo, int targetStationId) {
- WrkMast wrkMast = new WrkMast();
- wrkMast.setWrkNo(wrkNo);
- wrkMast.setStaNo(targetStationId);
- wrkMast.setWmsWrkNo("WMS-" + wrkNo);
- wrkMast.setIoTime(new Date());
- return wrkMast;
- }
-
- private static StationProtocol buildStationProtocol(int stationId,
- int taskNo,
- int targetStationId) {
- StationProtocol stationProtocol = new StationProtocol();
- stationProtocol.setStationId(stationId);
- stationProtocol.setTaskNo(taskNo);
- stationProtocol.setTargetStaNo(targetStationId);
- return stationProtocol;
- }
-
- private static StationCommand buildCommand(int wrkNo,
- int stationId,
- int targetStationId) {
- StationCommand command = new StationCommand();
- command.setTaskNo(wrkNo);
- command.setStationId(stationId);
- command.setTargetStaNo(targetStationId);
- return command;
- }
-}
diff --git a/src/test/java/com/zy/core/utils/station/StationRegularDispatchProcessorTest.java b/src/test/java/com/zy/core/utils/station/StationRegularDispatchProcessorTest.java
deleted file mode 100644
index a862ffd..0000000
--- a/src/test/java/com/zy/core/utils/station/StationRegularDispatchProcessorTest.java
+++ /dev/null
@@ -1,240 +0,0 @@
-package com.zy.core.utils.station;
-
-import com.zy.asrs.domain.enums.NotifyMsgType;
-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.WrkAnalysisService;
-import com.zy.asrs.service.WrkMastService;
-import com.zy.asrs.utils.NotifyUtils;
-import com.zy.common.entity.FindCrnNoResult;
-import com.zy.common.service.CommonService;
-import com.zy.common.utils.RedisUtil;
-import com.zy.core.cache.SlaveConnection;
-import com.zy.core.dispatch.StationCommandDispatchResult;
-import com.zy.core.dispatch.StationCommandDispatcher;
-import com.zy.core.enums.RedisKeyType;
-import com.zy.core.enums.SlaveType;
-import com.zy.core.enums.WrkStsType;
-import com.zy.core.model.command.StationCommand;
-import com.zy.core.model.protocol.StationProtocol;
-import com.zy.core.move.StationMoveCoordinator;
-import com.zy.core.thread.StationThread;
-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 org.junit.jupiter.api.Test;
-import org.springframework.test.util.ReflectionTestUtils;
-
-import java.util.Collections;
-import java.util.Date;
-import java.util.List;
-import java.util.Map;
-import java.util.Objects;
-
-import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.ArgumentMatchers.anyString;
-import static org.mockito.ArgumentMatchers.eq;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.never;
-import static org.mockito.Mockito.same;
-import static org.mockito.Mockito.times;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
-
-class StationRegularDispatchProcessorTest {
-
- @Test
- void stationInExecute_recordsDispatchSessionAfterIssuingMoveCommand() {
- StationRegularDispatchProcessor processor = new StationRegularDispatchProcessor();
- 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);
-
- 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);
-
- BasDevp basDevp = buildBasDevp(1);
- basDevp.setBarcodeStationList("[{\"deviceNo\":1,\"stationId\":101}]");
- when(basDevpService.list(any(com.baomidou.mybatisplus.core.conditions.Wrapper.class)))
- .thenReturn(Collections.singletonList(basDevp));
-
- StationProtocol stationProtocol = buildStationProtocol(101, 500670, 101);
- stationProtocol.setAutoing(true);
- stationProtocol.setLoading(true);
- stationProtocol.setBarcode("GSL110005");
- when(stationThread.getStatusMap()).thenReturn(Map.of(101, stationProtocol));
-
- WrkMast wrkMast = buildWrkMast(500670, 102);
- wrkMast.setWrkSts(WrkStsType.NEW_INBOUND.sts);
- wrkMast.setLocNo("8-4-1");
- when(wrkMastService.getOne(any(com.baomidou.mybatisplus.core.conditions.Wrapper.class))).thenReturn(wrkMast);
- when(wrkMastService.updateById(wrkMast)).thenReturn(true);
-
- FindCrnNoResult findCrnNoResult = new FindCrnNoResult();
- findCrnNoResult.setCrnNo(4);
- findCrnNoResult.setCrnType(SlaveType.Crn);
- when(commonService.findCrnNoByLocNo("8-4-1")).thenReturn(findCrnNoResult);
- when(commonService.findInStationId(findCrnNoResult, 101)).thenReturn(102);
-
- StationCommand command = new StationCommand();
- command.setTaskNo(500670);
- command.setStationId(101);
- command.setTargetStaNo(102);
- 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);
-
- SlaveConnection.put(SlaveType.Devp, 1, stationThread);
- try {
- processor.stationInExecute();
-
- verify(coordinator, times(1)).recordDispatch(eq(500670), eq(101), eq("stationInExecute"), same(command), eq(false));
- verify(redisUtil, times(1)).set(eq(RedisKeyType.STATION_IN_EXECUTE_LIMIT.key + 101), eq("lock"), eq(5L));
- verify(loadSupport, times(1)).saveLoopLoadReserve(500670, noHit);
- } finally {
- SlaveConnection.remove(SlaveType.Devp, 1);
- }
- }
-
- @Test
- void stationOutExecuteFinish_attemptsClearPathBeforeCompletingTask() {
- StationRegularDispatchProcessor processor = new StationRegularDispatchProcessor();
- WrkMastService wrkMastService = mock(WrkMastService.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);
-
- 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);
-
- WrkMast wrkMast = buildWrkMast(10335, 145);
- 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);
-
- 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(145, 10335, 145);
- when(stationThread.getStatusMap()).thenReturn(Map.of(145, stationProtocol));
- when(stationThread.clearPath(10335)).thenReturn(true);
-
- SlaveConnection.put(SlaveType.Devp, 1, stationThread);
- try {
- processor.stationOutExecuteFinish();
-
- verify(stationThread, times(1)).clearPath(10335);
- verify(coordinator, times(1)).finishSession(10335);
- verify(wrkMastService, times(1)).updateById(wrkMast);
- verify(notifyUtils, times(1)).notify(String.valueOf(SlaveType.Devp), 1, "10335", wrkMast.getWmsWrkNo(), NotifyMsgType.STATION_OUT_TASK_RUN_COMPLETE, null);
- assertEquals(WrkStsType.STATION_RUN_COMPLETE.sts, wrkMast.getWrkSts());
- } finally {
- SlaveConnection.remove(SlaveType.Devp, 1);
- }
- }
-
- @Test
- void checkTaskToComplete_marksTaskCompleteAfterLeavingTargetStation() {
- StationRegularDispatchProcessor processor = new StationRegularDispatchProcessor();
- WrkMastService wrkMastService = mock(WrkMastService.class);
- BasStationService basStationService = mock(BasStationService.class);
- StationMoveCoordinator coordinator = mock(StationMoveCoordinator.class);
- RedisUtil redisUtil = mock(RedisUtil.class);
- StationThread stationThread = mock(StationThread.class);
-
- ReflectionTestUtils.setField(processor, "wrkMastService", wrkMastService);
- ReflectionTestUtils.setField(processor, "basStationService", basStationService);
- ReflectionTestUtils.setField(processor, "stationMoveCoordinator", coordinator);
- ReflectionTestUtils.setField(processor, "redisUtil", redisUtil);
-
- WrkMast wrkMast = buildWrkMast(10335, 145);
- wrkMast.setWrkSts(WrkStsType.STATION_RUN_COMPLETE.sts);
- when(wrkMastService.list(any(com.baomidou.mybatisplus.core.conditions.Wrapper.class)))
- .thenReturn(Collections.singletonList(wrkMast));
-
- 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(145, 0, 145);
- when(stationThread.getStatusMap()).thenReturn(Map.of(145, stationProtocol));
- when(redisUtil.get(anyString())).thenReturn(null);
-
- SlaveConnection.put(SlaveType.Devp, 1, stationThread);
- try {
- processor.checkTaskToComplete();
-
- verify(coordinator, times(1)).finishSession(10335);
- verify(wrkMastService, times(1)).updateById(wrkMast);
- assertEquals(WrkStsType.COMPLETE_OUTBOUND.sts, wrkMast.getWrkSts());
- } finally {
- SlaveConnection.remove(SlaveType.Devp, 1);
- }
- }
-
- private static BasDevp buildBasDevp(int devpNo) {
- BasDevp basDevp = new BasDevp();
- basDevp.setDevpNo(devpNo);
- return basDevp;
- }
-
- private static WrkMast buildWrkMast(int wrkNo, int targetStationId) {
- WrkMast wrkMast = new WrkMast();
- wrkMast.setWrkNo(wrkNo);
- wrkMast.setStaNo(targetStationId);
- wrkMast.setWmsWrkNo("WMS-" + wrkNo);
- wrkMast.setIoTime(new Date());
- return wrkMast;
- }
-
- private static StationProtocol buildStationProtocol(int stationId,
- int taskNo,
- int targetStationId) {
- StationProtocol stationProtocol = new StationProtocol();
- stationProtocol.setStationId(stationId);
- stationProtocol.setTaskNo(taskNo);
- stationProtocol.setTargetStaNo(targetStationId);
- return stationProtocol;
- }
-}
diff --git a/src/test/java/com/zy/core/utils/station/model/StationModelTypePlacementTest.java b/src/test/java/com/zy/core/utils/station/model/StationModelTypePlacementTest.java
deleted file mode 100644
index 5d472e8..0000000
--- a/src/test/java/com/zy/core/utils/station/model/StationModelTypePlacementTest.java
+++ /dev/null
@@ -1,49 +0,0 @@
-package com.zy.core.utils.station.model;
-
-import com.zy.core.utils.StationOperateProcessUtils;
-import com.zy.core.utils.station.StationDispatchLoadSupport;
-import com.zy.core.utils.station.StationOutboundDecisionSupport;
-import com.zy.core.utils.station.StationRerouteProcessor;
-import org.junit.jupiter.api.Test;
-
-import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.junit.jupiter.api.Assertions.assertFalse;
-
-class StationModelTypePlacementTest {
-
- @Test
- void rerouteTypes_areNoLongerNestedInsideStationOperateProcessUtils() {
- assertFalse(hasDeclaredClass(StationOperateProcessUtils.class, "RerouteSceneType"));
- assertFalse(hasDeclaredClass(StationOperateProcessUtils.class, "RerouteDecision"));
- assertFalse(hasDeclaredClass(StationOperateProcessUtils.class, "RerouteContext"));
- assertFalse(hasDeclaredClass(StationOperateProcessUtils.class, "RerouteCommandPlan"));
- assertFalse(hasDeclaredClass(StationOperateProcessUtils.class, "RerouteExecutionResult"));
- }
-
- @Test
- void dispatchLoadTypes_areNoLongerNestedInsideStationDispatchLoadSupport() {
- assertFalse(hasDeclaredClass(StationDispatchLoadSupport.class, "DispatchLimitConfig"));
- assertFalse(hasDeclaredClass(StationDispatchLoadSupport.class, "LoadGuardState"));
- assertFalse(hasDeclaredClass(StationDispatchLoadSupport.class, "LoopHitResult"));
- }
-
- @Test
- void outboundDecisionTypes_areNoLongerNestedInsideStationOutboundDecisionSupport() {
- assertFalse(hasDeclaredClass(StationOutboundDecisionSupport.class, "OutOrderDispatchDecision"));
- assertFalse(hasDeclaredClass(StationOutboundDecisionSupport.class, "CircleTargetCandidate"));
- }
-
- @Test
- void rerouteProcessor_isLocatedUnderStationPackage() {
- assertEquals("com.zy.core.utils.station", StationRerouteProcessor.class.getPackageName());
- }
-
- private static boolean hasDeclaredClass(Class<?> ownerType, String simpleName) {
- for (Class<?> declaredClass : ownerType.getDeclaredClasses()) {
- if (simpleName.equals(declaredClass.getSimpleName())) {
- return true;
- }
- }
- return false;
- }
-}
--
Gitblit v1.9.1