Search in sources :

Example 11 with CalendarBasedTimeout

use of org.jboss.as.ejb3.timerservice.schedule.CalendarBasedTimeout 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 12 with CalendarBasedTimeout

use of org.jboss.as.ejb3.timerservice.schedule.CalendarBasedTimeout 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)

Example 13 with CalendarBasedTimeout

use of org.jboss.as.ejb3.timerservice.schedule.CalendarBasedTimeout 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 14 with CalendarBasedTimeout

use of org.jboss.as.ejb3.timerservice.schedule.CalendarBasedTimeout 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 15 with CalendarBasedTimeout

use of org.jboss.as.ejb3.timerservice.schedule.CalendarBasedTimeout 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)

Aggregations

Calendar (java.util.Calendar)17 GregorianCalendar (java.util.GregorianCalendar)17 ScheduleExpression (javax.ejb.ScheduleExpression)17 CalendarBasedTimeout (org.jboss.as.ejb3.timerservice.schedule.CalendarBasedTimeout)17 Test (org.junit.Test)7 TimeZone (java.util.TimeZone)3 ArrayList (java.util.ArrayList)2