use of javax.ejb.ScheduleExpression in project wildfly by wildfly.
the class CalendarBasedTimeoutTestCase method getTimezoneSpecificScheduleExpression.
private ScheduleExpression getTimezoneSpecificScheduleExpression() {
ScheduleExpression scheduleExpression = new ScheduleExpression().timezone(this.timezone.getID());
GregorianCalendar start = new GregorianCalendar(this.timezone);
start.clear();
start.set(2014, 0, 1, 1, 0, 0);
return scheduleExpression.start(start.getTime());
}
use of javax.ejb.ScheduleExpression in project wildfly by wildfly.
the class CalendarBasedTimeoutTestCase method testRun29thOfFeb.
//@Test
public void testRun29thOfFeb() {
ScheduleExpression everyLeapYearOn29thFeb = this.getTimezoneSpecificScheduleExpression();
everyLeapYearOn29thFeb.dayOfMonth(29);
everyLeapYearOn29thFeb.month("fEb");
CalendarBasedTimeout calendarTimeout = new CalendarBasedTimeout(everyLeapYearOn29thFeb);
Calendar firstTimeout = calendarTimeout.getFirstTimeout();
Assert.assertNotNull(timeZoneDisplayName, firstTimeout);
int minute = firstTimeout.get(Calendar.MINUTE);
int second = firstTimeout.get(Calendar.SECOND);
int hour = firstTimeout.get(Calendar.HOUR_OF_DAY);
int amOrPm = firstTimeout.get(Calendar.AM_PM);
int dayOfMonth = firstTimeout.get(Calendar.DAY_OF_MONTH);
int month = firstTimeout.get(Calendar.MONTH);
Assert.assertEquals(timeZoneDisplayName, 0, second);
Assert.assertEquals(timeZoneDisplayName, 0, minute);
Assert.assertEquals(timeZoneDisplayName, 0, hour);
Assert.assertEquals(timeZoneDisplayName, Calendar.AM, amOrPm);
Assert.assertEquals(timeZoneDisplayName, 29, dayOfMonth);
Assert.assertEquals(timeZoneDisplayName, Calendar.FEBRUARY, month);
Assert.assertTrue(timeZoneDisplayName, this.isLeapYear(firstTimeout));
Calendar previousTimeout = firstTimeout;
for (int i = 1; i <= 2; i++) {
Calendar nextTimeout = calendarTimeout.getNextTimeout(previousTimeout);
Assert.assertNotNull(timeZoneDisplayName, nextTimeout);
Assert.assertNotNull(timeZoneDisplayName, nextTimeout.after(previousTimeout));
// logger.debug("First timeout was: " + firstTimeoutDate + " Previous timeout was: " + previousTimeout.getTime()
// + " Next timeout is " + nextTimeoutDate);
int nextMinute = nextTimeout.get(Calendar.MINUTE);
int nextSecond = nextTimeout.get(Calendar.SECOND);
int nextHour = nextTimeout.get(Calendar.HOUR_OF_DAY);
int nextAmOrPm = nextTimeout.get(Calendar.AM_PM);
int nextDayOfMonth = nextTimeout.get(Calendar.DAY_OF_MONTH);
int nextMonth = nextTimeout.get(Calendar.MONTH);
Assert.assertEquals(timeZoneDisplayName, 0, nextSecond);
Assert.assertEquals(timeZoneDisplayName, 0, nextMinute);
Assert.assertEquals(timeZoneDisplayName, 0, nextHour);
Assert.assertEquals(timeZoneDisplayName, Calendar.AM, nextAmOrPm);
Assert.assertEquals(timeZoneDisplayName, 29, nextDayOfMonth);
Assert.assertEquals(timeZoneDisplayName, Calendar.FEBRUARY, nextMonth);
Assert.assertTrue(timeZoneDisplayName, this.isLeapYear(nextTimeout));
previousTimeout = nextTimeout;
}
}
use of javax.ejb.ScheduleExpression in project wildfly by wildfly.
the class CalendarBasedTimeoutTestCase method testEveryMonWedFriTwelveThirtyNoon.
//@Test
public void testEveryMonWedFriTwelveThirtyNoon() {
ScheduleExpression everyMonWedFriTwelveThirtyNoon = this.getTimezoneSpecificScheduleExpression();
everyMonWedFriTwelveThirtyNoon.hour(12);
everyMonWedFriTwelveThirtyNoon.second("30");
everyMonWedFriTwelveThirtyNoon.dayOfWeek("Mon,Wed,Fri");
CalendarBasedTimeout calendarTimeout = new CalendarBasedTimeout(everyMonWedFriTwelveThirtyNoon);
Calendar firstTimeout = calendarTimeout.getFirstTimeout();
Assert.assertNotNull(timeZoneDisplayName, firstTimeout);
int minute = firstTimeout.get(Calendar.MINUTE);
int second = firstTimeout.get(Calendar.SECOND);
int hour = firstTimeout.get(Calendar.HOUR_OF_DAY);
int amOrPm = firstTimeout.get(Calendar.AM_PM);
int dayOfWeek = firstTimeout.get(Calendar.DAY_OF_WEEK);
Assert.assertEquals(timeZoneDisplayName, 30, second);
Assert.assertEquals(timeZoneDisplayName, 0, minute);
Assert.assertEquals(timeZoneDisplayName, 12, hour);
Assert.assertEquals(timeZoneDisplayName, Calendar.PM, amOrPm);
List<Integer> validDays = new ArrayList<Integer>();
validDays.add(Calendar.MONDAY);
validDays.add(Calendar.WEDNESDAY);
validDays.add(Calendar.FRIDAY);
Assert.assertTrue(timeZoneDisplayName, validDays.contains(dayOfWeek));
Calendar previousTimeout = firstTimeout;
for (int i = 1; i <= 180; i++) {
Calendar nextTimeout = calendarTimeout.getNextTimeout(previousTimeout);
Assert.assertNotNull(timeZoneDisplayName, nextTimeout);
Assert.assertNotNull(timeZoneDisplayName, nextTimeout.after(previousTimeout));
// logger.debug("First timeout was: " + firstTimeoutDate + " Previous timeout was: " + previousTimeout.getTime()
// + " Next timeout is " + nextTimeoutDate);
int nextMinute = nextTimeout.get(Calendar.MINUTE);
int nextSecond = nextTimeout.get(Calendar.SECOND);
int nextHour = nextTimeout.get(Calendar.HOUR_OF_DAY);
int nextAmOrPm = nextTimeout.get(Calendar.AM_PM);
int nextDayOfWeek = nextTimeout.get(Calendar.DAY_OF_WEEK);
Assert.assertEquals(timeZoneDisplayName, 30, nextSecond);
Assert.assertEquals(timeZoneDisplayName, 0, nextMinute);
Assert.assertEquals(timeZoneDisplayName, 12, nextHour);
Assert.assertEquals(timeZoneDisplayName, Calendar.PM, nextAmOrPm);
Assert.assertTrue(timeZoneDisplayName, validDays.contains(nextDayOfWeek));
previousTimeout = nextTimeout;
}
}
use of javax.ejb.ScheduleExpression in project wildfly by wildfly.
the class CalendarBasedTimeoutTestCase method testEvery10Seconds.
//@Test
public void testEvery10Seconds() {
ScheduleExpression every10Secs = this.getTimezoneSpecificScheduleExpression();
every10Secs.second("*/10");
every10Secs.minute("*");
every10Secs.hour("*");
CalendarBasedTimeout calendarTimeout = new CalendarBasedTimeout(every10Secs);
Calendar firstTimeout = calendarTimeout.getFirstTimeout();
int firstTimeoutSecond = firstTimeout.get(Calendar.SECOND);
Assert.assertTrue(timeZoneDisplayName, firstTimeoutSecond % 10 == 0);
Calendar previousTimeout = firstTimeout;
for (int i = 0; i < 5; i++) {
Calendar nextTimeout = calendarTimeout.getNextTimeout(previousTimeout);
int nextTimeoutSecond = nextTimeout.get(Calendar.SECOND);
Assert.assertTrue(timeZoneDisplayName, nextTimeoutSecond % 10 == 0);
previousTimeout = nextTimeout;
}
}
use of javax.ejb.ScheduleExpression in project tomee by apache.
the class EJBCronTriggerTest method testRangeCDayOfWeek.
@Test(timeout = 500)
public void testRangeCDayOfWeek() throws ParseException {
final ScheduleExpression expr = new ScheduleExpression().dayOfWeek("0-7").hour(23).minute(1).second(59).start(new Date(0));
final EJBCronTrigger trigger = new EJBCronTrigger(expr);
assertEquals(new GregorianCalendar(2010, 5, 29, 23, 1, 59).getTime(), trigger.getFireTimeAfter(new GregorianCalendar(2010, 5, 29, 23, 0, 0).getTime()));
assertEquals(new GregorianCalendar(2010, 5, 30, 23, 1, 59).getTime(), trigger.getFireTimeAfter(new GregorianCalendar(2010, 5, 29, 23, 2, 0).getTime()));
assertEquals(new GregorianCalendar(2010, 6, 1, 23, 1, 59).getTime(), trigger.getFireTimeAfter(new GregorianCalendar(2010, 6, 1, 23, 0, 0).getTime()));
assertEquals(new GregorianCalendar(2010, 6, 2, 23, 1, 59).getTime(), trigger.getFireTimeAfter(new GregorianCalendar(2010, 6, 1, 23, 3, 0).getTime()));
assertEquals(new GregorianCalendar(2010, 6, 2, 23, 1, 59).getTime(), trigger.getFireTimeAfter(new GregorianCalendar(2010, 6, 2, 23, 0, 0).getTime()));
assertEquals(new GregorianCalendar(2010, 6, 3, 23, 1, 59).getTime(), trigger.getFireTimeAfter(new GregorianCalendar(2010, 6, 2, 23, 2, 0).getTime()));
}
Aggregations