tomee-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From genspr...@apache.org
Subject svn commit: r1141376 - in /openejb/trunk/openejb3/container/openejb-core/src: main/java/org/apache/openejb/core/timer/EJBCronTrigger.java test/java/org/apache/openejb/timer/EJBCronTriggerTest.java
Date Thu, 30 Jun 2011 03:19:10 GMT
Author: genspring
Date: Thu Jun 30 03:19:10 2011
New Revision: 1141376

URL: http://svn.apache.org/viewvc?rev=1141376&view=rev
Log:
OPENEJB-1622 Adding more boundary condition handling in cron calendar timer.

Support simple day of Week  at the end of month.

Modified:
    openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/timer/EJBCronTrigger.java
    openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/timer/EJBCronTriggerTest.java

Modified: openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/timer/EJBCronTrigger.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/timer/EJBCronTrigger.java?rev=1141376&r1=1141375&r2=1141376&view=diff
==============================================================================
--- openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/timer/EJBCronTrigger.java
(original)
+++ openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/timer/EJBCronTrigger.java
Thu Jun 30 03:19:10 2011
@@ -452,7 +452,6 @@ public class EJBCronTrigger extends Trig
 
            
             FieldExpression expr = expressions[currentFieldIndex];
-            int oldValue1 = calendar.get(expr.field);
             Integer value = expr.getNextValue(calendar);
 
             /*
@@ -462,16 +461,16 @@ public class EJBCronTrigger extends Trig
              * two fields need not match the current day).
              */
             if (currentFieldIndex == 2 && !(expressions[3] instanceof AsteriskExpression))
{
-                Calendar calendarDayOfWeek = (Calendar) calendar.clone();
-                Integer nextDayOfWeek = expressions[3].getNextValue(calendarDayOfWeek);
+                Calendar clonedCalendarDayOfWeek = (Calendar) calendar.clone();
+                Integer nextDayOfWeek = expressions[3].getNextValue(clonedCalendarDayOfWeek);
                 while (nextDayOfWeek == null) {
-                    calendarDayOfWeek.add(Calendar.DAY_OF_MONTH, 1);
-                    nextDayOfWeek = expressions[3].getNextValue(calendarDayOfWeek);
+                    clonedCalendarDayOfWeek.add(Calendar.DAY_OF_MONTH, 1);
+                    nextDayOfWeek = expressions[3].getNextValue(clonedCalendarDayOfWeek);
                 }
 
                 if (nextDayOfWeek != null) {
-                    calendarDayOfWeek.set(expressions[3].field, nextDayOfWeek);
-                    int newDayOfMonth = calendarDayOfWeek.get(expressions[2].field);
+                    clonedCalendarDayOfWeek.set(expressions[3].field, nextDayOfWeek);
+                    int newDayOfMonth = clonedCalendarDayOfWeek.get(expressions[2].field);
                     
                     if (value == null) {
                         value = newDayOfMonth;
@@ -479,7 +478,12 @@ public class EJBCronTrigger extends Trig
                         value = Math.min(value, newDayOfMonth);
                     }
                     //Next valid DayOfWeek might exist in next month.
-                    calendar.set(Calendar.MONTH, calendarDayOfWeek.get(Calendar.MONTH));
+                    
+                    if(expressions[1].getNextValue(clonedCalendarDayOfWeek)==null){
+                        return null;
+                    }else {
+                        calendar.set(Calendar.MONTH, clonedCalendarDayOfWeek.get(Calendar.MONTH));
+                    }
                 }
             }
 

Modified: openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/timer/EJBCronTriggerTest.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/timer/EJBCronTriggerTest.java?rev=1141376&r1=1141375&r2=1141376&view=diff
==============================================================================
--- openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/timer/EJBCronTriggerTest.java
(original)
+++ openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/timer/EJBCronTriggerTest.java
Thu Jun 30 03:19:10 2011
@@ -270,6 +270,13 @@ public class EJBCronTriggerTest {
        EJBCronTrigger trigger = new EJBCronTrigger(expr);
        assertEquals(new GregorianCalendar(2011, 4, 6, 14, 1, 59).getTime(), trigger.getFireTimeAfter(new
GregorianCalendar(2011, 4, 5, 23, 1, 30).getTime()));
    }
+   
+   @Test(timeout = 5000)
+   public void testSimpleDayOfWeekC() throws ParseException {
+       ScheduleExpression expr = new ScheduleExpression().year(2011).month(6).dayOfWeek("3").hour(22).minute(1).second(1).start(new
Date(0));;
+       EJBCronTrigger trigger = new EJBCronTrigger(expr);
+       assertEquals(null, trigger.getFireTimeAfter(new GregorianCalendar(2011, 5, 29, 23,
1, 1).getTime()));
+   }      
 
    
    @Test(timeout = 5000)



Mime
View raw message