Search in sources :

Example 46 with ScheduleExpression

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

the class CancelledTimerServiceBean method createTimer.

public TimerHandle createTimer() {
    ScheduleExpression expression = new ScheduleExpression();
    expression.second("*");
    expression.minute("*");
    expression.hour("*");
    expression.dayOfMonth("*");
    expression.year("*");
    TimerConfig timerConfig = new TimerConfig();
    timerConfig.setInfo(new String("info"));
    return timerService.createCalendarTimer(expression, timerConfig).getHandle();
}
Also used : ScheduleExpression(javax.ejb.ScheduleExpression) TimerConfig(javax.ejb.TimerConfig)

Example 47 with ScheduleExpression

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

the class CalendarBasedTimeoutTestCase method testNextDayOfWeek.

private void testNextDayOfWeek(Date start) {
    ScheduleExpression expression = new ScheduleExpression();
    expression.dayOfWeek("6");
    expression.hour("3");
    expression.minute("21");
    expression.second("50");
    expression.start(start);
    CalendarBasedTimeout calendarTimeout = new CalendarBasedTimeout(expression);
    Calendar firstTimeout = calendarTimeout.getFirstTimeout();
    Assert.assertNotNull(firstTimeout);
    Assert.assertEquals(50, firstTimeout.get(Calendar.SECOND));
    Assert.assertEquals(21, firstTimeout.get(Calendar.MINUTE));
    Assert.assertEquals(3, firstTimeout.get(Calendar.HOUR_OF_DAY));
    Assert.assertEquals(7, firstTimeout.get(Calendar.DAY_OF_WEEK));
    Assert.assertEquals(29, firstTimeout.get(Calendar.DAY_OF_MONTH));
}
Also used : ScheduleExpression(javax.ejb.ScheduleExpression) CalendarBasedTimeout(org.jboss.as.ejb3.timerservice.schedule.CalendarBasedTimeout) Calendar(java.util.Calendar) GregorianCalendar(java.util.GregorianCalendar)

Example 48 with ScheduleExpression

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

the class CalendarBasedTimeoutTestCase method testEveryMorningFiveFifteen.

//@Test
public void testEveryMorningFiveFifteen() {
    ScheduleExpression everyMorningFiveFifteen = this.getTimezoneSpecificScheduleExpression();
    everyMorningFiveFifteen.minute(15);
    everyMorningFiveFifteen.hour(5);
    CalendarBasedTimeout calendarTimeout = new CalendarBasedTimeout(everyMorningFiveFifteen);
    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, 5, hour);
    Assert.assertEquals(timeZoneDisplayName, Calendar.AM, amOrPm);
    Calendar previousTimeout = firstTimeout;
    for (int i = 1; i <= 370; i++) {
        Calendar nextTimeout = calendarTimeout.getNextTimeout(previousTimeout);
        Assert.assertNotNull(timeZoneDisplayName, nextTimeout);
        Assert.assertNotNull(timeZoneDisplayName, nextTimeout.after(previousTimeout));
        //            logger.debug("First timeout was: " + firstTimeout.getTime() + " Previous timeout was: "
        //                    + previousTimeout.getTime() + " Next timeout is " + nextTimeout.getTime());
        Assert.assertEquals(timeZoneDisplayName, 0, nextTimeout.get(Calendar.SECOND));
        Assert.assertEquals(timeZoneDisplayName, 15, nextTimeout.get(Calendar.MINUTE));
        Assert.assertEquals(timeZoneDisplayName, 5, nextTimeout.get(Calendar.HOUR_OF_DAY));
        Assert.assertEquals(timeZoneDisplayName, Calendar.AM, nextTimeout.get(Calendar.AM_PM));
        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 49 with ScheduleExpression

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

the class CalendarBasedTimeoutTestCase method testDayOverflow.

/**
     * Check if the hour/minute/second is reseted correct if the day must be updated
     */
@Test
public void testDayOverflow() {
    int year = 2016;
    int month = Calendar.JANUARY;
    int dayOfMonth = 14;
    int hourOfDay = 9;
    int minute = 56;
    int second = 0;
    Calendar start = new GregorianCalendar();
    start.clear();
    start.set(year, month, dayOfMonth, hourOfDay, minute, second);
    ScheduleExpression expression = new ScheduleExpression().dayOfMonth("2-13").hour("3-9").minute("0/5").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(1, firstTimeout.get(Calendar.MONTH));
    Assert.assertEquals(2, firstTimeout.get(Calendar.DAY_OF_MONTH));
    Assert.assertEquals(3, 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)

Example 50 with ScheduleExpression

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

the class CalendarBasedTimeoutTestCase method testWFLY1468.

/**
     * WFLY-1468
     * Create a Timeout with a schedule start date in the past (day before) to ensure the time is set correctly.
     * The schedule is on the first day of month to ensure that the calculated time must be moved to the next month.
     *
     * The test is run for each day of a whole year.
     */
@Test
public void testWFLY1468() {
    ScheduleExpression schedule = new ScheduleExpression();
    int year = 2013;
    int month = Calendar.JUNE;
    int dayOfMonth = 3;
    int hourOfDay = 2;
    int minutes = 0;
    Calendar start = new GregorianCalendar(year, month, dayOfMonth, hourOfDay, minutes);
    schedule.hour("0-12").month("*").dayOfMonth("3").minute("0/5").second("0").start(start.getTime());
    CalendarBasedTimeout calendarTimeout = new CalendarBasedTimeout(schedule);
    Calendar firstTimeout = calendarTimeout.getFirstTimeout();
    // assert first timeout result
    if (firstTimeout.get(Calendar.DAY_OF_MONTH) != 3 || firstTimeout.get(Calendar.HOUR_OF_DAY) != 2 || firstTimeout.get(Calendar.MINUTE) != 0 || firstTimeout.get(Calendar.SECOND) != 0) {
        Assert.fail(firstTimeout.toString());
    }
}
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