Search in sources :

Example 6 with ScheduleExpression

use of javax.ejb.ScheduleExpression in project wildfly by wildfly.

the class CalendarBasedTimeout method clone.

private ScheduleExpression clone(ScheduleExpression schedule) {
    // clone the schedule
    ScheduleExpression clonedSchedule = new ScheduleExpression();
    clonedSchedule.second(schedule.getSecond());
    clonedSchedule.minute(schedule.getMinute());
    clonedSchedule.hour(schedule.getHour());
    clonedSchedule.dayOfWeek(schedule.getDayOfWeek());
    clonedSchedule.dayOfMonth(schedule.getDayOfMonth());
    clonedSchedule.month(schedule.getMonth());
    clonedSchedule.year(schedule.getYear());
    clonedSchedule.timezone(schedule.getTimezone());
    clonedSchedule.start(schedule.getStart());
    clonedSchedule.end(schedule.getEnd());
    return clonedSchedule;
}
Also used : ScheduleExpression(javax.ejb.ScheduleExpression)

Example 7 with ScheduleExpression

use of javax.ejb.ScheduleExpression in project wildfly by wildfly.

the class CalendarBasedTimeoutTestCase method testEveryWeekdayEightFifteen.

//@Test
public void testEveryWeekdayEightFifteen() {
    ScheduleExpression everyWeekDayThreeFifteen = this.getTimezoneSpecificScheduleExpression();
    everyWeekDayThreeFifteen.minute(15);
    everyWeekDayThreeFifteen.hour(8);
    everyWeekDayThreeFifteen.dayOfWeek("Mon-Fri");
    CalendarBasedTimeout calendarTimeout = new CalendarBasedTimeout(everyWeekDayThreeFifteen);
    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);
    Assert.assertEquals(timeZoneDisplayName, 0, second);
    Assert.assertEquals(timeZoneDisplayName, 15, minute);
    Assert.assertEquals(timeZoneDisplayName, 8, hour);
    Assert.assertEquals(timeZoneDisplayName, Calendar.AM, amOrPm);
    Assert.assertTrue(timeZoneDisplayName, this.isWeekDay(firstTimeout));
    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);
        Assert.assertEquals(timeZoneDisplayName, 0, nextSecond);
        Assert.assertEquals(timeZoneDisplayName, 15, nextMinute);
        Assert.assertEquals(timeZoneDisplayName, 8, nextHour);
        Assert.assertEquals(timeZoneDisplayName, Calendar.AM, nextAmOrPm);
        Assert.assertTrue(timeZoneDisplayName, this.isWeekDay(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 8 with ScheduleExpression

use of javax.ejb.ScheduleExpression in project wildfly by wildfly.

the class CalendarBasedTimeoutTestCase method testWFLY3947_1.

/**
     * Testcase #1 for WFLY-3947
     */
@Test
public void testWFLY3947_1() {
    TimeZone timeZone = TimeZone.getTimeZone("Europe/Lisbon");
    int year = 2013;
    int month = Calendar.MARCH;
    int dayOfMonth = 31;
    int hourOfDay = 3;
    int minute = 30;
    int second = 0;
    Calendar start = new GregorianCalendar(timeZone);
    start.clear();
    start.set(year, month, dayOfMonth, hourOfDay, minute, second);
    ScheduleExpression expression = new ScheduleExpression().timezone(timeZone.getID()).dayOfMonth("*").hour("1").minute("30").second("0").start(start.getTime());
    CalendarBasedTimeout calendarTimeout = new CalendarBasedTimeout(expression);
    Calendar firstTimeout = calendarTimeout.getFirstTimeout();
    Assert.assertNotNull(firstTimeout);
    Assert.assertEquals(year, firstTimeout.get(Calendar.YEAR));
    Assert.assertEquals(Calendar.APRIL, firstTimeout.get(Calendar.MONTH));
    Assert.assertEquals(1, firstTimeout.get(Calendar.DAY_OF_MONTH));
    Assert.assertEquals(1, firstTimeout.get(Calendar.HOUR_OF_DAY));
    Assert.assertEquals(30, firstTimeout.get(Calendar.MINUTE));
    Assert.assertEquals(second, firstTimeout.get(Calendar.SECOND));
}
Also used : ScheduleExpression(javax.ejb.ScheduleExpression) TimeZone(java.util.TimeZone) CalendarBasedTimeout(org.jboss.as.ejb3.timerservice.schedule.CalendarBasedTimeout) Calendar(java.util.Calendar) GregorianCalendar(java.util.GregorianCalendar) GregorianCalendar(java.util.GregorianCalendar) Test(org.junit.Test)

Example 9 with ScheduleExpression

use of javax.ejb.ScheduleExpression in project wildfly by wildfly.

the class CalendarBasedTimeoutTestCase method testWFLY3947_2.

/**
     * Testcase #2 for WFLY-3947
     */
@Test
public void testWFLY3947_2() {
    TimeZone timeZone = TimeZone.getTimeZone("Australia/Lord_Howe");
    int year = 2013;
    int month = Calendar.OCTOBER;
    int dayOfMonth = 6;
    int hourOfDay = 2;
    int minute = 41;
    int second = 0;
    Calendar start = new GregorianCalendar(timeZone);
    start.clear();
    start.set(year, month, dayOfMonth, hourOfDay, minute, second);
    ScheduleExpression expression = new ScheduleExpression().timezone(timeZone.getID()).dayOfMonth("*").hour("2, 3").minute("20, 40").second("0").start(start.getTime());
    CalendarBasedTimeout calendarTimeout = new CalendarBasedTimeout(expression);
    Calendar firstTimeout = calendarTimeout.getFirstTimeout();
    Assert.assertNotNull(firstTimeout);
    Assert.assertEquals(year, firstTimeout.get(Calendar.YEAR));
    Assert.assertEquals(month, firstTimeout.get(Calendar.MONTH));
    Assert.assertEquals(dayOfMonth, firstTimeout.get(Calendar.DAY_OF_MONTH));
    Assert.assertEquals(3, firstTimeout.get(Calendar.HOUR_OF_DAY));
    Assert.assertEquals(20, firstTimeout.get(Calendar.MINUTE));
    Assert.assertEquals(second, firstTimeout.get(Calendar.SECOND));
}
Also used : ScheduleExpression(javax.ejb.ScheduleExpression) TimeZone(java.util.TimeZone) CalendarBasedTimeout(org.jboss.as.ejb3.timerservice.schedule.CalendarBasedTimeout) Calendar(java.util.Calendar) GregorianCalendar(java.util.GregorianCalendar) GregorianCalendar(java.util.GregorianCalendar) Test(org.junit.Test)

Example 10 with ScheduleExpression

use of javax.ejb.ScheduleExpression in project wildfly by wildfly.

the class CalendarBasedTimeoutTestCase method testWFLY5995_MinuteOverflow.

/**
     * If we have an overflow for minutes, the seconds must be reseted.
     * Test for WFLY-5995
     */
@Test
public void testWFLY5995_MinuteOverflow() {
    int year = 2016;
    int month = Calendar.JANUARY;
    int dayOfMonth = 14;
    int hourOfDay = 9;
    int minute = 46;
    int second = 42;
    Calendar start = new GregorianCalendar();
    start.clear();
    start.set(year, month, dayOfMonth, hourOfDay, minute, second);
    ScheduleExpression expression = new ScheduleExpression().dayOfMonth("*").hour("*").minute("0-45").second("0/10").start(start.getTime());
    CalendarBasedTimeout calendarTimeout = new CalendarBasedTimeout(expression);
    Calendar firstTimeout = calendarTimeout.getFirstTimeout();
    Assert.assertNotNull(firstTimeout);
    Assert.assertEquals(year, firstTimeout.get(Calendar.YEAR));
    Assert.assertEquals(month, firstTimeout.get(Calendar.MONTH));
    Assert.assertEquals(dayOfMonth, firstTimeout.get(Calendar.DAY_OF_MONTH));
    Assert.assertEquals(10, firstTimeout.get(Calendar.HOUR_OF_DAY));
    Assert.assertEquals(0, firstTimeout.get(Calendar.MINUTE));
    Assert.assertEquals(0, firstTimeout.get(Calendar.SECOND));
}
Also used : ScheduleExpression(javax.ejb.ScheduleExpression) CalendarBasedTimeout(org.jboss.as.ejb3.timerservice.schedule.CalendarBasedTimeout) Calendar(java.util.Calendar) GregorianCalendar(java.util.GregorianCalendar) GregorianCalendar(java.util.GregorianCalendar) 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