mirror of https://github.com/apache/activemq.git
Apply patch for: https://issues.apache.org/jira/browse/AMQ-3036
git-svn-id: https://svn.apache.org/repos/asf/activemq/trunk@1071411 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
e8d9b709e0
commit
e0c678e9a0
|
@ -43,7 +43,7 @@ public class CronParser {
|
|||
CronEntry hours = entries.get(HOURS);
|
||||
CronEntry dayOfMonth = entries.get(DAY_OF_MONTH);
|
||||
CronEntry month = entries.get(MONTH);
|
||||
CronEntry dayOfWeek = entries.get(DAY_OF_MONTH);
|
||||
CronEntry dayOfWeek = entries.get(DAY_OF_WEEK);
|
||||
|
||||
int currentMinutes = working.get(Calendar.MINUTE);
|
||||
if (!isCurrent(minutes, currentMinutes)) {
|
||||
|
@ -71,7 +71,7 @@ public class CronParser {
|
|||
}
|
||||
int currentDayOfMonth = working.get(Calendar.DAY_OF_MONTH);
|
||||
if (!isCurrent(dayOfMonth, currentDayOfMonth)) {
|
||||
int nextDay = getNext(dayOfMonth, currentMonth);
|
||||
int nextDay = getNext(dayOfMonth, currentDayOfMonth);
|
||||
working.add(Calendar.DAY_OF_MONTH, nextDay);
|
||||
result = working.getTimeInMillis();
|
||||
}
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
package org.apache.activemq.broker.scheduler;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import java.util.Calendar;
|
||||
|
@ -26,6 +27,79 @@ import org.junit.Test;
|
|||
|
||||
public class CronParserTest {
|
||||
|
||||
@Test
|
||||
public void testgetNextTimeDayOfWeek() throws MessageFormatException {
|
||||
|
||||
|
||||
// using an absolute date so that result will be absolute - Monday 15 Nov 2010
|
||||
Calendar current = Calendar.getInstance();
|
||||
current.set(2010, Calendar.NOVEMBER, 15, 9, 15, 30);
|
||||
System.out.println("start:" + current.getTime());
|
||||
|
||||
String test = "* * * * 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(15,result.get(Calendar.MINUTE));
|
||||
assertEquals(9,result.get(Calendar.HOUR));
|
||||
// expecting Friday 19th
|
||||
assertEquals(19,result.get(Calendar.DAY_OF_MONTH));
|
||||
assertEquals(Calendar.NOVEMBER,result.get(Calendar.MONTH));
|
||||
assertEquals(2010,result.get(Calendar.YEAR));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testgetNextTimeMonth() throws MessageFormatException {
|
||||
|
||||
|
||||
// using an absolute date so that result will be absolute - Monday 15 Nov 2010
|
||||
Calendar current = Calendar.getInstance();
|
||||
current.set(2010, Calendar.NOVEMBER, 15, 9, 15, 30);
|
||||
System.out.println("start:" + current.getTime());
|
||||
|
||||
String test = "* * * 12 *";
|
||||
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(15,result.get(Calendar.MINUTE));
|
||||
assertEquals(9,result.get(Calendar.HOUR));
|
||||
assertEquals(15,result.get(Calendar.DAY_OF_MONTH));
|
||||
assertEquals(Calendar.DECEMBER,result.get(Calendar.MONTH));
|
||||
assertEquals(2010,result.get(Calendar.YEAR));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testgetNextTimeDays() throws MessageFormatException {
|
||||
|
||||
|
||||
// using an absolute date so that result will be absolute - Monday 15 Nov 2010
|
||||
Calendar current = Calendar.getInstance();
|
||||
current.set(2010, Calendar.NOVEMBER, 15, 9, 15, 30);
|
||||
System.out.println("start:" + current.getTime());
|
||||
|
||||
String test = "* * 16 * *";
|
||||
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(15,result.get(Calendar.MINUTE));
|
||||
assertEquals(9,result.get(Calendar.HOUR));
|
||||
assertEquals(16,result.get(Calendar.DAY_OF_MONTH));
|
||||
assertEquals(Calendar.NOVEMBER,result.get(Calendar.MONTH));
|
||||
assertEquals(2010,result.get(Calendar.YEAR));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testgetNextTimeMinutes() throws MessageFormatException {
|
||||
String test = "30 * * * *";
|
||||
|
@ -153,6 +227,16 @@ public class CronParserTest {
|
|||
} catch (Throwable e) {
|
||||
}
|
||||
|
||||
test = "0 1 2 3 4";
|
||||
list = CronParser.tokenize(test);
|
||||
assertEquals(list.size(), 5);
|
||||
|
||||
assertEquals(list.get(0), "0");
|
||||
assertEquals(list.get(1), "1");
|
||||
assertEquals(list.get(2), "2");
|
||||
assertEquals(list.get(3), "3");
|
||||
assertEquals(list.get(4), "4");
|
||||
|
||||
}
|
||||
|
||||
public void testGetNextScheduledTime() {
|
||||
|
|
Loading…
Reference in New Issue