单元测试用例

This commit is contained in:
redkale
2023-12-05 17:44:18 +08:00
parent a0da13bc4f
commit 54f9b68b3d
3 changed files with 84 additions and 15 deletions

View File

@@ -0,0 +1,31 @@
/*
*
*/
package org.redkale.test.scheduling;
import org.redkale.annotation.Scheduled;
import org.redkale.service.Service;
import org.redkale.util.Times;
/**
*
* @author zhangjx
*/
public class ScheduleService implements Service {
@Scheduled(cron = "0/1 * * * * ?")
public void task1() {
System.out.println(Times.nowMillis() + "每秒-----------执行task1");
}
@Scheduled(cron = "0/1 * * * * ?")
public String task2() {
System.out.println(Times.nowMillis() + "每秒*****执行task2");
return "";
}
@Scheduled(cron = "0/1 * * * * ?")
private void task3() {
System.out.println(Times.nowMillis() + "每秒执行task3");
}
}

View File

@@ -0,0 +1,31 @@
/*
*
*/
package org.redkale.test.scheduling;
import org.junit.jupiter.api.Test;
import org.redkale.scheduling.ScheduledFactory;
import org.redkale.util.Utility;
/**
*
* @author zhangjx
*/
public class ScheduleTest {
public static void main(String[] args) throws Throwable {
ScheduleTest test = new ScheduleTest();
test.run();
}
@Test
public void run() throws Exception {
ScheduledFactory factory = ScheduledFactory.create(null);
ScheduleService service = new ScheduleService();
factory.schedule(service);
Utility.sleep(3000);
factory.unschedule(service);
factory.destroy();
}
}