feat(collect-channel): 采集执行方按单判定并随 /parse 落库
「这一单交本机还是线上」原先是全局 yml aiimage.collect-routing.local-enabled, 一台服务器一个值,把同机所有账号捆成同一个执行方:本机开着的用户被迫走线上, 跑 Linux 兜底的用户也没法把某一单留在本机。现改为建单时逐单登记 biz_file_task.collect_channel(V183,可空=按模块默认),全局开关只留兜底窗口。 - 列可空且不回填:空值按模块默认解释,APPEARANCE_PATENT/SIMILAR_ASIN 读作 LOCAL、 其余读作 ONLINE,与撤掉的 AIIMAGE_COLLECT_LOCAL_* 出厂值逐字节等价, 历史单与未升级前端行为不变。 - TaskRetryCloneSupport.buildChild 必须继承通道:原单选了线上,重试掉回模块默认 等于悄悄换执行方。 - CollectChannel 用逐值比对而非 valueOf+catch 判「不可识别」:后者会把静默 catch 总数顶过 CatchSilenceRatchetTest 上限 1057。 - 两支建单快照 golden 随 collect_channel 键重建(只多出 collectChannel=null)。
This commit is contained in:
+31
-17
@@ -1,38 +1,52 @@
|
||||
package com.nanri.aiimage.config;
|
||||
|
||||
import com.nanri.aiimage.modules.task.model.CollectChannel;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
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.assertNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
/**
|
||||
* 采集路由开关的判定口径(2026-10-29):
|
||||
* 只对 local-enabled 里点名的模块生效,未登记模块一律「非本地」——新模块不能被默认卷进本地优先;
|
||||
* 采集路由的判定口径(2026-10-31 改为任务级通道):
|
||||
* 执行方由 {@code biz_file_task.collect_channel} 这一单自己说,全局 {@code local-enabled} 已撤;
|
||||
* 未登记通道的行按模块默认解释——外观专利/货源默认本机,其余模块默认线上,
|
||||
* 与撤掉的那个全局开关的出厂值(true)逐字等价,历史任务与旧客户端行为不变。
|
||||
* 兜底窗口下限 1 分钟,配 0/负数不许静默变成「Linux 立刻抢」。
|
||||
*/
|
||||
class CollectRoutingPropertiesTest {
|
||||
|
||||
@Test
|
||||
void 点名的模块按配置返回且大小写不敏感() {
|
||||
CollectRoutingProperties properties = new CollectRoutingProperties();
|
||||
properties.setLocalEnabled(Map.of("APPEARANCE_PATENT", true, "SIMILAR_ASIN", false));
|
||||
void 默认通道只对专利与货源是本机() {
|
||||
assertTrue(CollectChannel.defaultFor(CollectRoutingProperties.MODULE_APPEARANCE_PATENT).isLocal());
|
||||
assertTrue(CollectChannel.defaultFor("appearance_patent").isLocal(), "模块名大小写不应影响判定");
|
||||
assertTrue(CollectChannel.defaultFor(CollectRoutingProperties.MODULE_SIMILAR_ASIN).isLocal());
|
||||
|
||||
assertTrue(properties.isLocal("APPEARANCE_PATENT"));
|
||||
assertTrue(properties.isLocal("appearance_patent"), "模块名大小写不应影响判定");
|
||||
assertFalse(properties.isLocal("SIMILAR_ASIN"));
|
||||
assertEquals(CollectChannel.ONLINE, CollectChannel.defaultFor("COLLECT_DATA"),
|
||||
"没点名的模块必须保持 Linux 原有等待窗口,不能被默认卷进本机优先");
|
||||
assertEquals(CollectChannel.ONLINE, CollectChannel.defaultFor(null));
|
||||
assertEquals(CollectChannel.ONLINE, CollectChannel.defaultFor(" "));
|
||||
}
|
||||
|
||||
@Test
|
||||
void 未登记的模块按非本地处理() {
|
||||
CollectRoutingProperties properties = new CollectRoutingProperties();
|
||||
properties.setLocalEnabled(Map.of("SIMILAR_ASIN", true));
|
||||
void 库里存的通道优先于模块默认() {
|
||||
assertEquals(CollectChannel.ONLINE,
|
||||
CollectChannel.resolve("ONLINE", CollectRoutingProperties.MODULE_APPEARANCE_PATENT),
|
||||
"这一单选了线上,模块默认是机器也不能盖过去");
|
||||
assertEquals(CollectChannel.LOCAL, CollectChannel.resolve(" local ", CollectRoutingProperties.MODULE_SIMILAR_ASIN));
|
||||
assertTrue(CollectChannel.resolve(null, CollectRoutingProperties.MODULE_SIMILAR_ASIN).isLocal(),
|
||||
"空值=未登记,按模块默认");
|
||||
assertTrue(CollectChannel.resolve("未识别的值", CollectRoutingProperties.MODULE_APPEARANCE_PATENT).isLocal(),
|
||||
"脏值必须回落默认,不能让一个坏值把单子永久饿死");
|
||||
}
|
||||
|
||||
assertFalse(properties.isLocal("COLLECT_DATA"), "没配置的模块必须保持 Linux 原有等待窗口");
|
||||
assertFalse(properties.isLocal(null));
|
||||
assertFalse(properties.isLocal(" "));
|
||||
@Test
|
||||
void 界面传入的非法通道值按未登记处理() {
|
||||
assertEquals(CollectChannel.LOCAL, CollectChannel.ofNullable("local"));
|
||||
assertEquals(CollectChannel.ONLINE, CollectChannel.ofNullable("ONLINE"));
|
||||
assertNull(CollectChannel.ofNullable(null), "空=不登记,由服务端按默认解释");
|
||||
assertNull(CollectChannel.ofNullable(" "));
|
||||
assertNull(CollectChannel.ofNullable("BOTH"), "不接受的第三值不能被静默收下降级成本地/线上");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
+18
-11
@@ -64,11 +64,11 @@ class AppearancePatentActivateRoutingTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
void 本地采集开启时_activate_走条件更新并刷心跳() {
|
||||
FileTaskEntity task = pendingTask();
|
||||
void 本机通道的单_activate_走条件更新并刷心跳() {
|
||||
FileTaskEntity task = pendingTask(com.nanri.aiimage.modules.task.model.CollectChannel.LOCAL);
|
||||
when(fileTaskMapper.selectById(TASK_ID)).thenReturn(task);
|
||||
when(fileTaskMapper.update(isNull(), any())).thenReturn(1);
|
||||
AppearancePatentTaskService service = service(routing(true));
|
||||
AppearancePatentTaskService service = service(new CollectRoutingProperties());
|
||||
|
||||
service.activateTask(TASK_ID, USER_ID);
|
||||
|
||||
@@ -82,9 +82,10 @@ class AppearancePatentActivateRoutingTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
void 本地采集关闭时_activate_保持后台语义并明确拒绝() {
|
||||
when(fileTaskMapper.selectById(TASK_ID)).thenReturn(pendingTask());
|
||||
AppearancePatentTaskService service = service(routing(false));
|
||||
void 线上通道的单_activate_保持后台语义并明确拒绝() {
|
||||
when(fileTaskMapper.selectById(TASK_ID))
|
||||
.thenReturn(pendingTask(com.nanri.aiimage.modules.task.model.CollectChannel.ONLINE));
|
||||
AppearancePatentTaskService service = service(new CollectRoutingProperties());
|
||||
|
||||
BusinessException error = assertThrows(BusinessException.class,
|
||||
() -> service.activateTask(TASK_ID, USER_ID));
|
||||
@@ -93,18 +94,24 @@ class AppearancePatentActivateRoutingTest {
|
||||
verify(fileTaskMapper, never()).update(isNull(), any());
|
||||
}
|
||||
|
||||
private static CollectRoutingProperties routing(boolean local) {
|
||||
CollectRoutingProperties properties = new CollectRoutingProperties();
|
||||
properties.setLocalEnabled(Map.of(CollectRoutingProperties.MODULE_APPEARANCE_PATENT, local));
|
||||
return properties;
|
||||
@Test
|
||||
void 未登记通道的历史单按模块默认走本机() {
|
||||
FileTaskEntity task = pendingTask(null);
|
||||
when(fileTaskMapper.selectById(TASK_ID)).thenReturn(task);
|
||||
when(fileTaskMapper.update(isNull(), any())).thenReturn(1);
|
||||
|
||||
service(new CollectRoutingProperties()).activateTask(TASK_ID, USER_ID);
|
||||
|
||||
verify(taskCacheService).touchTaskHeartbeat(TASK_ID);
|
||||
}
|
||||
|
||||
private FileTaskEntity pendingTask() {
|
||||
private FileTaskEntity pendingTask(com.nanri.aiimage.modules.task.model.CollectChannel channel) {
|
||||
FileTaskEntity task = new FileTaskEntity();
|
||||
task.setId(TASK_ID);
|
||||
task.setModuleType(AppearancePatentTaskService.MODULE_TYPE);
|
||||
task.setUserId(USER_ID);
|
||||
task.setStatus("PENDING");
|
||||
task.setCollectChannel(channel == null ? null : channel.name());
|
||||
return task;
|
||||
}
|
||||
|
||||
|
||||
+21
@@ -161,6 +161,7 @@ class AppearancePatentCreateTaskSnapshotTest {
|
||||
+ " moduleType=" + task.getModuleType()
|
||||
+ " status=" + task.getStatus()
|
||||
+ " taskMode=" + task.getTaskMode()
|
||||
+ " collectChannel=" + task.getCollectChannel()
|
||||
+ " sourceFileCount=" + task.getSourceFileCount()
|
||||
+ " successFileCount=" + task.getSuccessFileCount()
|
||||
+ " failedFileCount=" + task.getFailedFileCount()
|
||||
@@ -448,6 +449,26 @@ class AppearancePatentCreateTaskSnapshotTest {
|
||||
assertTrue(resultEvent.contains(" rowCount=2"), "rowCount 记的是接受行数(4 行夹具去掉 dropped 与全空行):" + resultEvent);
|
||||
}
|
||||
|
||||
@Test
|
||||
void 建单按界面选的通道落库() throws Exception {
|
||||
// V183:执行方由这一单自己定(界面 LOCAL/ONLINE 单选框),建单就得把选择写进头行。
|
||||
Harness online = harnessWithFiles("uploads/main.xlsx", mixedWorkbook(), null, null);
|
||||
AppearancePatentParseRequest picked = request(7L, List.of(source("uploads/main.xlsx", "17.xlsx")));
|
||||
picked.setCollectChannel(" online ");
|
||||
online.service().parseAndCreateTask(picked, "device-1");
|
||||
assertTrue(firstTaskInsert(online).contains(" collectChannel=ONLINE"),
|
||||
"选线上的单子必须钉成 ONLINE,否则 activate 会把任务推回本机客户端:" + firstTaskInsert(online));
|
||||
|
||||
Harness legacy = harnessWithFiles("uploads/main.xlsx", mixedWorkbook(), null, null);
|
||||
legacy.service().parseAndCreateTask(request(7L, List.of(source("uploads/main.xlsx", "17.xlsx"))), "device-1");
|
||||
assertTrue(firstTaskInsert(legacy).contains(" collectChannel=null"),
|
||||
"未升级前端不传通道=不登记,由模块默认兜(外观专利默认本机),历史行为不变:" + firstTaskInsert(legacy));
|
||||
}
|
||||
|
||||
private static String firstTaskInsert(Harness harness) {
|
||||
return harness.events.stream().filter(e -> e.startsWith("task.insert")).findFirst().orElse("<无 task.insert>");
|
||||
}
|
||||
|
||||
@Test
|
||||
void 头行先落库再有载荷指针() throws Exception {
|
||||
Harness harness = harnessWithFiles("uploads/main.xlsx", mixedWorkbook(), null, null);
|
||||
|
||||
+29
@@ -24,6 +24,7 @@ import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.Mockito;
|
||||
import org.mockito.Spy;
|
||||
@@ -41,12 +42,14 @@ import java.util.concurrent.atomic.AtomicLong;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyInt;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.clearInvocations;
|
||||
import static org.mockito.Mockito.lenient;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
@@ -185,6 +188,32 @@ class SimilarAsinTaskServiceParseDelegationTest {
|
||||
assertEquals("uploads/f1.xlsx::1@2", vo.getGroups().get(0).getGroupKey(), "分组键按归一化 fileKey 拼接");
|
||||
}
|
||||
|
||||
@Test
|
||||
void test_parse_records_collect_channel() throws Exception {
|
||||
// V183:执行方由这一单自己定,界面选的通道必须在建单时落进 collect_channel。
|
||||
File workbook = buildWorkbook(List.<String[]>of(new String[]{"1", "B01A", "US"}));
|
||||
|
||||
assertEquals("ONLINE", insertedChannel(workbook, "uploads/collect-online.xlsx", "ONLINE"));
|
||||
assertEquals("LOCAL", insertedChannel(workbook, "uploads/collect-local.xlsx", " local "));
|
||||
assertNull(insertedChannel(workbook, "uploads/collect-absent.xlsx", null),
|
||||
"不传就留空=按模块默认,未升级前端的行为一字不变");
|
||||
assertNull(insertedChannel(workbook, "uploads/collect-dirty.xlsx", "本机"),
|
||||
"不可识别的值按不登记处理,不把脏值钉进库里让单子永久卡在一侧");
|
||||
}
|
||||
|
||||
/** 跑一次建单,取回落库任务头的通道字段。 */
|
||||
private String insertedChannel(File workbook, String fileKey, String collectChannel) {
|
||||
when(localFileStorageService.findLocalSourceFile(fileKey)).thenReturn(workbook);
|
||||
SimilarAsinParseRequest request = request(fileKey);
|
||||
request.setCollectChannel(collectChannel);
|
||||
// 只清调用记录、保留赋值 id 的桩:一个用例连跑四次建单,否则 captor 拿到的是上一单的实体
|
||||
clearInvocations(fileTaskMapper);
|
||||
service.parseAndCreateTask(request, "test-device");
|
||||
ArgumentCaptor<FileTaskEntity> captor = ArgumentCaptor.forClass(FileTaskEntity.class);
|
||||
verify(fileTaskMapper).insert(captor.capture());
|
||||
return captor.getValue().getCollectChannel();
|
||||
}
|
||||
|
||||
@Test
|
||||
void test_parse_delegates_validator() throws Exception {
|
||||
// 重复 ASIN+国家 / 非字母数字 ASIN:校验器标记但不改接收结果(与改造前一致)
|
||||
|
||||
+1
@@ -195,6 +195,7 @@ class SimilarAsinCreateTaskSnapshotTest {
|
||||
+ " taskNoPrefix=" + taskNoPrefix(task.getTaskNo())
|
||||
+ " moduleType=" + dash(task.getModuleType())
|
||||
+ " taskMode=" + dash(task.getTaskMode())
|
||||
+ " collectChannel=" + dash(task.getCollectChannel())
|
||||
+ " status=" + dash(task.getStatus())
|
||||
+ " sourceFileCount=" + task.getSourceFileCount()
|
||||
+ " ok=" + task.getSuccessFileCount()
|
||||
|
||||
+3
-4
@@ -20,7 +20,6 @@ class CollectRoutingControllerTest {
|
||||
@Test
|
||||
void 开关默认开启时两个模块都答本地() throws Exception {
|
||||
CollectRoutingProperties properties = new CollectRoutingProperties();
|
||||
properties.setLocalEnabled(Map.of("APPEARANCE_PATENT", true, "SIMILAR_ASIN", true));
|
||||
MockMvc mockMvc = MockMvcBuilders
|
||||
.standaloneSetup(new CollectRoutingController(properties))
|
||||
.build();
|
||||
@@ -33,16 +32,16 @@ class CollectRoutingControllerTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
void 关闭本地采集时接口如实回答且未登记模块不影响这两项() throws Exception {
|
||||
void 兜底窗口配置不改变这两项默认() throws Exception {
|
||||
CollectRoutingProperties properties = new CollectRoutingProperties();
|
||||
properties.setLocalEnabled(Map.of("APPEARANCE_PATENT", false, "SIMILAR_ASIN", true));
|
||||
properties.setLinuxFallbackMinutes(90L);
|
||||
MockMvc mockMvc = MockMvcBuilders
|
||||
.standaloneSetup(new CollectRoutingController(properties))
|
||||
.build();
|
||||
|
||||
mockMvc.perform(get("/api/collect-routing"))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(jsonPath("$.data.appearancePatentLocal").value(false))
|
||||
.andExpect(jsonPath("$.data.appearancePatentLocal").value(true))
|
||||
.andExpect(jsonPath("$.data.similarAsinLocal").value(true));
|
||||
}
|
||||
}
|
||||
|
||||
+64
@@ -0,0 +1,64 @@
|
||||
package com.nanri.aiimage.modules.task.model;
|
||||
|
||||
import com.nanri.aiimage.config.CollectRoutingProperties;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
|
||||
/**
|
||||
* V183 任务级采集通道的判据(建单写入、认领读取、脏值兜底)。
|
||||
*
|
||||
* <p>这里钉死的是「不登记=按模块默认」这条兼容线:外观专利/相似ASIN 读作本机,
|
||||
* 其余模块读作线上,与 V183 之前 {@code AIIMAGE_COLLECT_LOCAL_*} 出厂值 {@code true} 等价。
|
||||
* 一旦默认翻转,全部历史任务与未升级客户端的执行方会集体换边,所以逐条点名。
|
||||
*/
|
||||
class CollectChannelTest {
|
||||
|
||||
@Test
|
||||
void 模块默认外观专利与相似ASIN走本机() {
|
||||
assertEquals(CollectChannel.LOCAL,
|
||||
CollectChannel.defaultFor(CollectRoutingProperties.MODULE_APPEARANCE_PATENT));
|
||||
assertEquals(CollectChannel.LOCAL,
|
||||
CollectChannel.defaultFor(CollectRoutingProperties.MODULE_SIMILAR_ASIN));
|
||||
assertFalse(CollectChannel.defaultFor("DEDUPE").isLocal(), "未点名的模块保持原有的线上语义");
|
||||
assertFalse(CollectChannel.defaultFor(null).isLocal(), "模块名缺失按线上,不给任意单本机优先");
|
||||
assertFalse(CollectChannel.defaultFor(" ").isLocal());
|
||||
}
|
||||
|
||||
@Test
|
||||
void 模块默认大小写与空白不影响判定() {
|
||||
assertEquals(CollectChannel.LOCAL, CollectChannel.defaultFor("similar_asin"));
|
||||
assertEquals(CollectChannel.LOCAL, CollectChannel.defaultFor(" SIMILAR_ASIN "));
|
||||
}
|
||||
|
||||
@Test
|
||||
void 库里登记过就按登记的读() {
|
||||
assertEquals(CollectChannel.ONLINE,
|
||||
CollectChannel.resolve("ONLINE", CollectRoutingProperties.MODULE_APPEARANCE_PATENT),
|
||||
"外观专利默认本机,但这一单选了线上就必须读成线上");
|
||||
assertEquals(CollectChannel.ONLINE, CollectChannel.resolve(" online ", CollectRoutingProperties.MODULE_APPEARANCE_PATENT));
|
||||
assertEquals(CollectChannel.LOCAL, CollectChannel.resolve("LOCAL", "DEDUPE"),
|
||||
"选了本机的单子不因模块不是本地默认而被判成线上");
|
||||
}
|
||||
|
||||
@Test
|
||||
void 未登记或脏值回落到模块默认而不饿死任务() {
|
||||
assertEquals(CollectChannel.LOCAL, CollectChannel.resolve(null, CollectRoutingProperties.MODULE_APPEARANCE_PATENT));
|
||||
assertEquals(CollectChannel.LOCAL, CollectChannel.resolve("", CollectRoutingProperties.MODULE_SIMILAR_ASIN));
|
||||
assertEquals(CollectChannel.ONLINE, CollectChannel.resolve(null, "DEDUPE"));
|
||||
assertEquals(CollectChannel.LOCAL, CollectChannel.resolve("本地", CollectRoutingProperties.MODULE_APPEARANCE_PATENT),
|
||||
"脏值按模块默认兜,不让一个写花的值把单子永久卡在没人领的一侧");
|
||||
}
|
||||
|
||||
@Test
|
||||
void 建单写入只认两个规范值其余登记为空() {
|
||||
assertEquals("ONLINE", CollectChannel.persistedValue("online"));
|
||||
assertEquals("LOCAL", CollectChannel.persistedValue(" LOCAL "));
|
||||
assertNull(CollectChannel.persistedValue(null), "不登记=留空,由模块默认兜");
|
||||
assertNull(CollectChannel.persistedValue(""));
|
||||
assertNull(CollectChannel.persistedValue("LOCALHOST"), "不可识别的值不留库,回落默认");
|
||||
assertNull(CollectChannel.ofNullable("本地"));
|
||||
}
|
||||
}
|
||||
+34
-22
@@ -193,41 +193,56 @@ class TaskClientPullServiceTest {
|
||||
// ------------------------------------------------------------ 本地采集路由(2026-10-29)
|
||||
|
||||
@Test
|
||||
void 客户端兜底拉取只认本地模块() {
|
||||
com.nanri.aiimage.config.CollectRoutingProperties routing =
|
||||
new com.nanri.aiimage.config.CollectRoutingProperties();
|
||||
routing.setLocalEnabled(Map.of("SIMILAR_ASIN", false, "COLLECT_DATA", false));
|
||||
void 客户端兜底拉取不领线上通道的单() {
|
||||
FileTaskEntity online = task(11L, "SIMILAR_ASIN", 10L);
|
||||
online.setCollectChannel("ONLINE");
|
||||
when(fileTaskMapper.selectList(any())).thenReturn(List.of(online));
|
||||
|
||||
List<TaskClientPullVo> result = serviceWithRouting(routing,
|
||||
List<TaskClientPullVo> result = serviceWithRouting(defaultRouting(),
|
||||
new StubHandler("SIMILAR_ASIN", payload("similar-asin-run"))).pullPendingTasks(USER_ID);
|
||||
|
||||
assertTrue(result.isEmpty(), "模块切到 Linux 后台后客户端不应再拉取");
|
||||
verifyNoInteractions(fileTaskMapper);
|
||||
assertTrue(result.isEmpty(), "这一单选了线上采集,客户端领了就是抢跑");
|
||||
verify(fileTaskMapper, never()).update(isNull(), any());
|
||||
}
|
||||
|
||||
@Test
|
||||
void 内部认领对本地模块让位到兜底窗口() {
|
||||
void 客户端兜底拉取照领本机通道的单() {
|
||||
FileTaskEntity local = task(11L, "SIMILAR_ASIN", 10L);
|
||||
local.setCollectChannel("LOCAL");
|
||||
when(fileTaskMapper.selectList(any())).thenReturn(List.of(local));
|
||||
when(fileTaskMapper.update(isNull(), any())).thenReturn(1);
|
||||
when(fileTaskMapper.selectById(11L)).thenReturn(local);
|
||||
|
||||
List<TaskClientPullVo> result = serviceWithRouting(defaultRouting(),
|
||||
new StubHandler("SIMILAR_ASIN", payload("similar-asin-run"))).pullPendingTasks(USER_ID);
|
||||
|
||||
assertEquals(1, result.size(), "本机通道的单必须能被在线客户端领走");
|
||||
}
|
||||
|
||||
@Test
|
||||
void 内部认领对本机通道让位到兜底窗口() {
|
||||
com.nanri.aiimage.config.CollectRoutingProperties routing =
|
||||
new com.nanri.aiimage.config.CollectRoutingProperties();
|
||||
routing.setLocalEnabled(Map.of("SIMILAR_ASIN", true));
|
||||
routing.setLinuxFallbackMinutes(30L);
|
||||
when(fileTaskMapper.selectList(any())).thenReturn(List.of(task(11L, "SIMILAR_ASIN", 10L)));
|
||||
FileTaskEntity localTask = task(11L, "SIMILAR_ASIN", 10L);
|
||||
localTask.setCollectChannel("LOCAL");
|
||||
when(fileTaskMapper.selectList(any())).thenReturn(List.of(localTask));
|
||||
|
||||
List<TaskClientPullVo> result = serviceWithRouting(routing,
|
||||
new StubHandler("SIMILAR_ASIN", payload("similar-asin-run")))
|
||||
.pullPendingTasksInternal(List.of("SIMILAR_ASIN"));
|
||||
|
||||
assertTrue(result.isEmpty(), "本地采集模块在兜底窗口内必须让位给本地客户端");
|
||||
assertTrue(result.isEmpty(), "本机通道的单在兜底窗口内必须让位给本地客户端");
|
||||
verify(fileTaskMapper, never()).update(isNull(), any());
|
||||
}
|
||||
|
||||
@Test
|
||||
void 内部认领超过兜底窗口后接管本地模块() {
|
||||
void 内部认领超过兜底窗口后接管本机通道的单() {
|
||||
com.nanri.aiimage.config.CollectRoutingProperties routing =
|
||||
new com.nanri.aiimage.config.CollectRoutingProperties();
|
||||
routing.setLocalEnabled(Map.of("SIMILAR_ASIN", true));
|
||||
routing.setLinuxFallbackMinutes(30L);
|
||||
FileTaskEntity candidate = task(11L, "SIMILAR_ASIN", 40L);
|
||||
candidate.setCollectChannel("LOCAL");
|
||||
when(fileTaskMapper.selectList(any())).thenReturn(List.of(candidate));
|
||||
when(fileTaskMapper.update(isNull(), any())).thenReturn(1);
|
||||
when(fileTaskMapper.selectById(11L)).thenReturn(candidate);
|
||||
@@ -236,16 +251,16 @@ class TaskClientPullServiceTest {
|
||||
new StubHandler("SIMILAR_ASIN", payload("similar-asin-run")))
|
||||
.pullPendingTasksInternal(List.of("SIMILAR_ASIN"));
|
||||
|
||||
assertEquals(1, result.size(), "本地长时间没人领,Linux 必须兜底接管");
|
||||
assertEquals(1, result.size(), "本机长时间没人领,Linux 必须兜底接管");
|
||||
}
|
||||
|
||||
@Test
|
||||
void 内部认领对非本地模块保持原等待窗口() {
|
||||
void 内部认领对线上通道不受兜底窗口影响() {
|
||||
com.nanri.aiimage.config.CollectRoutingProperties routing =
|
||||
new com.nanri.aiimage.config.CollectRoutingProperties();
|
||||
routing.setLocalEnabled(Map.of("SIMILAR_ASIN", true));
|
||||
routing.setLinuxFallbackMinutes(30L);
|
||||
FileTaskEntity candidate = task(21L, "COLLECT_DATA", 10L);
|
||||
candidate.setCollectChannel("ONLINE");
|
||||
when(fileTaskMapper.selectList(any())).thenReturn(List.of(candidate));
|
||||
when(fileTaskMapper.update(isNull(), any())).thenReturn(1);
|
||||
when(fileTaskMapper.selectById(21L)).thenReturn(candidate);
|
||||
@@ -254,19 +269,16 @@ class TaskClientPullServiceTest {
|
||||
new StubHandler("COLLECT_DATA", payload("collect-data-run")))
|
||||
.pullPendingTasksInternal(List.of("COLLECT_DATA"));
|
||||
|
||||
assertEquals(1, result.size(), "未登记本地开关的模块不受兜底窗口影响");
|
||||
assertEquals(1, result.size(), "选了线上的单子不能被本地优先的窗口拖住");
|
||||
}
|
||||
|
||||
private TaskClientPullService service(ClientTaskPullSpi... handlers) {
|
||||
return serviceWithRouting(defaultRouting(), handlers);
|
||||
}
|
||||
|
||||
/** 默认路由:两个模块都按本地采集(现有用例的既有语义)。 */
|
||||
/** 默认路由:兜底窗口取出厂 30 分钟;通道由每条任务自己带(V183),不在这里配全局。 */
|
||||
private static com.nanri.aiimage.config.CollectRoutingProperties defaultRouting() {
|
||||
com.nanri.aiimage.config.CollectRoutingProperties routing =
|
||||
new com.nanri.aiimage.config.CollectRoutingProperties();
|
||||
routing.setLocalEnabled(Map.of("SIMILAR_ASIN", true, "COLLECT_DATA", true));
|
||||
return routing;
|
||||
return new com.nanri.aiimage.config.CollectRoutingProperties();
|
||||
}
|
||||
|
||||
private TaskClientPullService serviceWithRouting(
|
||||
|
||||
+2
@@ -32,12 +32,14 @@ class TaskRetryCloneSupportTest {
|
||||
void 克隆任务头保留输入与代数并清空结果计数() {
|
||||
FileTaskMapperHolder holder = new FileTaskMapperHolder();
|
||||
FileTaskEntity original = holder.original();
|
||||
original.setCollectChannel("ONLINE");
|
||||
TaskRetryCloneSupport support = support(mock(FileResultMapper.class), mock(TaskScopeStateMapper.class));
|
||||
|
||||
FileTaskEntity child = support.buildChild(original, "{\"parsedPayloadRef\":\"p\"}");
|
||||
|
||||
assertEquals("PENDING", child.getStatus());
|
||||
assertEquals("SIMILAR_ASIN", child.getModuleType());
|
||||
assertEquals("ONLINE", child.getCollectChannel(), "重试不得悄悄换执行方:通道随原单继承");
|
||||
assertEquals(original.getRequestJson(), child.getRequestJson());
|
||||
assertEquals("{\"parsedPayloadRef\":\"p\"}", child.getResultJson());
|
||||
assertEquals(977L, child.getUserId());
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
== 单文件建单 ==
|
||||
task.insert taskNo=APPEARANCE_PATENT-<snowflake> moduleType=APPEARANCE_PATENT status=PENDING taskMode=PYTHON_QUEUE sourceFileCount=1 successFileCount=0 failedFileCount=0 userId=7 createdBy=user:7 deviceId=device-1 requestJson.keys=[files,fileKey,originalFilename,relativePath,user_id,ai_prompt,api_key] requestJson.digest=e9c718bc06a1 resultJson={}
|
||||
task.insert taskNo=APPEARANCE_PATENT-<snowflake> moduleType=APPEARANCE_PATENT status=PENDING taskMode=PYTHON_QUEUE collectChannel=null sourceFileCount=1 successFileCount=0 failedFileCount=0 userId=7 createdBy=user:7 deviceId=device-1 requestJson.keys=[files,fileKey,originalFilename,relativePath,user_id,ai_prompt,api_key,collect_channel] requestJson.digest=8a10649faa72 resultJson={}
|
||||
payload.storeParsed module=APPEARANCE_PATENT taskId=1001 scopeHash=5aef06a0d982 entry=latest encodeAsJson=false content.len=1131 content.digest=3f9589e6833c
|
||||
task.update id=1001 resultJson.keys=[aiPrompt,apiKey,sourceFileKeys,parsedPayloadRef,ownerInstanceId] resultJson={"aiPrompt":"请排查侵权风险","apiKey":"sk-test-0001","sourceFileKeys":["uploads/main.xlsx"],"parsedPayloadRef":"ptr://task-parsed/5aef06a0d982/latest","ownerInstanceId":"instance-A"}
|
||||
result.insert taskId=1001 moduleType=APPEARANCE_PATENT sourceFilename=17.xlsx sourceFileUrl=uploads/main.xlsx rowCount=2 success=null userId=7
|
||||
@@ -7,7 +7,7 @@ scope.insert taskId=1001 moduleType=APPEARANCE_PATENT scopeKey=uploads/main.xlsx
|
||||
vo: taskId=1001 sourceFilename=17.xlsx sourceFileCount=1 totalRows=3 acceptedRows=2 droppedRows=1 groupCount=1 aiPrompt=请排查侵权风险 items=0 groups=0
|
||||
|
||||
== 双文件聚合 ==
|
||||
task.insert taskNo=APPEARANCE_PATENT-<snowflake> moduleType=APPEARANCE_PATENT status=PENDING taskMode=PYTHON_QUEUE sourceFileCount=2 successFileCount=0 failedFileCount=0 userId=7 createdBy=user:7 deviceId=null requestJson.keys=[files,fileKey,originalFilename,relativePath,fileKey,originalFilename,relativePath,user_id,ai_prompt,api_key] requestJson.digest=2f72932983ea resultJson={}
|
||||
task.insert taskNo=APPEARANCE_PATENT-<snowflake> moduleType=APPEARANCE_PATENT status=PENDING taskMode=PYTHON_QUEUE collectChannel=null sourceFileCount=2 successFileCount=0 failedFileCount=0 userId=7 createdBy=user:7 deviceId=null requestJson.keys=[files,fileKey,originalFilename,relativePath,fileKey,originalFilename,relativePath,user_id,ai_prompt,api_key,collect_channel] requestJson.digest=2b44afc83905 resultJson={}
|
||||
payload.storeParsed module=APPEARANCE_PATENT taskId=1001 scopeHash=c822dc131109 entry=latest encodeAsJson=false content.len=1610 content.digest=e2bb1a0e4ab4
|
||||
task.update id=1001 resultJson.keys=[aiPrompt,apiKey,sourceFileKeys,parsedPayloadRef,ownerInstanceId] resultJson={"aiPrompt":"请排查侵权风险","apiKey":"sk-test-0001","sourceFileKeys":["uploads/a.xlsx","uploads/b.xlsx"],"parsedPayloadRef":"ptr://task-parsed/c822dc131109/latest","ownerInstanceId":"instance-A"}
|
||||
result.insert taskId=1001 moduleType=APPEARANCE_PATENT sourceFilename=a.xlsx 等 2 个文件 sourceFileUrl=aggregate:7b002a4b8031c0f8ee99822337979dfbe4720f1c3bf262701d04767a09b9dd36 rowCount=3 success=null userId=7
|
||||
@@ -25,5 +25,5 @@ fileKey=空白 -> BusinessException: fileKey 不能为空
|
||||
events=5(四格有夹具的场景也必须零落库)
|
||||
|
||||
== 载荷存储失败时的副作用边界(本支建单无事务) ==
|
||||
task.insert taskNo=APPEARANCE_PATENT-<snowflake> moduleType=APPEARANCE_PATENT status=PENDING taskMode=PYTHON_QUEUE sourceFileCount=1 successFileCount=0 failedFileCount=0 userId=7 createdBy=user:7 deviceId=d requestJson.keys=[files,fileKey,originalFilename,relativePath,user_id,ai_prompt,api_key] requestJson.digest=e9c718bc06a1 resultJson={}
|
||||
task.insert taskNo=APPEARANCE_PATENT-<snowflake> moduleType=APPEARANCE_PATENT status=PENDING taskMode=PYTHON_QUEUE collectChannel=null sourceFileCount=1 successFileCount=0 failedFileCount=0 userId=7 createdBy=user:7 deviceId=d requestJson.keys=[files,fileKey,originalFilename,relativePath,user_id,ai_prompt,api_key,collect_channel] requestJson.digest=8a10649faa72 resultJson={}
|
||||
outcome=共享临时存储关闭 -> BusinessException: 外观专利parsed payload必须写入共享临时存储 RustFS,请检查 aiimage.transient-storage 配置
|
||||
|
||||
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user