mirror of https://github.com/apache/activemq.git
git-svn-id: https://svn.apache.org/repos/asf/activemq/trunk@1078821 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
1c1aa17311
commit
74a45502e2
|
@ -29,20 +29,20 @@ public class CronParserTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testgetNextTimeDayOfWeek() throws MessageFormatException {
|
public void testgetNextTimeDayOfWeek() throws MessageFormatException {
|
||||||
|
|
||||||
|
|
||||||
// using an absolute date so that result will be absolute - Monday 15 Nov 2010
|
// using an absolute date so that result will be absolute - Monday 15 Nov 2010
|
||||||
Calendar current = Calendar.getInstance();
|
Calendar current = Calendar.getInstance();
|
||||||
current.set(2010, Calendar.NOVEMBER, 15, 9, 15, 30);
|
current.set(2010, Calendar.NOVEMBER, 15, 9, 15, 30);
|
||||||
System.out.println("start:" + current.getTime());
|
System.out.println("start:" + current.getTime());
|
||||||
|
|
||||||
String test = "* * * * 5";
|
String test = "* * * * 5";
|
||||||
long next = CronParser.getNextScheduledTime(test, current.getTimeInMillis());
|
long next = CronParser.getNextScheduledTime(test, current.getTimeInMillis());
|
||||||
|
|
||||||
Calendar result = Calendar.getInstance();
|
Calendar result = Calendar.getInstance();
|
||||||
result.setTimeInMillis(next);
|
result.setTimeInMillis(next);
|
||||||
System.out.println("next:" + result.getTime());
|
System.out.println("next:" + result.getTime());
|
||||||
|
|
||||||
assertEquals(30,result.get(Calendar.SECOND));
|
assertEquals(30,result.get(Calendar.SECOND));
|
||||||
assertEquals(15,result.get(Calendar.MINUTE));
|
assertEquals(15,result.get(Calendar.MINUTE));
|
||||||
assertEquals(9,result.get(Calendar.HOUR));
|
assertEquals(9,result.get(Calendar.HOUR));
|
||||||
|
@ -51,23 +51,49 @@ public class CronParserTest {
|
||||||
assertEquals(Calendar.NOVEMBER,result.get(Calendar.MONTH));
|
assertEquals(Calendar.NOVEMBER,result.get(Calendar.MONTH));
|
||||||
assertEquals(2010,result.get(Calendar.YEAR));
|
assertEquals(2010,result.get(Calendar.YEAR));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testgetNextTimeCase1() throws MessageFormatException {
|
||||||
|
|
||||||
|
|
||||||
|
// using an absolute date so that result will be absolute - Monday 15 Nov 2010
|
||||||
|
Calendar current = Calendar.getInstance();
|
||||||
|
current.set(2011, Calendar.MARCH, 7, 9, 15, 30);
|
||||||
|
System.out.println("start:" + current.getTime());
|
||||||
|
|
||||||
|
String test = "50 20 * * 5";
|
||||||
|
long next = CronParser.getNextScheduledTime(test, current.getTimeInMillis());
|
||||||
|
|
||||||
|
Calendar result = Calendar.getInstance();
|
||||||
|
result.setTimeInMillis(next);
|
||||||
|
System.out.println("next:" + result.getTime());
|
||||||
|
|
||||||
|
assertEquals(30,result.get(Calendar.SECOND));
|
||||||
|
assertEquals(50,result.get(Calendar.MINUTE));
|
||||||
|
assertEquals(20,result.get(Calendar.HOUR_OF_DAY));
|
||||||
|
// expecting Friday 11th
|
||||||
|
assertEquals(11,result.get(Calendar.DAY_OF_MONTH));
|
||||||
|
assertEquals(Calendar.FRIDAY,result.get(Calendar.DAY_OF_WEEK));
|
||||||
|
assertEquals(Calendar.MARCH,result.get(Calendar.MONTH));
|
||||||
|
assertEquals(2011,result.get(Calendar.YEAR));
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testgetNextTimeMonth() throws MessageFormatException {
|
public void testgetNextTimeMonth() throws MessageFormatException {
|
||||||
|
|
||||||
|
|
||||||
// using an absolute date so that result will be absolute - Monday 15 Nov 2010
|
// using an absolute date so that result will be absolute - Monday 15 Nov 2010
|
||||||
Calendar current = Calendar.getInstance();
|
Calendar current = Calendar.getInstance();
|
||||||
current.set(2010, Calendar.NOVEMBER, 15, 9, 15, 30);
|
current.set(2010, Calendar.NOVEMBER, 15, 9, 15, 30);
|
||||||
System.out.println("start:" + current.getTime());
|
System.out.println("start:" + current.getTime());
|
||||||
|
|
||||||
String test = "* * * 12 *";
|
String test = "* * * 12 *";
|
||||||
long next = CronParser.getNextScheduledTime(test, current.getTimeInMillis());
|
long next = CronParser.getNextScheduledTime(test, current.getTimeInMillis());
|
||||||
|
|
||||||
Calendar result = Calendar.getInstance();
|
Calendar result = Calendar.getInstance();
|
||||||
result.setTimeInMillis(next);
|
result.setTimeInMillis(next);
|
||||||
System.out.println("next:" + result.getTime());
|
System.out.println("next:" + result.getTime());
|
||||||
|
|
||||||
assertEquals(30,result.get(Calendar.SECOND));
|
assertEquals(30,result.get(Calendar.SECOND));
|
||||||
assertEquals(15,result.get(Calendar.MINUTE));
|
assertEquals(15,result.get(Calendar.MINUTE));
|
||||||
assertEquals(9,result.get(Calendar.HOUR));
|
assertEquals(9,result.get(Calendar.HOUR));
|
||||||
|
@ -75,7 +101,7 @@ public class CronParserTest {
|
||||||
assertEquals(Calendar.DECEMBER,result.get(Calendar.MONTH));
|
assertEquals(Calendar.DECEMBER,result.get(Calendar.MONTH));
|
||||||
assertEquals(2010,result.get(Calendar.YEAR));
|
assertEquals(2010,result.get(Calendar.YEAR));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testgetNextTimeDays() throws MessageFormatException {
|
public void testgetNextTimeDays() throws MessageFormatException {
|
||||||
|
|
||||||
|
@ -84,14 +110,14 @@ public class CronParserTest {
|
||||||
Calendar current = Calendar.getInstance();
|
Calendar current = Calendar.getInstance();
|
||||||
current.set(2010, Calendar.NOVEMBER, 15, 9, 15, 30);
|
current.set(2010, Calendar.NOVEMBER, 15, 9, 15, 30);
|
||||||
System.out.println("start:" + current.getTime());
|
System.out.println("start:" + current.getTime());
|
||||||
|
|
||||||
String test = "* * 16 * *";
|
String test = "* * 16 * *";
|
||||||
long next = CronParser.getNextScheduledTime(test, current.getTimeInMillis());
|
long next = CronParser.getNextScheduledTime(test, current.getTimeInMillis());
|
||||||
|
|
||||||
Calendar result = Calendar.getInstance();
|
Calendar result = Calendar.getInstance();
|
||||||
result.setTimeInMillis(next);
|
result.setTimeInMillis(next);
|
||||||
System.out.println("next:" + result.getTime());
|
System.out.println("next:" + result.getTime());
|
||||||
|
|
||||||
assertEquals(30,result.get(Calendar.SECOND));
|
assertEquals(30,result.get(Calendar.SECOND));
|
||||||
assertEquals(15,result.get(Calendar.MINUTE));
|
assertEquals(15,result.get(Calendar.MINUTE));
|
||||||
assertEquals(9,result.get(Calendar.HOUR));
|
assertEquals(9,result.get(Calendar.HOUR));
|
||||||
|
@ -99,7 +125,7 @@ public class CronParserTest {
|
||||||
assertEquals(Calendar.NOVEMBER,result.get(Calendar.MONTH));
|
assertEquals(Calendar.NOVEMBER,result.get(Calendar.MONTH));
|
||||||
assertEquals(2010,result.get(Calendar.YEAR));
|
assertEquals(2010,result.get(Calendar.YEAR));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testgetNextTimeMinutes() throws MessageFormatException {
|
public void testgetNextTimeMinutes() throws MessageFormatException {
|
||||||
String test = "30 * * * *";
|
String test = "30 * * * *";
|
||||||
|
@ -108,22 +134,22 @@ public class CronParserTest {
|
||||||
calender.setTimeInMillis(current);
|
calender.setTimeInMillis(current);
|
||||||
System.out.println("start:" + calender.getTime());
|
System.out.println("start:" + calender.getTime());
|
||||||
long next = CronParser.getNextScheduledTime(test, current);
|
long next = CronParser.getNextScheduledTime(test, current);
|
||||||
|
|
||||||
calender.setTimeInMillis(next);
|
calender.setTimeInMillis(next);
|
||||||
System.out.println("next:" + calender.getTime());
|
System.out.println("next:" + calender.getTime());
|
||||||
long result = next - current;
|
long result = next - current;
|
||||||
assertEquals(60*10*1000,result);
|
assertEquals(60*10*1000,result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testgetNextTimeHours() throws MessageFormatException {
|
public void testgetNextTimeHours() throws MessageFormatException {
|
||||||
String test = "* 1 * * *";
|
String test = "* 1 * * *";
|
||||||
|
|
||||||
Calendar calender = Calendar.getInstance();
|
Calendar calender = Calendar.getInstance();
|
||||||
calender.set(1972, 2, 2, 17, 10, 0);
|
calender.set(1972, 2, 2, 17, 10, 0);
|
||||||
long current = calender.getTimeInMillis();
|
long current = calender.getTimeInMillis();
|
||||||
long next = CronParser.getNextScheduledTime(test, current);
|
long next = CronParser.getNextScheduledTime(test, current);
|
||||||
|
|
||||||
calender.setTimeInMillis(next);
|
calender.setTimeInMillis(next);
|
||||||
long result = next - current;
|
long result = next - current;
|
||||||
long expected = 60*1000*60*8;
|
long expected = 60*1000*60*8;
|
||||||
|
@ -133,12 +159,12 @@ public class CronParserTest {
|
||||||
@Test
|
@Test
|
||||||
public void testgetNextTimeHoursZeroMin() throws MessageFormatException {
|
public void testgetNextTimeHoursZeroMin() throws MessageFormatException {
|
||||||
String test = "0 1 * * *";
|
String test = "0 1 * * *";
|
||||||
|
|
||||||
Calendar calender = Calendar.getInstance();
|
Calendar calender = Calendar.getInstance();
|
||||||
calender.set(1972, 2, 2, 17, 10, 0);
|
calender.set(1972, 2, 2, 17, 10, 0);
|
||||||
long current = calender.getTimeInMillis();
|
long current = calender.getTimeInMillis();
|
||||||
long next = CronParser.getNextScheduledTime(test, current);
|
long next = CronParser.getNextScheduledTime(test, current);
|
||||||
|
|
||||||
calender.setTimeInMillis(next);
|
calender.setTimeInMillis(next);
|
||||||
long result = next - current;
|
long result = next - current;
|
||||||
long expected = 60*1000*60*7 + 60*1000*50;
|
long expected = 60*1000*60*7 + 60*1000*50;
|
||||||
|
@ -230,13 +256,13 @@ public class CronParserTest {
|
||||||
test = "0 1 2 3 4";
|
test = "0 1 2 3 4";
|
||||||
list = CronParser.tokenize(test);
|
list = CronParser.tokenize(test);
|
||||||
assertEquals(list.size(), 5);
|
assertEquals(list.size(), 5);
|
||||||
|
|
||||||
assertEquals(list.get(0), "0");
|
assertEquals(list.get(0), "0");
|
||||||
assertEquals(list.get(1), "1");
|
assertEquals(list.get(1), "1");
|
||||||
assertEquals(list.get(2), "2");
|
assertEquals(list.get(2), "2");
|
||||||
assertEquals(list.get(3), "3");
|
assertEquals(list.get(3), "3");
|
||||||
assertEquals(list.get(4), "4");
|
assertEquals(list.get(4), "4");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testGetNextScheduledTime() {
|
public void testGetNextScheduledTime() {
|
||||||
|
|
Loading…
Reference in New Issue