|
@@ -1,5 +1,7 @@
|
|
|
package com.etotem.cfc.unit;
|
|
package com.etotem.cfc.unit;
|
|
|
|
|
|
|
|
|
|
+import com.baomidou.mybatisplus.core.conditions.Wrapper;
|
|
|
|
|
+import com.baomidou.mybatisplus.core.metadata.TableInfoHelper;
|
|
|
import com.etotem.cfc.entity.Task;
|
|
import com.etotem.cfc.entity.Task;
|
|
|
import com.etotem.cfc.mapper.TaskMapper;
|
|
import com.etotem.cfc.mapper.TaskMapper;
|
|
|
import com.etotem.cfc.task.RepeatTaskGenerator;
|
|
import com.etotem.cfc.task.RepeatTaskGenerator;
|
|
@@ -26,6 +28,8 @@ class RepeatTaskGeneratorPassThroughTest {
|
|
|
|
|
|
|
|
@BeforeEach
|
|
@BeforeEach
|
|
|
void setUp() throws Exception {
|
|
void setUp() throws Exception {
|
|
|
|
|
+ // 初始化 Task 实体的 lambda 缓存,供 LambdaQueryWrapper 在纯单元测试中解析列名
|
|
|
|
|
+ try { org.apache.ibatis.builder.MapperBuilderAssistant a = new org.apache.ibatis.builder.MapperBuilderAssistant(new com.baomidou.mybatisplus.core.MybatisConfiguration(), "x"); TableInfoHelper.initTableInfo(a, Task.class); } catch (Exception ignore) {}
|
|
|
generator = new RepeatTaskGenerator();
|
|
generator = new RepeatTaskGenerator();
|
|
|
taskMapper = mock(TaskMapper.class);
|
|
taskMapper = mock(TaskMapper.class);
|
|
|
Field f = RepeatTaskGenerator.class.getDeclaredField("taskMapper");
|
|
Field f = RepeatTaskGenerator.class.getDeclaredField("taskMapper");
|
|
@@ -122,4 +126,50 @@ class RepeatTaskGeneratorPassThroughTest {
|
|
|
assertNull(inst.getParentTaskId());
|
|
assertNull(inst.getParentTaskId());
|
|
|
assertNull(inst.getDimensionCode());
|
|
assertNull(inst.getDimensionCode());
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 判重必须按归属日(deadline)命中跨日手工实例:
|
|
|
|
|
+ * 11-30 创建、deadline=12-01 的实例,在 12-01 生成窗口内应被判为已存在。
|
|
|
|
|
+ * 原逻辑只看 created_at 会漏判 → 生成器重复生成同归属日的第二条(昨夜无屏重复根因)。
|
|
|
|
|
+ */
|
|
|
|
|
+ @Test
|
|
|
|
|
+ void hasTaskForDate_按归属日deadline判重跨日实例() throws Exception {
|
|
|
|
|
+ Task template = healthPlanTemplate(88L);
|
|
|
|
|
+ when(taskMapper.selectCount(any())).thenReturn(1L);
|
|
|
|
|
+
|
|
|
|
|
+ Method m = RepeatTaskGenerator.class.getDeclaredMethod(
|
|
|
|
|
+ "hasTaskForDate", Task.class, Date.class, long.class);
|
|
|
|
|
+ m.setAccessible(true);
|
|
|
|
|
+ java.util.Date today = new java.util.Date();
|
|
|
|
|
+ Boolean exists = (Boolean) m.invoke(generator, template, today, 86400000L);
|
|
|
|
|
+
|
|
|
|
|
+ assertTrue(exists, "判重应命中");
|
|
|
|
|
+ org.mockito.ArgumentCaptor<Wrapper> captor = org.mockito.ArgumentCaptor.forClass(Wrapper.class);
|
|
|
|
|
+ verify(taskMapper).selectCount(captor.capture());
|
|
|
|
|
+ String seg = captor.getValue().getSqlSegment().toLowerCase();
|
|
|
|
|
+ assertTrue(seg.contains("deadline"), "判重 SQL 必须包含 deadline(归属日) 条件,实际: " + seg);
|
|
|
|
|
+ assertTrue(seg.contains("created_at"), "判重 SQL 应保留 created_at 条件兼容, 实际: " + seg);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * hourly 短窗口(1h)不得按 deadline 判重:其 deadline 常落在窗口末端(now+duration),
|
|
|
|
|
+ * 按 deadline 判会误命中导致小时任务永不滚动生成。
|
|
|
|
|
+ */
|
|
|
|
|
+ @Test
|
|
|
|
|
+ void hasTaskForDate_hourly短窗口不按deadline判重() throws Exception {
|
|
|
|
|
+ Task template = healthPlanTemplate(88L);
|
|
|
|
|
+ when(taskMapper.selectCount(any())).thenReturn(0L);
|
|
|
|
|
+
|
|
|
|
|
+ Method m = RepeatTaskGenerator.class.getDeclaredMethod(
|
|
|
|
|
+ "hasTaskForDate", Task.class, Date.class, long.class);
|
|
|
|
|
+ m.setAccessible(true);
|
|
|
|
|
+ Boolean exists = (Boolean) m.invoke(generator, template, new java.util.Date(), 3600000L);
|
|
|
|
|
+
|
|
|
|
|
+ assertFalse(exists);
|
|
|
|
|
+ org.mockito.ArgumentCaptor<Wrapper> captor = org.mockito.ArgumentCaptor.forClass(Wrapper.class);
|
|
|
|
|
+ verify(taskMapper).selectCount(captor.capture());
|
|
|
|
|
+ String seg = captor.getValue().getSqlSegment().toLowerCase();
|
|
|
|
|
+ assertFalse(seg.contains("deadline"), "短窗口判重 SQL 不应含 deadline 条件,实际: " + seg);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
}
|
|
}
|