Search in sources :

Example 1 with CalendarBasedTimeout

use of org.jboss.as.ejb3.timerservice.schedule.CalendarBasedTimeout in project wildfly by wildfly.

the class CalendarBasedTimeoutWithDifferentTimeZoneTestCase method testScheduledTimezoneDifferentThanCurrentSystem.

@Test
public void testScheduledTimezoneDifferentThanCurrentSystem() {
    // This tests replicates an automatic timer below being deployed in a system whose default timezone is America/Chicago
    // @Schedule(persistent = false, timezone = "America/New_York", dayOfMonth = "*", dayOfWeek = "*", month = "*", hour =
    // "2", minute = "*", second = "0", year = "*")
    // The schedule for the timer is to fire every minute where the hour is 2 in the America/New_York timezone
    ScheduleExpression sch = new ScheduleExpression();
    sch.timezone("America/New_York");
    sch.dayOfMonth("*");
    sch.dayOfWeek("*");
    sch.month("*");
    sch.hour("2");
    sch.minute("*");
    sch.second("0");
    sch.year("*");
    CalendarBasedTimeout calendarTimeout = new CalendarBasedTimeout(sch);
    Calendar firstTimeout = calendarTimeout.getFirstTimeout();
    Assert.assertNotNull("first timeout is null", firstTimeout);
    logger.info("First timeout is " + firstTimeout.getTime());
    // currentCal sets up a dummy time in the future, the timezone is America/Chicago in which this imaginary system is
    // running
    TimeZone currentTimezone = TimeZone.getTimeZone("America/Chicago");
    Calendar currentCal = new GregorianCalendar(currentTimezone);
    currentCal.set(Calendar.YEAR, 2014);
    currentCal.set(Calendar.MONTH, 1);
    currentCal.set(Calendar.DATE, 8);
    currentCal.set(Calendar.HOUR_OF_DAY, 1);
    currentCal.set(Calendar.MINUTE, 1);
    currentCal.set(Calendar.SECOND, 1);
    currentCal.set(Calendar.MILLISECOND, 0);
    // https://issues.jboss.org/browse/WFLY-2840 - @Schedule EJB Timer not using timezone when calcualting next timeout
    // Next test WFLY-2840, by calling getNextTimeout with the dummy time above, the expected result is for the timer to
    // fire at 1:02:00
    // If the bug is not fixed it will return 2:00:00
    Calendar nextTimeout = calendarTimeout.getNextTimeout(currentCal);
    logger.info("Next timeout is " + nextTimeout.getTime());
    Calendar expectedCal = new GregorianCalendar(currentTimezone);
    expectedCal.set(Calendar.YEAR, 2014);
    expectedCal.set(Calendar.MONTH, 1);
    expectedCal.set(Calendar.DATE, 8);
    expectedCal.set(Calendar.HOUR_OF_DAY, 1);
    expectedCal.set(Calendar.MINUTE, 2);
    expectedCal.set(Calendar.SECOND, 0);
    expectedCal.set(Calendar.MILLISECOND, 0);
    Assert.assertEquals("[WFLY-2840] Next timeout should be: " + expectedCal.getTime(), expectedCal.getTime(), nextTimeout.getTime());
}
Also used : ScheduleExpression(javax.ejb.ScheduleExpression) CalendarBasedTimeout(org.jboss.as.ejb3.timerservice.schedule.CalendarBasedTimeout) TimeZone(java.util.TimeZone) Calendar(java.util.Calendar) GregorianCalendar(java.util.GregorianCalendar) GregorianCalendar(java.util.GregorianCalendar) Test(org.junit.Test)

Example 2 with CalendarBasedTimeout

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

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

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

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

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