geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ga...@apache.org
Subject svn commit: r640462 - in /geronimo/sandbox/concurrent/geronimo-concurrent-core/src: main/java/org/apache/geronimo/concurrent/executor/ test/java/org/apache/geronimo/concurrent/executor/
Date Mon, 24 Mar 2008 16:48:34 GMT
Author: gawor
Date: Mon Mar 24 09:48:23 2008
New Revision: 640462

URL: http://svn.apache.org/viewvc?rev=640462&view=rev
Log:
throw exception when Trigger.getNextRunTime() returns null on the verify first time

Modified:
    geronimo/sandbox/concurrent/geronimo-concurrent-core/src/main/java/org/apache/geronimo/concurrent/executor/AbstractManagedScheduledExecutorService.java
    geronimo/sandbox/concurrent/geronimo-concurrent-core/src/test/java/org/apache/geronimo/concurrent/executor/BasicManagedScheduledExecutorServiceTest.java

Modified: geronimo/sandbox/concurrent/geronimo-concurrent-core/src/main/java/org/apache/geronimo/concurrent/executor/AbstractManagedScheduledExecutorService.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/concurrent/geronimo-concurrent-core/src/main/java/org/apache/geronimo/concurrent/executor/AbstractManagedScheduledExecutorService.java?rev=640462&r1=640461&r2=640462&view=diff
==============================================================================
--- geronimo/sandbox/concurrent/geronimo-concurrent-core/src/main/java/org/apache/geronimo/concurrent/executor/AbstractManagedScheduledExecutorService.java
(original)
+++ geronimo/sandbox/concurrent/geronimo-concurrent-core/src/main/java/org/apache/geronimo/concurrent/executor/AbstractManagedScheduledExecutorService.java
Mon Mar 24 09:48:23 2008
@@ -98,9 +98,8 @@
             super(r, result, managedContext, listener);
             this.trigger = trigger;
             this.submitTime = new Date();
-            this.lastScheduledRunTime = 
-                trigger.getNextRunTime(this, this.submitTime, null, null, null);        
  
             this.sequenceNumber = sequencer.getAndIncrement();
+            getNextRunTime();
         }
 
         ScheduledFutureTask(Callable<V> callable,
@@ -121,9 +120,20 @@
             super(callable, managedContext, listener);
             this.trigger = trigger;
             this.submitTime = new Date();
-            this.lastScheduledRunTime = 
-                trigger.getNextRunTime(this, this.submitTime, null, null, null);
             this.sequenceNumber = sequencer.getAndIncrement();
+            getNextRunTime();
+        }
+        
+        private void getNextRunTime() {   
+            /* XXX: The spec does not define (yet) what should happen if trigger.getNextRunTime()
+             * returns null on the verify first time. We throw RejectedExecutionException
+             * in such case since the task will not run.              
+             */
+            this.lastScheduledRunTime = 
+                trigger.getNextRunTime(this, this.submitTime, null, null, null);  
+            if (this.lastScheduledRunTime == null) {
+                throw new RejectedExecutionException("Null nextRunTime returned by Trigger");
+            }            
         }
         
         public long getDelay(TimeUnit unit) {

Modified: geronimo/sandbox/concurrent/geronimo-concurrent-core/src/test/java/org/apache/geronimo/concurrent/executor/BasicManagedScheduledExecutorServiceTest.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/concurrent/geronimo-concurrent-core/src/test/java/org/apache/geronimo/concurrent/executor/BasicManagedScheduledExecutorServiceTest.java?rev=640462&r1=640461&r2=640462&view=diff
==============================================================================
--- geronimo/sandbox/concurrent/geronimo-concurrent-core/src/test/java/org/apache/geronimo/concurrent/executor/BasicManagedScheduledExecutorServiceTest.java
(original)
+++ geronimo/sandbox/concurrent/geronimo-concurrent-core/src/test/java/org/apache/geronimo/concurrent/executor/BasicManagedScheduledExecutorServiceTest.java
Mon Mar 24 09:48:23 2008
@@ -17,13 +17,16 @@
 package org.apache.geronimo.concurrent.executor;
 
 import java.util.Arrays;
+import java.util.Date;
 import java.util.List;
 import java.util.concurrent.CancellationException;
 import java.util.concurrent.Future;
+import java.util.concurrent.RejectedExecutionException;
 import java.util.concurrent.TimeUnit;
 
 import javax.util.concurrent.ManagedScheduledExecutorService;
 import javax.util.concurrent.SkippedException;
+import javax.util.concurrent.Trigger;
 
 import org.apache.geronimo.concurrent.TestCallable;
 import org.apache.geronimo.concurrent.TestRunnable;
@@ -275,6 +278,36 @@
         f1.get(30, TimeUnit.SECONDS);    
     }
     */
+    
+    public void testTriggerNull() throws Exception {        
+        NullTrigger trigger = new NullTrigger();
+        TestManagedTaskListener listener = new TestManagedTaskListener();
+        
+        TestRunnable task1 = new TestRunnable(true);
+        try {
+            Future f1 = scheduledExecutor.schedule(task1, trigger, listener);
+            fail("Did not throw exception");
+        } catch (RejectedExecutionException ex) {
+            // expected
+        }
+        
+        TestCallable task2 = new TestCallable(0, true);
+        try {
+            Future f2 = scheduledExecutor.schedule(task2, trigger, listener);
+            fail("Did not throw exception");
+        } catch (RejectedExecutionException ex) {
+            // expected
+        }
+    }
+    
+    private static class NullTrigger implements Trigger {
+        public Date getNextRunTime(Future<?> arg0, Date arg1, Date arg2, Date arg3,
Date arg4) {
+            return null;
+        }
+        public boolean skipRun(Future<?> arg0, Date arg1) {
+            return false;
+        }        
+    }
     
     protected void checkTriggerBasics(Future expectedFuture,
                                       List<TestTrigger.CallbackInfo> callbacks) throws
Exception {



Mime
View raw message