package tech.easyflow.datacenter.schedule;

import org.junit.Test;
import org.springframework.jdbc.core.JdbcTemplate;

import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

/**
 * 数据集写入回执清理任务测试。
 */
public class DatacenterWriteReceiptCleanupJobTest {

    /**
     * 验证清理任务按固定大小分批，并在最后一个非满批次后停止。
     */
    @Test
    public void shouldDeleteExpiredReceiptsInBoundedBatches() {
        JdbcTemplate jdbcTemplate = mock(JdbcTemplate.class);
        when(jdbcTemplate.update(anyString(), any(), anyInt()))
                .thenReturn(1000, 7);
        DatacenterWriteReceiptCleanupJob job =
                new DatacenterWriteReceiptCleanupJob(
                        jdbcTemplate, 14L, 1000, 20);

        job.cleanup();

        verify(jdbcTemplate, times(2)).update(
                anyString(), any(), anyInt());
    }
}
