tomee-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rmannibu...@apache.org
Subject svn commit: r1509726 - in /tomee/tomee/trunk/container/openejb-core/src: main/java/org/apache/openejb/core/timer/ test/java/org/apache/openejb/timer/
Date Fri, 02 Aug 2013 14:34:40 GMT
Author: rmannibucau
Date: Fri Aug  2 14:34:39 2013
New Revision: 1509726

URL: http://svn.apache.org/r1509726
Log:
startTime for timer service seemed wrong

Added:
    tomee/tomee/trunk/container/openejb-core/src/test/java/org/apache/openejb/timer/InitialIntervalTimerTest.java
Modified:
    tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/core/timer/IntervalTimerData.java
    tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/core/timer/TimerData.java
    tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/core/timer/TimerImpl.java

Modified: tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/core/timer/IntervalTimerData.java
URL: http://svn.apache.org/viewvc/tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/core/timer/IntervalTimerData.java?rev=1509726&r1=1509725&r2=1509726&view=diff
==============================================================================
--- tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/core/timer/IntervalTimerData.java
(original)
+++ tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/core/timer/IntervalTimerData.java
Fri Aug  2 14:34:39 2013
@@ -58,7 +58,7 @@ public class IntervalTimerData extends T
     @Override
     public AbstractTrigger<?> initializeTrigger() {
         SimpleTriggerImpl simpleTrigger = new SimpleTriggerImpl();
-        Date startTime = new Date(initialExpiration.getTime() - intervalDuration);
+        Date startTime = new Date(initialExpiration.getTime());
         simpleTrigger.setStartTime(startTime);
         simpleTrigger.setRepeatInterval(intervalDuration);
         simpleTrigger.setRepeatCount(SimpleTrigger.REPEAT_INDEFINITELY);

Modified: tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/core/timer/TimerData.java
URL: http://svn.apache.org/viewvc/tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/core/timer/TimerData.java?rev=1509726&r1=1509725&r2=1509726&view=diff
==============================================================================
--- tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/core/timer/TimerData.java
(original)
+++ tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/core/timer/TimerData.java
Fri Aug  2 14:34:39 2013
@@ -84,6 +84,8 @@ public abstract class TimerData implemen
      */
     private boolean cancelled = false;
 
+    private boolean stopped = false;
+
     /**
      * Has this timer been registered with the transaction for callbacks?  We remember
      * when we are registered to avoid multiple registrations.
@@ -170,6 +172,7 @@ public abstract class TimerData implemen
             }
         }
         cancelled = true;
+        stopped = true;
     }
 
     public long getId() {
@@ -211,6 +214,10 @@ public abstract class TimerData implemen
     }
 
     public void cancel() {
+        if (stopped) {
+            return;
+        }
+
         timerService.cancelled(TimerData.this);
         if (trigger != null) {
             try {
@@ -271,6 +278,10 @@ public abstract class TimerData implemen
         transactionComplete(true);
     }
 
+    public boolean isStopped() {
+        return stopped;
+    }
+
     private class TimerDataSynchronization implements Synchronization {
         @Override
         public void beforeCompletion() {

Modified: tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/core/timer/TimerImpl.java
URL: http://svn.apache.org/viewvc/tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/core/timer/TimerImpl.java?rev=1509726&r1=1509725&r2=1509726&view=diff
==============================================================================
--- tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/core/timer/TimerImpl.java
(original)
+++ tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/core/timer/TimerImpl.java
Fri Aug  2 14:34:39 2013
@@ -97,7 +97,7 @@ public class TimerImpl implements Timer,
         final BaseContext context = (BaseContext) beanContext.get(EJBContext.class);
         context.check(BaseContext.Call.timerMethod);
 
-        if (timerData.isCancelled()) {
+        if (timerData.isCancelled() && !timerData.isStopped()) {
             throw new NoSuchObjectLocalException("Timer has been cancelled");
         }
         

Added: tomee/tomee/trunk/container/openejb-core/src/test/java/org/apache/openejb/timer/InitialIntervalTimerTest.java
URL: http://svn.apache.org/viewvc/tomee/tomee/trunk/container/openejb-core/src/test/java/org/apache/openejb/timer/InitialIntervalTimerTest.java?rev=1509726&view=auto
==============================================================================
--- tomee/tomee/trunk/container/openejb-core/src/test/java/org/apache/openejb/timer/InitialIntervalTimerTest.java
(added)
+++ tomee/tomee/trunk/container/openejb-core/src/test/java/org/apache/openejb/timer/InitialIntervalTimerTest.java
Fri Aug  2 14:34:39 2013
@@ -0,0 +1,88 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.openejb.timer;
+
+import org.apache.openejb.jee.EnterpriseBean;
+import org.apache.openejb.jee.SingletonBean;
+import org.apache.openejb.junit.ApplicationComposer;
+import org.apache.openejb.testing.Module;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import javax.annotation.PostConstruct;
+import javax.annotation.PreDestroy;
+import javax.annotation.Resource;
+import javax.ejb.EJB;
+import javax.ejb.Lock;
+import javax.ejb.LockType;
+import javax.ejb.Singleton;
+import javax.ejb.Startup;
+import javax.ejb.Timeout;
+import javax.ejb.Timer;
+import javax.ejb.TimerConfig;
+import javax.ejb.TimerService;
+
+import static org.junit.Assert.assertEquals;
+
+@RunWith(ApplicationComposer.class)
+public class InitialIntervalTimerTest {
+    @Module
+    public EnterpriseBean bean() {
+        return new SingletonBean(TimerWithDelay.class).localBean();
+    }
+
+    @EJB
+    private TimerWithDelay bean;
+
+    @Test
+    public void test() throws InterruptedException {
+        Thread.sleep(5400);
+        assertEquals(3, bean.getOk());
+    }
+
+    @Singleton
+    @Startup
+    @Lock(LockType.READ)
+    public static class TimerWithDelay {
+        @Resource
+        private TimerService ts;
+
+        private Timer timer;
+        private int ok = 0;
+
+        @PostConstruct
+        public void start() {
+            timer = ts.createIntervalTimer(3000, 1000, new TimerConfig(System.currentTimeMillis(),
false));
+        }
+
+        @Timeout
+        public void timeout(final Timer timer) {
+            final long actual = System.currentTimeMillis() - ((Long) timer.getInfo() + 1000
* ok + 3000);
+            assertEquals(0, actual, 500);
+            ok++;
+        }
+
+        public int getOk() {
+            return ok;
+        }
+
+        @PreDestroy
+        public void stop() {
+            timer.cancel();
+        }
+    }
+}



Mime
View raw message