From 63b01db83d9aad8a15276b4236a9a22e4aeef065 Mon Sep 17 00:00:00 2001
From: Junjie <fallin.jie@qq.com>
Date: 星期二, 05 五月 2026 12:30:59 +0800
Subject: [PATCH] # Agent数据分析V3.0.1.7
---
src/test/java/com/zy/ai/service/impl/AutoTuneSnapshotServiceImplTest.java | 144 ++++++++++++++++++++++++++++++++++++++++++++++--
1 files changed, 138 insertions(+), 6 deletions(-)
diff --git a/src/test/java/com/zy/ai/service/impl/AutoTuneSnapshotServiceImplTest.java b/src/test/java/com/zy/ai/service/impl/AutoTuneSnapshotServiceImplTest.java
index 5aba3a8..46b35d1 100644
--- a/src/test/java/com/zy/ai/service/impl/AutoTuneSnapshotServiceImplTest.java
+++ b/src/test/java/com/zy/ai/service/impl/AutoTuneSnapshotServiceImplTest.java
@@ -2,14 +2,25 @@
import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
+import com.zy.ai.domain.autotune.AutoTuneRoutePressureSnapshot;
import com.zy.ai.domain.autotune.AutoTuneRuleSnapshotItem;
+import com.zy.ai.domain.autotune.AutoTuneSnapshot;
+import com.zy.ai.domain.autotune.AutoTuneStationRuntimeItem;
+import com.zy.ai.domain.autotune.AutoTuneTaskDetailItem;
+import com.zy.ai.domain.autotune.AutoTuneTaskSnapshot;
+import com.zy.ai.service.FlowTopologySnapshotService;
+import com.zy.ai.service.RoutePressureSnapshotService;
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.WrkMastService;
+import com.zy.core.enums.WrkIoType;
+import com.zy.core.enums.WrkStsType;
import com.zy.core.model.StationObjModel;
+import com.zy.core.model.protocol.StationProtocol;
+import com.zy.system.service.ConfigService;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.ArgumentCaptor;
@@ -22,6 +33,7 @@
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertSame;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock;
@@ -35,7 +47,11 @@
@BeforeEach
void setUp() {
+ ConfigService configService = mock(ConfigService.class);
service = new AutoTuneSnapshotServiceImpl();
+ ReflectionTestUtils.setField(service, "configService", configService);
+ ReflectionTestUtils.setField(service, "autoTuneControlModeService",
+ new AutoTuneControlModeServiceImpl(configService));
}
@Test
@@ -67,23 +83,30 @@
}
@Test
- void buildRuleSnapshotExposesStepRangeCooldownAndDynamicMaxSource() {
+ void buildRuleSnapshotExposesStepRangeCooldownAndRiskNote() {
List<AutoTuneRuleSnapshotItem> result = service.buildRuleSnapshot();
AutoTuneRuleSnapshotItem stationOutTaskRule = findRule(result, "station", "outTaskLimit");
assertEquals(0, stationOutTaskRule.getMinValue());
assertNull(stationOutTaskRule.getMaxValue());
- assertEquals(1, stationOutTaskRule.getMaxStep());
+ assertEquals(3, stationOutTaskRule.getMaxStep());
assertEquals(10, stationOutTaskRule.getCooldownMinutes());
- assertEquals(Boolean.TRUE, stationOutTaskRule.getDynamicMaxValue());
- assertEquals("currentParameterSnapshot.stationOutBufferCapacities[targetId]",
- stationOutTaskRule.getDynamicMaxSource());
+ assertEquals(Boolean.FALSE, stationOutTaskRule.getDynamicMaxValue());
+ assertNull(stationOutTaskRule.getDynamicMaxSource());
+ assertEquals("鍗曟璋冩暣骞呭害涓嶈兘瓒呰繃 maxStep锛沷utBufferCapacity 浠h〃鍑哄簱绔欑紦瀛樹綅缃暟閲忥紝瓒呰繃璇ュ閲忓彲鑳戒娇浠诲姟鍑虹幇鍦ㄤ富骞查亾锛屼粎浣滀负椋庨櫓鍙傝�冿紝涓嶆槸鍚堟硶鎬т笂闄愩��",
+ stationOutTaskRule.getNote());
AutoTuneRuleSnapshotItem crnMaxOutRule = findRule(result, "crn", "maxOutTask");
assertEquals(3, crnMaxOutRule.getMaxStep());
+ assertNull(crnMaxOutRule.getDynamicMaxSource());
+ assertEquals("鍗曟璋冩暣骞呭害涓嶈兘瓒呰繃 maxStep銆�", crnMaxOutRule.getNote());
AutoTuneRuleSnapshotItem crnMaxInRule = findRule(result, "crn", "maxInTask");
- assertEquals(1, crnMaxInRule.getMaxStep());
+ assertEquals(3, crnMaxInRule.getMaxStep());
+
+ assertRuleMaxStep(result, "sys_config", "crnOutBatchRunningLimit", 3);
+ assertRuleMaxStep(result, "dual_crn", "maxOutTask", 3);
+ assertRuleMaxStep(result, "dual_crn", "maxInTask", 3);
}
@Test
@@ -100,6 +123,74 @@
String normalizedSqlSegment = sqlSegment.replaceAll("\\s+", " ");
assertTrue(normalizedSqlSegment.contains("(wrk_sts NOT IN"));
assertTrue(normalizedSqlSegment.contains("OR wrk_sts IS NULL"));
+ }
+
+ @Test
+ void buildTaskSnapshotExposesStationLimitBlockedTasksAndOutboundOrder() {
+ WrkMastService wrkMastService = mock(WrkMastService.class);
+ when(wrkMastService.list(any(Wrapper.class))).thenReturn(Arrays.asList(
+ outboundTask(190264, WrkStsType.STATION_RUN.sts, 101, 1,
+ "MANUAL_OUT_20260427181201", 9, ""),
+ outboundTask(190263, WrkStsType.NEW_OUTBOUND.sts, 101, 1,
+ "MANUAL_OUT_20260427181201", 8,
+ "鐩爣鍑哄簱绔�:101 宸茶揪鍑哄簱浠诲姟涓婇檺锛屽綋鍓�=1锛屼笂闄�=1")
+ ));
+ ReflectionTestUtils.setField(service, "wrkMastService", wrkMastService);
+
+ AutoTuneTaskSnapshot snapshot = ReflectionTestUtils.invokeMethod(service, "buildTaskSnapshot");
+
+ assertEquals(2, snapshot.getActiveTaskCount());
+ assertEquals(1, snapshot.getByStatus().get("101"));
+ assertEquals(1, snapshot.getByStatus().get("104"));
+
+ List<AutoTuneTaskDetailItem> blockedTasks = snapshot.getStationLimitBlockedTasks();
+ assertEquals(1, blockedTasks.size());
+ assertEquals(190263, blockedTasks.get(0).getWrkNo());
+ assertEquals("鐢熸垚鍑哄簱浠诲姟", blockedTasks.get(0).getWrkStsDesc());
+ assertTrue(blockedTasks.get(0).getSystemMsg().contains("鍑哄簱浠诲姟涓婇檺"));
+
+ List<AutoTuneTaskDetailItem> outboundSamples = snapshot.getOutboundTaskSamples();
+ assertEquals(2, outboundSamples.size());
+ assertEquals(190263, outboundSamples.get(0).getWrkNo());
+ assertEquals(8, outboundSamples.get(0).getBatchSeq());
+ assertEquals(190264, outboundSamples.get(1).getWrkNo());
+ assertEquals(9, outboundSamples.get(1).getBatchSeq());
+ }
+
+ @Test
+ void buildSnapshotIncludesRoutePressureSnapshot() {
+ WrkMastService wrkMastService = mock(WrkMastService.class);
+ FlowTopologySnapshotService flowTopologySnapshotService = mock(FlowTopologySnapshotService.class);
+ RoutePressureSnapshotService routePressureSnapshotService = mock(RoutePressureSnapshotService.class);
+ AutoTuneRoutePressureSnapshot routePressureSnapshot = new AutoTuneRoutePressureSnapshot();
+ List<WrkMast> activeTasks = Collections.singletonList(
+ outboundTask(190263, WrkStsType.NEW_OUTBOUND.sts, 101, 1,
+ "BATCH", 8, "鐩爣鍑哄簱绔�:101 宸茶揪鍑哄簱浠诲姟涓婇檺锛屽綋鍓�=1锛屼笂闄�=1")
+ );
+ when(wrkMastService.list(any(Wrapper.class))).thenReturn(activeTasks);
+ when(flowTopologySnapshotService.buildSnapshot(any())).thenReturn(Collections.emptyList());
+ when(routePressureSnapshotService.buildSnapshot(any(), any(), any())).thenReturn(routePressureSnapshot);
+ ReflectionTestUtils.setField(service, "wrkMastService", wrkMastService);
+ ReflectionTestUtils.setField(service, "flowTopologySnapshotService", flowTopologySnapshotService);
+ ReflectionTestUtils.setField(service, "routePressureSnapshotService", routePressureSnapshotService);
+
+ AutoTuneSnapshot snapshot = service.buildSnapshot();
+
+ assertSame(routePressureSnapshot, snapshot.getRoutePressureSnapshot());
+ assertEquals(1, snapshot.getTaskSnapshot().getActiveTaskCount());
+
+ ArgumentCaptor<List<WrkMast>> activeTasksCaptor = ArgumentCaptor.forClass(List.class);
+ ArgumentCaptor<AutoTuneTaskSnapshot> taskSnapshotCaptor = ArgumentCaptor.forClass(AutoTuneTaskSnapshot.class);
+ ArgumentCaptor<List<AutoTuneStationRuntimeItem>> stationRuntimeCaptor = ArgumentCaptor.forClass(List.class);
+ verify(routePressureSnapshotService).buildSnapshot(
+ activeTasksCaptor.capture(),
+ taskSnapshotCaptor.capture(),
+ stationRuntimeCaptor.capture()
+ );
+ assertSame(activeTasks, activeTasksCaptor.getValue());
+ assertSame(snapshot.getTaskSnapshot(), taskSnapshotCaptor.getValue());
+ assertSame(snapshot.getStationRuntimeSnapshot(), stationRuntimeCaptor.getValue());
+ verify(wrkMastService).list(any(Wrapper.class));
}
@Test
@@ -146,6 +237,20 @@
verify(basStationService, never()).list(any(Wrapper.class));
}
+ @Test
+ void toRuntimeItemExposesRunBlockForRoutePressure() {
+ StationProtocol protocol = new StationProtocol();
+ protocol.setStationId(101);
+ protocol.setAutoing(true);
+ protocol.setLoading(false);
+ protocol.setTaskNo(0);
+ protocol.setRunBlock(true);
+
+ AutoTuneStationRuntimeItem item = ReflectionTestUtils.invokeMethod(service, "toRuntimeItem", protocol);
+
+ assertEquals(1, item.getRunBlock());
+ }
+
private BasStation station(Integer stationId, Integer outTaskLimit) {
return station(stationId, outTaskLimit, null);
}
@@ -156,6 +261,25 @@
station.setOutTaskLimit(outTaskLimit);
station.setOutBufferCapacity(outBufferCapacity);
return station;
+ }
+
+ private WrkMast outboundTask(Integer wrkNo,
+ long wrkSts,
+ Integer stationNo,
+ Integer crnNo,
+ String batch,
+ Integer batchSeq,
+ String systemMsg) {
+ WrkMast wrkMast = new WrkMast();
+ wrkMast.setWrkNo(wrkNo);
+ wrkMast.setWrkSts(wrkSts);
+ wrkMast.setIoType(WrkIoType.OUT.id);
+ wrkMast.setStaNo(stationNo);
+ wrkMast.setCrnNo(crnNo);
+ wrkMast.setBatch(batch);
+ wrkMast.setBatchSeq(batchSeq);
+ wrkMast.setSystemMsg(systemMsg);
+ return wrkMast;
}
private BasDevp basDevp(Integer devpNo, Integer... stationIds) {
@@ -187,4 +311,12 @@
}
throw new AssertionError("rule not found: " + targetType + "/" + targetKey);
}
+
+ private void assertRuleMaxStep(List<AutoTuneRuleSnapshotItem> rules,
+ String targetType,
+ String targetKey,
+ int expectedMaxStep) {
+ AutoTuneRuleSnapshotItem rule = findRule(rules, targetType, targetKey);
+ assertEquals(expectedMaxStep, rule.getMaxStep());
+ }
}
--
Gitblit v1.9.1