Search in sources :

Example 51 with ScheduleExpression

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

the class CalendarBasedTimeoutTestCase method testSomeSpecificTime.

//@Test
public void testSomeSpecificTime() {
    ScheduleExpression every0_15_30_Sec_At_9_30_PM = this.getTimezoneSpecificScheduleExpression();
    every0_15_30_Sec_At_9_30_PM.dayOfMonth(31);
    every0_15_30_Sec_At_9_30_PM.month("Nov-Feb");
    every0_15_30_Sec_At_9_30_PM.second("0,15,30");
    every0_15_30_Sec_At_9_30_PM.minute(30);
    every0_15_30_Sec_At_9_30_PM.hour("21");
    CalendarBasedTimeout calendarTimeout = new CalendarBasedTimeout(every0_15_30_Sec_At_9_30_PM);
    Calendar firstTimeout = calendarTimeout.getFirstTimeout();
    Assert.assertNotNull(timeZoneDisplayName, firstTimeout);
    //        logger.debug("First timeout is " + firstTimeoutDate);
    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, 30, minute);
    Assert.assertEquals(timeZoneDisplayName, 21, hour);
    Assert.assertEquals(timeZoneDisplayName, Calendar.PM, amOrPm);
    Assert.assertEquals(timeZoneDisplayName, 31, dayOfMonth);
    List<Integer> validMonths = new ArrayList<Integer>();
    validMonths.add(Calendar.NOVEMBER);
    validMonths.add(Calendar.DECEMBER);
    validMonths.add(Calendar.JANUARY);
    validMonths.add(Calendar.FEBRUARY);
    Assert.assertTrue(timeZoneDisplayName, validMonths.contains(month));
    Calendar nextTimeout = calendarTimeout.getNextTimeout(firstTimeout);
    long diff = nextTimeout.getTimeInMillis() - firstTimeout.getTimeInMillis();
    Assert.assertEquals(timeZoneDisplayName, 15 * 1000, diff);
    Calendar date = new GregorianCalendar(2014, 3, 18);
    Calendar nextTimeoutFromNow = calendarTimeout.getNextTimeout(date);
    //        logger.debug("Next timeout from now is " + nextTimeoutFromNow.getTime());
    int nextMinute = nextTimeoutFromNow.get(Calendar.MINUTE);
    int nextSecond = nextTimeoutFromNow.get(Calendar.SECOND);
    int nextHour = nextTimeoutFromNow.get(Calendar.HOUR_OF_DAY);
    int nextAmOrPM = nextTimeoutFromNow.get(Calendar.AM_PM);
    int nextDayOfMonth = nextTimeoutFromNow.get(Calendar.DAY_OF_MONTH);
    int nextMonth = nextTimeoutFromNow.get(Calendar.MONTH);
    List<Integer> validSeconds = new ArrayList<Integer>();
    validSeconds.add(0);
    validSeconds.add(15);
    validSeconds.add(30);
    Assert.assertTrue(timeZoneDisplayName, validSeconds.contains(nextSecond));
    Assert.assertEquals(timeZoneDisplayName, 30, nextMinute);
    Assert.assertEquals(timeZoneDisplayName, 21, nextHour);
    Assert.assertEquals(timeZoneDisplayName, Calendar.PM, nextAmOrPM);
    Assert.assertEquals(timeZoneDisplayName, 31, nextDayOfMonth);
    Assert.assertTrue(timeZoneDisplayName, validMonths.contains(nextMonth));
}
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) GregorianCalendar(java.util.GregorianCalendar)

Example 52 with ScheduleExpression

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

the class CalendarBasedTimeoutTestCase method testWFLY5995_HourOverflow.

/**
     * If we have an overflow for hours, the minutes and seconds must be reseted.
     * Test for WFLY-5995
     */
@Test
public void testWFLY5995_HourOverflow() {
    int year = 2016;
    int month = Calendar.JANUARY;
    int dayOfMonth = 14;
    int hourOfDay = 9;
    int minute = 45;
    int second = 35;
    Calendar start = new GregorianCalendar();
    start.clear();
    start.set(year, month, dayOfMonth, hourOfDay, minute, second);
    ScheduleExpression expression = new ScheduleExpression().dayOfMonth("*").hour("20-22").minute("0/5").second("20,40").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(20, firstTimeout.get(Calendar.HOUR_OF_DAY));
    Assert.assertEquals(0, firstTimeout.get(Calendar.MINUTE));
    Assert.assertEquals(20, 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 53 with ScheduleExpression

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

the class CalendarBasedTimeoutTestCase method testEverySecondTimeout.

//@Test
public void testEverySecondTimeout() {
    ScheduleExpression everySecondExpression = this.getTimezoneSpecificScheduleExpression();
    everySecondExpression.second("*");
    everySecondExpression.minute("*");
    everySecondExpression.hour("*");
    CalendarBasedTimeout calendarTimeout = new CalendarBasedTimeout(everySecondExpression);
    Calendar firstTimeout = calendarTimeout.getFirstTimeout();
    Calendar nextTimeout = calendarTimeout.getNextTimeout(firstTimeout);
    Assert.assertNotNull(timeZoneDisplayName, nextTimeout);
    Assert.assertNotNull(timeZoneDisplayName, nextTimeout.after(firstTimeout));
    //        logger.debug("Previous timeout was: " + firstTimeout.getTime() + " Next timeout is " + nextTimeout.getTime());
    long diff = nextTimeout.getTimeInMillis() - firstTimeout.getTimeInMillis();
    Assert.assertEquals(timeZoneDisplayName, 1000, diff);
}
Also used : ScheduleExpression(javax.ejb.ScheduleExpression) CalendarBasedTimeout(org.jboss.as.ejb3.timerservice.schedule.CalendarBasedTimeout) Calendar(java.util.Calendar) GregorianCalendar(java.util.GregorianCalendar)

Example 54 with ScheduleExpression

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

the class CalendarBasedTimeoutTestCase method testEveryMinuteEveryHourEveryDay.

//@Test
public void testEveryMinuteEveryHourEveryDay() {
    ScheduleExpression everyMinEveryHourEveryDay = this.getTimezoneSpecificScheduleExpression();
    everyMinEveryHourEveryDay.minute("*");
    everyMinEveryHourEveryDay.hour("*");
    CalendarBasedTimeout calendarTimeout = new CalendarBasedTimeout(everyMinEveryHourEveryDay);
    Calendar firstTimeout = calendarTimeout.getFirstTimeout();
    Calendar previousTimeout = firstTimeout;
    for (int i = 1; i <= 65; 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());
        long diff = nextTimeout.getTimeInMillis() - previousTimeout.getTimeInMillis();
        long diffWithFirstTimeout = nextTimeout.getTimeInMillis() - firstTimeout.getTimeInMillis();
        Assert.assertEquals(timeZoneDisplayName, 60 * 1000, diff);
        Assert.assertEquals(timeZoneDisplayName, 60 * 1000 * i, diffWithFirstTimeout);
        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 55 with ScheduleExpression

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

the class CalendarBasedTimeoutTestCase method testEvery31stOfTheMonth.

//@Test
public void testEvery31stOfTheMonth() {
    ScheduleExpression every31st9_30_15_AM = this.getTimezoneSpecificScheduleExpression();
    every31st9_30_15_AM.dayOfMonth(31);
    every31st9_30_15_AM.hour(9);
    every31st9_30_15_AM.minute("30");
    every31st9_30_15_AM.second(15);
    CalendarBasedTimeout calendarTimeout = new CalendarBasedTimeout(every31st9_30_15_AM);
    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);
    Assert.assertEquals(timeZoneDisplayName, 15, second);
    Assert.assertEquals(timeZoneDisplayName, 30, minute);
    Assert.assertEquals(timeZoneDisplayName, 9, hour);
    Assert.assertEquals(timeZoneDisplayName, Calendar.AM, amOrPm);
    Assert.assertEquals(timeZoneDisplayName, 31, dayOfMonth);
    Calendar previousTimeout = firstTimeout;
    for (int i = 1; i <= 18; 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);
        Assert.assertEquals(timeZoneDisplayName, 15, nextSecond);
        Assert.assertEquals(timeZoneDisplayName, 30, nextMinute);
        Assert.assertEquals(timeZoneDisplayName, 9, nextHour);
        Assert.assertEquals(timeZoneDisplayName, Calendar.AM, nextAmOrPm);
        Assert.assertEquals(timeZoneDisplayName, 31, nextDayOfMonth);
        previousTimeout = nextTimeout;
    }
}
Also used : ScheduleExpression(javax.ejb.ScheduleExpression) CalendarBasedTimeout(org.jboss.as.ejb3.timerservice.schedule.CalendarBasedTimeout) Calendar(java.util.Calendar) GregorianCalendar(java.util.GregorianCalendar)

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