Search in sources :

Example 36 with ScheduleExpression

use of javax.ejb.ScheduleExpression in project tomee by apache.

the class EJBCronTriggerTest method testSimpleDayOfWeek.

@Test(timeout = 500)
public void testSimpleDayOfWeek() throws ParseException {
    final ScheduleExpression expr = new ScheduleExpression().dayOfWeek("7").hour(23).minute(1).second(59).start(new Date(0));
    ;
    final EJBCronTrigger trigger = new EJBCronTrigger(expr);
    assertEquals(new GregorianCalendar(2011, 4, 8, 23, 1, 59).getTime(), trigger.getFireTimeAfter(new GregorianCalendar(2011, 4, 5, 23, 1, 30).getTime()));
}
Also used : ScheduleExpression(javax.ejb.ScheduleExpression) EJBCronTrigger(org.apache.openejb.core.timer.EJBCronTrigger) GregorianCalendar(java.util.GregorianCalendar) Date(java.util.Date) Test(org.junit.Test)

Example 37 with ScheduleExpression

use of javax.ejb.ScheduleExpression in project tomee by apache.

the class EJBCronTriggerTest method testBothDayOfMonthAndDayOfWeekH.

@Test(timeout = 5000)
public void testBothDayOfMonthAndDayOfWeekH() throws ParseException {
    final ScheduleExpression expr = new ScheduleExpression().year(2011).dayOfMonth("28").dayOfWeek("3").hour(20).minute(59).second(59).start(new GregorianCalendar(2011, 5, 11, 20, 59, 58).getTime());
    final EJBCronTrigger trigger = new EJBCronTrigger(expr);
    assertEquals(new GregorianCalendar(2011, 6, 28, 20, 59, 59).getTime(), trigger.getFireTimeAfter(new GregorianCalendar(2011, 6, 27, 21, 59, 59).getTime()));
}
Also used : ScheduleExpression(javax.ejb.ScheduleExpression) EJBCronTrigger(org.apache.openejb.core.timer.EJBCronTrigger) GregorianCalendar(java.util.GregorianCalendar) Test(org.junit.Test)

Example 38 with ScheduleExpression

use of javax.ejb.ScheduleExpression in project tomee by apache.

the class EJBCronTriggerTest method testIncrementsA.

@Test(timeout = 1000)
public void testIncrementsA() throws ParseException {
    final ScheduleExpression expr = new ScheduleExpression().year(2008).month(1).dayOfMonth(20).hour("6/3").minute(30).start(new Date(0));
    final EJBCronTrigger trigger = new EJBCronTrigger(expr);
    // Should fire on Sunday, January 20th, first at 6:30
    Calendar calendar = new GregorianCalendar(2008, 0, 20);
    Date startTime = new Date(calendar.getTimeInMillis() - 1000);
    calendar.set(Calendar.HOUR_OF_DAY, 6);
    calendar.set(Calendar.MINUTE, 30);
    assertEquals(calendar.getTime(), trigger.getFireTimeAfter(startTime));
    // Next on 9:30
    startTime = new Date(calendar.getTimeInMillis());
    calendar.set(Calendar.HOUR_OF_DAY, 9);
    assertEquals(calendar.getTime(), trigger.getFireTimeAfter(startTime));
    // Won't be fired after the 20th so it should return null
    calendar = new GregorianCalendar(2008, 0, 21);
    startTime = new Date(calendar.getTimeInMillis());
    assertNull(trigger.getFireTimeAfter(startTime));
}
Also used : ScheduleExpression(javax.ejb.ScheduleExpression) EJBCronTrigger(org.apache.openejb.core.timer.EJBCronTrigger) Calendar(java.util.Calendar) GregorianCalendar(java.util.GregorianCalendar) GregorianCalendar(java.util.GregorianCalendar) Date(java.util.Date) Test(org.junit.Test)

Example 39 with ScheduleExpression

use of javax.ejb.ScheduleExpression in project tomee by apache.

the class EJBCronTriggerTest method testRangeYearsB.

@Test(timeout = 500)
public void testRangeYearsB() throws ParseException {
    final ScheduleExpression expr = new ScheduleExpression().year("2013-2016").month(2).dayOfMonth(29).hour(23).minute(1).second(0).start(new Date(0));
    ;
    final EJBCronTrigger trigger = new EJBCronTrigger(expr);
    assertEquals(new GregorianCalendar(2016, 1, 29, 23, 1, 0).getTime(), trigger.getFireTimeAfter(new GregorianCalendar(2011, 1, 1, 23, 0, 0).getTime()));
}
Also used : ScheduleExpression(javax.ejb.ScheduleExpression) EJBCronTrigger(org.apache.openejb.core.timer.EJBCronTrigger) GregorianCalendar(java.util.GregorianCalendar) Date(java.util.Date) Test(org.junit.Test)

Example 40 with ScheduleExpression

use of javax.ejb.ScheduleExpression in project tomee by apache.

the class EJBCronTriggerTest method testOrdinalNumbersDayOfMonthD.

@Test(timeout = 5000)
public void testOrdinalNumbersDayOfMonthD() throws ParseException {
    final ScheduleExpression expr = new ScheduleExpression().dayOfMonth("1st sun").hour(23).minute(1).second(59);
    final EJBCronTrigger trigger = new EJBCronTrigger(expr);
    assertEquals(new GregorianCalendar(2100, 1, 7, 23, 1, 59).getTime(), trigger.getFireTimeAfter(new GregorianCalendar(2100, 1, 1, 0, 0, 0).getTime()));
}
Also used : ScheduleExpression(javax.ejb.ScheduleExpression) EJBCronTrigger(org.apache.openejb.core.timer.EJBCronTrigger) 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