tomee-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From genspr...@apache.org
Subject svn commit: r1134566 - 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 Sat, 11 Jun 2011 10:43:56 GMT
Author: genspring
Date: Sat Jun 11 10:43:56 2011
New Revision: 1134566

URL: http://svn.apache.org/viewvc?rev=1134566&view=rev
Log:
OPENEJB-1542 Implement the Expression Rules defined in ejb3.1 spec 18.2.1.2, additional fix
and unit tests.

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=1134566&r1=1134565&r2=1134566&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
Sat Jun 11 10:43:56 2011
@@ -450,7 +450,9 @@ public class EJBCronTrigger extends Trig
 		
         while (currentFieldIndex <= 6 && calendar.before(stopCalendar)) {
 
+           
             FieldExpression expr = expressions[currentFieldIndex];
+            int oldValue1 = calendar.get(expr.field);
             Integer value = expr.getNextValue(calendar);
 
             /*
@@ -482,21 +484,42 @@ public class EJBCronTrigger extends Trig
             }
 
             if (currentFieldIndex >= 1 && value == null) {
-                // No suitable value was found, so move back to the previous field
-                // and increase the value
-                // When current field is HOUR_OF_DAY, its upper field is DAY_OF_MONTH, so
we need to -2 due to DAY_OF_WEEK.
-                int parentFieldIndex = currentFieldIndex == 4 ? currentFieldIndex - 2 : currentFieldIndex
- 1;
-                int maxAffectedFieldType = upadteCalendar(calendar, expressions[parentFieldIndex].field,
1);
-                currentFieldIndex = CALENDAR_FIELD_TYPE_ORDERED_INDEX_MAP.get(maxAffectedFieldType);
-                resetFields(calendar, maxAffectedFieldType, false);
+
+                if (currentFieldIndex == 3 && !(expressions[2] instanceof AsteriskExpression))
{
+                    /*
+                     *18.2.1.2 Expression Rules, the day has been resolved when dayOfMonth
expression
+                     *is not AsteriskExpression.
+                     */
+                    currentFieldIndex++;
+                } else {
+                    // No suitable value was found, so move back to the previous field
+                    // and increase the value
+                    // When current field is HOUR_OF_DAY, its upper field is DAY_OF_MONTH,
so we need to -2 due to
+                    // DAY_OF_WEEK.
+                    int parentFieldIndex = currentFieldIndex == 4 ? currentFieldIndex - 2
: currentFieldIndex - 1;
+                    int maxAffectedFieldType = upadteCalendar(calendar, expressions[parentFieldIndex].field,
1);
+                    currentFieldIndex = CALENDAR_FIELD_TYPE_ORDERED_INDEX_MAP.get(maxAffectedFieldType);
+                    resetFields(calendar, maxAffectedFieldType, false);
+                }
+                
             } else if (value != null) {
+                
                 int oldValue = calendar.get(expr.field);
                 if (oldValue != value) {
-                    // The value has changed, so update the calendar and reset all
-                    // less significant fields
-                    calendar.set(expr.field, value);
-                    resetFields(calendar, expr.field, false);
-                    currentFieldIndex++;
+                    
+                    if (currentFieldIndex == 3 && !(expressions[2] instanceof AsteriskExpression))
{
+                        /*
+                         *18.2.1.2 Expression Rules, the day has been resolved when dayOfMonth
expression
+                         *is not AsteriskExpression.
+                         */
+                        currentFieldIndex++;
+                    } else {
+                        // The value has changed, so update the calendar and reset all
+                        // less significant fields
+                        calendar.set(expr.field, value);
+                        resetFields(calendar, expr.field, false);
+                        currentFieldIndex++;
+                    }
                 } else {
                     currentFieldIndex++;
                 }

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=1134566&r1=1134565&r2=1134566&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
Sat Jun 11 10:43:56 2011
@@ -157,14 +157,34 @@ public class EJBCronTriggerTest {
        assertEquals(new GregorianCalendar(2011, 4, 18, 23, 59, 59).getTime(), trigger.getFireTimeAfter(new
GregorianCalendar(2011, 4, 18, 23, 59, 58).getTime()));
    }
    
-/*   @Test(timeout = 5000000)
+   @Test(timeout = 5000)
    public void testBothDayOfMonthAndDayOfWeekE() throws ParseException {
        ScheduleExpression expr = new ScheduleExpression().year(2011).dayOfMonth("19").dayOfWeek("3").hour(23).minute(59).second(58).start(new
GregorianCalendar(2011, 4, 18, 23, 59, 58).getTime());
        EJBCronTrigger trigger = new EJBCronTrigger(expr);
        assertEquals(new GregorianCalendar(2011, 4, 19, 23, 59, 58).getTime(), trigger.getFireTimeAfter(new
GregorianCalendar(2011, 4, 18, 23, 59, 59).getTime()));
        
        System.out.println(trigger.getNextFireTime());
-   }   */  
+   }     
+   
+   @Test(timeout = 5000)
+   public void testBothDayOfMonthAndDayOfWeekF() throws ParseException {
+       ScheduleExpression expr = new ScheduleExpression().year(2011).dayOfMonth("19").dayOfWeek("3").hour(20).minute(59).second(59).start(new
GregorianCalendar(2011, 4, 18, 20, 59, 58).getTime());
+       EJBCronTrigger trigger = new EJBCronTrigger(expr);
+       assertEquals(new GregorianCalendar(2011, 4, 18, 20, 59, 59).getTime(), trigger.getFireTimeAfter(new
GregorianCalendar(2011, 4, 18, 20, 59, 58).getTime()));
+       assertEquals(new GregorianCalendar(2011, 4, 19, 20, 59, 59).getTime(), trigger.getFireTimeAfter(new
GregorianCalendar(2011, 4, 18, 20, 59, 59).getTime()));
+       
+       System.out.println(trigger.getNextFireTime());
+   }    
+   
+   @Test(timeout = 5000000)
+   public void testBothDayOfMonthAndDayOfWeekG() throws ParseException {
+       ScheduleExpression expr = new ScheduleExpression().year(2011).dayOfMonth("12").dayOfWeek("6").hour(20).minute(59).second(59).start(new
GregorianCalendar(2011, 5, 11, 20, 59, 58).getTime());
+       EJBCronTrigger trigger = new EJBCronTrigger(expr);
+       //assertEquals(new GregorianCalendar(2011, 5, 11, 20, 59, 59).getTime(), trigger.getFireTimeAfter(new
GregorianCalendar(2011, 5, 11, 20, 59, 58).getTime()));
+       assertEquals(new GregorianCalendar(2011, 5, 12, 20, 59, 59).getTime(), trigger.getFireTimeAfter(new
GregorianCalendar(2011, 5, 11, 20, 59, 59).getTime()));
+       
+       System.out.println(trigger.getNextFireTime());
+   }     
 
 	@Test(timeout = 5000)
     public void testLastDayOfMonthA() throws ParseException {



Mime
View raw message