activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tab...@apache.org
Subject svn commit: r1071411 - in /activemq/trunk/activemq-core/src: main/java/org/apache/activemq/broker/scheduler/CronParser.java test/java/org/apache/activemq/broker/scheduler/CronParserTest.java
Date Wed, 16 Feb 2011 21:38:42 GMT
Author: tabish
Date: Wed Feb 16 21:38:41 2011
New Revision: 1071411

URL: http://svn.apache.org/viewvc?rev=1071411&view=rev
Log:
Apply patch for: https://issues.apache.org/jira/browse/AMQ-3036

Modified:
    activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/scheduler/CronParser.java
    activemq/trunk/activemq-core/src/test/java/org/apache/activemq/broker/scheduler/CronParserTest.java

Modified: activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/scheduler/CronParser.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/scheduler/CronParser.java?rev=1071411&r1=1071410&r2=1071411&view=diff
==============================================================================
--- activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/scheduler/CronParser.java
(original)
+++ activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/scheduler/CronParser.java
Wed Feb 16 21:38:41 2011
@@ -43,7 +43,7 @@ public class CronParser {
             CronEntry hours = entries.get(HOURS);
             CronEntry dayOfMonth = entries.get(DAY_OF_MONTH);
             CronEntry month = entries.get(MONTH);
-            CronEntry dayOfWeek = entries.get(DAY_OF_MONTH);
+            CronEntry dayOfWeek = entries.get(DAY_OF_WEEK);
             
             int currentMinutes = working.get(Calendar.MINUTE);
             if (!isCurrent(minutes, currentMinutes)) {
@@ -71,7 +71,7 @@ public class CronParser {
             }
             int currentDayOfMonth = working.get(Calendar.DAY_OF_MONTH);
             if (!isCurrent(dayOfMonth, currentDayOfMonth)) {
-                int nextDay = getNext(dayOfMonth, currentMonth);
+                int nextDay = getNext(dayOfMonth, currentDayOfMonth);
                 working.add(Calendar.DAY_OF_MONTH, nextDay);
                 result = working.getTimeInMillis();
             }

Modified: activemq/trunk/activemq-core/src/test/java/org/apache/activemq/broker/scheduler/CronParserTest.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/broker/scheduler/CronParserTest.java?rev=1071411&r1=1071410&r2=1071411&view=diff
==============================================================================
--- activemq/trunk/activemq-core/src/test/java/org/apache/activemq/broker/scheduler/CronParserTest.java
(original)
+++ activemq/trunk/activemq-core/src/test/java/org/apache/activemq/broker/scheduler/CronParserTest.java
Wed Feb 16 21:38:41 2011
@@ -17,6 +17,7 @@
 package org.apache.activemq.broker.scheduler;
 
 import static org.junit.Assert.assertEquals;
+
 import static org.junit.Assert.fail;
 
 import java.util.Calendar;
@@ -27,6 +28,79 @@ import org.junit.Test;
 public class CronParserTest {
 
     @Test
+    public void testgetNextTimeDayOfWeek() throws MessageFormatException {
+        
+        
+        // using an absolute date so that result will be absolute - Monday 15 Nov 2010
+        Calendar current = Calendar.getInstance();
+        current.set(2010, Calendar.NOVEMBER, 15, 9, 15, 30);
+        System.out.println("start:" + current.getTime());
+        
+        String test = "* * * * 5";
+        long next = CronParser.getNextScheduledTime(test, current.getTimeInMillis());
+        
+        Calendar result = Calendar.getInstance();
+        result.setTimeInMillis(next);
+        System.out.println("next:" + result.getTime());
+        
+        assertEquals(30,result.get(Calendar.SECOND));
+        assertEquals(15,result.get(Calendar.MINUTE));
+        assertEquals(9,result.get(Calendar.HOUR));
+        // expecting Friday 19th
+        assertEquals(19,result.get(Calendar.DAY_OF_MONTH));
+        assertEquals(Calendar.NOVEMBER,result.get(Calendar.MONTH));
+        assertEquals(2010,result.get(Calendar.YEAR));
+    }
+    
+    @Test
+    public void testgetNextTimeMonth() throws MessageFormatException {
+        
+        
+        // using an absolute date so that result will be absolute - Monday 15 Nov 2010
+        Calendar current = Calendar.getInstance();
+        current.set(2010, Calendar.NOVEMBER, 15, 9, 15, 30);
+        System.out.println("start:" + current.getTime());
+        
+        String test = "* * * 12 *";
+        long next = CronParser.getNextScheduledTime(test, current.getTimeInMillis());
+        
+        Calendar result = Calendar.getInstance();
+        result.setTimeInMillis(next);
+        System.out.println("next:" + result.getTime());
+        
+        assertEquals(30,result.get(Calendar.SECOND));
+        assertEquals(15,result.get(Calendar.MINUTE));
+        assertEquals(9,result.get(Calendar.HOUR));
+        assertEquals(15,result.get(Calendar.DAY_OF_MONTH));
+        assertEquals(Calendar.DECEMBER,result.get(Calendar.MONTH));
+        assertEquals(2010,result.get(Calendar.YEAR));
+    }
+    
+    @Test
+    public void testgetNextTimeDays() throws MessageFormatException {
+
+
+        // using an absolute date so that result will be absolute - Monday 15 Nov 2010
+        Calendar current = Calendar.getInstance();
+        current.set(2010, Calendar.NOVEMBER, 15, 9, 15, 30);
+        System.out.println("start:" + current.getTime());
+        
+        String test = "* * 16 * *";
+        long next = CronParser.getNextScheduledTime(test, current.getTimeInMillis());
+
+        Calendar result = Calendar.getInstance();
+        result.setTimeInMillis(next);
+        System.out.println("next:" + result.getTime());
+        
+        assertEquals(30,result.get(Calendar.SECOND));
+        assertEquals(15,result.get(Calendar.MINUTE));
+        assertEquals(9,result.get(Calendar.HOUR));
+        assertEquals(16,result.get(Calendar.DAY_OF_MONTH));
+        assertEquals(Calendar.NOVEMBER,result.get(Calendar.MONTH));
+        assertEquals(2010,result.get(Calendar.YEAR));
+    }
+    
+    @Test
     public void testgetNextTimeMinutes() throws MessageFormatException {
         String test = "30 * * * *";
         long current = 20*60*1000;
@@ -153,6 +227,16 @@ public class CronParserTest {
         } catch (Throwable e) {
         }
 
+        test = "0 1 2 3 4";
+        list = CronParser.tokenize(test);
+        assertEquals(list.size(), 5);
+        
+        assertEquals(list.get(0), "0");
+        assertEquals(list.get(1), "1");
+        assertEquals(list.get(2), "2");
+        assertEquals(list.get(3), "3");
+        assertEquals(list.get(4), "4");
+        
     }
 
     public void testGetNextScheduledTime() {



Mime
View raw message