Search in sources :

Example 11 with ScheduleExpression

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());
}
Also used : ScheduleExpression(javax.ejb.ScheduleExpression) GregorianCalendar(java.util.GregorianCalendar)

Example 12 with ScheduleExpression

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;
    }
}
Also used : ScheduleExpression(javax.ejb.ScheduleExpression) CalendarBasedTimeout(org.jboss.as.ejb3.timerservice.schedule.CalendarBasedTimeout) Calendar(java.util.Calendar) GregorianCalendar(java.util.GregorianCalendar)

Example 13 with ScheduleExpression

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;
    }
}
Also used : ScheduleExpression(javax.ejb.ScheduleExpression) CalendarBasedTimeout(org.jboss.as.ejb3.timerservice.schedule.CalendarBasedTimeout) Calendar(java.util.Calendar) GregorianCalendar(java.util.GregorianCalendar) ArrayList(java.util.ArrayList)

Example 14 with ScheduleExpression

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;
    }
}
Also used : ScheduleExpression(javax.ejb.ScheduleExpression) CalendarBasedTimeout(org.jboss.as.ejb3.timerservice.schedule.CalendarBasedTimeout) Calendar(java.util.Calendar) GregorianCalendar(java.util.GregorianCalendar)

Example 15 with ScheduleExpression

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()));
}
Also used : ScheduleExpression(javax.ejb.ScheduleExpression) EJBCronTrigger(org.apache.openejb.core.timer.EJBCronTrigger) GregorianCalendar(java.util.GregorianCalendar) Date(java.util.Date) Test(org.junit.Test)

Aggregations

ScheduleExpression (javax.ejb.ScheduleExpression)75 GregorianCalendar (java.util.GregorianCalendar)60 Test (org.junit.Test)52 EJBCronTrigger (org.apache.openejb.core.timer.EJBCronTrigger)44 Date (java.util.Date)34 Calendar (java.util.Calendar)21 CalendarBasedTimeout (org.jboss.as.ejb3.timerservice.schedule.CalendarBasedTimeout)17 TimerConfig (javax.ejb.TimerConfig)4 TimeZone (java.util.TimeZone)3 ArrayList (java.util.ArrayList)2 ParseException (org.apache.openejb.core.timer.EJBCronTrigger.ParseException)2 IOException (java.io.IOException)1 PreparedStatement (java.sql.PreparedStatement)1 ResultSet (java.sql.ResultSet)1 PostConstruct (javax.annotation.PostConstruct)1 EJBException (javax.ejb.EJBException)1 NoSuchObjectLocalException (javax.ejb.NoSuchObjectLocalException)1 ScheduleData (org.apache.openejb.core.timer.ScheduleData)1 AutoTimer (org.jboss.as.ejb3.timerservice.AutoTimer)1 ModelNode (org.jboss.dmr.ModelNode)1