|
|
|
@ -70,9 +70,9 @@ public class CronUtilsTest {
|
|
|
|
|
@Test |
|
|
|
|
public void testCronParse() throws ParseException { |
|
|
|
|
String strCrontab = "0 1 2 3 * ? *"; |
|
|
|
|
strCrontab = "0/50 0/59 * * * ? *"; |
|
|
|
|
strCrontab = "3/5 * 0/5 * * ? *"; |
|
|
|
|
strCrontab = "1/5 3/5 1/5 3/30 * ? *"; |
|
|
|
|
// strCrontab = "0/50 0/59 * * * ? *";
|
|
|
|
|
// strCrontab = "3/5 * 0/5 * * ? *";
|
|
|
|
|
// strCrontab = "1/5 3/5 1/5 3/30 * ? *";
|
|
|
|
|
|
|
|
|
|
Cron depCron = CronUtils.parse2Cron(strCrontab); |
|
|
|
|
Assert.assertEquals(depCron.retrieve(CronFieldName.SECOND).getExpression().asString(), "0"); |
|
|
|
@ -90,11 +90,14 @@ public class CronUtilsTest {
|
|
|
|
|
@Test |
|
|
|
|
public void testScheduleType() throws ParseException { |
|
|
|
|
|
|
|
|
|
CycleEnum cycleEnum = CronUtils.getMaxCycle("0 */1 * * * ? *"); |
|
|
|
|
CycleEnum cycleEnum = CronUtils.getMaxCycle(CronUtils.parse2Cron("0 */1 * * * ? *")); |
|
|
|
|
Assert.assertEquals(cycleEnum.name(), "MINUTE"); |
|
|
|
|
|
|
|
|
|
CycleEnum cycleEnum2 = CronUtils.getMaxCycle("0 * * * * ? *"); |
|
|
|
|
Assert.assertEquals(cycleEnum2.name(), "MINUTE"); |
|
|
|
|
|
|
|
|
|
CycleEnum cycleEnum3 = CronUtils.getMiniCycle(CronUtils.parse2Cron("0 * * * * ? *")); |
|
|
|
|
Assert.assertEquals(cycleEnum3.name(), "MINUTE"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
@ -185,7 +188,12 @@ public class CronUtilsTest {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void test3(){ |
|
|
|
|
public void parse2Cron(){ |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void getSelfFireDateList() throws ParseException{ |
|
|
|
|
Date from = DateUtils.stringToDate("2020-01-01 00:00:00"); |
|
|
|
|
Date to = DateUtils.stringToDate("2020-01-31 01:00:00"); |
|
|
|
|
// test date
|
|
|
|
@ -194,5 +202,23 @@ public class CronUtilsTest {
|
|
|
|
|
Assert.assertEquals(0, CronUtils.getSelfFireDateList(from, to, "0 0 0 * *").size()); |
|
|
|
|
// test cron
|
|
|
|
|
Assert.assertEquals(30, CronUtils.getSelfFireDateList(from, to, "0 0 0 * * ? ").size()); |
|
|
|
|
// test other
|
|
|
|
|
Assert.assertEquals(30, CronUtils.getFireDateList(from, to, CronUtils.parse2CronExpression("0 0 0 * * ? ")).size()); |
|
|
|
|
Assert.assertEquals(5, CronUtils.getSelfFireDateList(from, to, CronUtils.parse2CronExpression("0 0 0 * * ? "), 5).size()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void getExpirationTime(){ |
|
|
|
|
Date startTime = DateUtils.stringToDate("2020-02-07 18:30:00"); |
|
|
|
|
Date expirationTime = CronUtils.getExpirationTime(startTime, CycleEnum.HOUR); |
|
|
|
|
Assert.assertEquals("2020-02-07 19:30:00", DateUtils.dateToString(expirationTime)); |
|
|
|
|
expirationTime = CronUtils.getExpirationTime(startTime, CycleEnum.DAY); |
|
|
|
|
Assert.assertEquals("2020-02-07 23:59:59", DateUtils.dateToString(expirationTime)); |
|
|
|
|
expirationTime = CronUtils.getExpirationTime(startTime, CycleEnum.WEEK); |
|
|
|
|
Assert.assertEquals("2020-02-07 23:59:59", DateUtils.dateToString(expirationTime)); |
|
|
|
|
expirationTime = CronUtils.getExpirationTime(startTime, CycleEnum.MONTH); |
|
|
|
|
Assert.assertEquals("2020-02-07 23:59:59", DateUtils.dateToString(expirationTime)); |
|
|
|
|
expirationTime = CronUtils.getExpirationTime(startTime, CycleEnum.YEAR); |
|
|
|
|
Assert.assertEquals("2020-02-07 18:30:00", DateUtils.dateToString(expirationTime)); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|