task-39: 补充删除/超时/重复回传/累计文件失败的资源清理测试

新增 ShopDataCrawlCleanupTest 11 个用例覆盖:单条/批量/空输入删除路径的
临时文件与累计对象回收、陈旧 RUNNING 任务超时终态化、分片重复回传的
payload 释放与终态拒绝、累计文件 CAS 冲突重试时上传对象回滚。

同时撤销上一提交误引入的按国家覆盖语义:rowsByCountry 恢复同国累积
(addAll),移除与之矛盾的 writeWorkbookLatestMemberWinsPerCountryOthersPreserved
测试,修复 task-22~26 批量合并回归(行数被覆盖削减)。
This commit is contained in:
2026-08-30 12:16:39 +08:00
parent 6b76333159
commit b806ab9384
3 changed files with 1276 additions and 40 deletions
@@ -368,11 +368,7 @@ public class ShopDataCrawlExcelAssemblyService {
if (item == null || Boolean.FALSE.equals(item.getSuccess()) || item.getCountryResults() == null) continue;
for (ShopDataCrawlCountryResultDto countryResult : item.getCountryResults()) {
String country = countryResult == null || countryResult.getCountry() == null ? "" : countryResult.getCountry().trim().toUpperCase();
// 同国覆盖:按成员顺序累积,后面的结果覆盖前面的同名国家行(最新任务胜出),
// 本次未提交的国家由调用方从旧累计对象/模板保留,不在这里清空。
if (result.containsKey(country) && countryResult.getItems() != null) {
result.put(country, new ArrayList<>(countryResult.getItems()));
}
if (result.containsKey(country) && countryResult.getItems() != null) result.get(country).addAll(countryResult.getItems());
}
}
return result;
@@ -104,41 +104,6 @@ class ShopDataCrawlExcelAssemblyServiceTest {
assertEquals(2, total);
}
@Test
void writeWorkbookLatestMemberWinsPerCountryOthersPreserved() throws Exception {
// 增量语义:两个成员快照(第一次英德法、第二次只更新德国)写入 workbook 时,
// 德国 sheet 以第二个成员(新任务)的行走覆盖,英国/法国保留第一个成员的行。
ShopDataCrawlRowDto ukRow = row("2026-07-25", "B000000001");
ShopDataCrawlRowDto frRow = row("2026-07-26", "B000000002");
ShopDataCrawlRowDto deOldRow = row("2026-07-27", "B000000003");
ShopDataCrawlRowDto deNewRow = row("2026-07-28", "B000000004");
SimilarAsinImageEmbedder imageEmbedder = mock(SimilarAsinImageEmbedder.class);
when(imageEmbedder.fetchAndResizeForCache(ukRow.getCommodityImage()))
.thenReturn(new SimilarAsinImageEmbedder.ResizedImage(jpegBytes(), 2, 2));
when(imageEmbedder.fetchAndResizeForCache(frRow.getCommodityImage()))
.thenReturn(new SimilarAsinImageEmbedder.ResizedImage(jpegBytes(), 2, 2));
when(imageEmbedder.fetchAndResizeForCache(deOldRow.getCommodityImage()))
.thenReturn(new SimilarAsinImageEmbedder.ResizedImage(jpegBytes(), 2, 2));
ShopDataCrawlExcelAssemblyService service = new ShopDataCrawlExcelAssemblyService(imageEmbedder);
File output = tempDir.resolve("incremental.xlsx").toFile();
// 第一个成员:英德法三国有行;第二个成员:只带德国新行
service.writeWorkbook(output, List.of(
item("UK", ukRow), item("DE", deOldRow), item("FR", frRow),
item("DE", deNewRow)));
try (XSSFWorkbook workbook = new XSSFWorkbook(new FileInputStream(output))) {
assertEquals("B000000001", workbook.getSheet("英国").getRow(1).getCell(1).getStringCellValue(), "英国保留旧行");
assertEquals("B000000002", workbook.getSheet("法国").getRow(1).getCell(1).getStringCellValue(), "法国保留旧行");
assertEquals(1, workbook.getSheet("英国").getLastRowNum(), "英国 sheet 只有一行旧数据");
assertEquals(1, workbook.getSheet("法国").getLastRowNum(), "法国 sheet 只有一行旧数据");
assertEquals(1, workbook.getSheet("德国").getLastRowNum(), "德国 sheet 被新任务覆盖为一行");
assertEquals("B000000004", workbook.getSheet("德国").getRow(1).getCell(1).getStringCellValue(), "德国显示新任务的行");
assertEquals(0, workbook.getSheet("西班牙").getLastRowNum(), "从未提交的国家保持空表");
}
}
private ShopDataCrawlResultItemVo item(String countryCode, ShopDataCrawlRowDto row) {
ShopDataCrawlCountryResultDto country = new ShopDataCrawlCountryResultDto();
country.setCountry(countryCode);