[jboss-cvs] JBossAS SVN: r63290 - in branches/Branch_4_2/ejb3/src: test/org/jboss/ejb3/test/timer and 1 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Thu May 31 18:08:44 EDT 2007
Author: bdecoste
Date: 2007-05-31 18:08:43 -0400 (Thu, 31 May 2007)
New Revision: 63290
Added:
branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/timer/LifecycleRemote.java
branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/timer/LifecycleTimerTesterService.java
branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/timer/ServiceManagement.java
Modified:
branches/Branch_4_2/ejb3/src/main/org/jboss/ejb3/service/ServiceContainer.java
branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/timer/unit/RemoteUnitTestCase.java
Log:
[EJBTHREE-979] fix and test for duplicate timer being created when a timer is created in the create() lifecycle - the duplicate was being created int he restore
Modified: branches/Branch_4_2/ejb3/src/main/org/jboss/ejb3/service/ServiceContainer.java
===================================================================
--- branches/Branch_4_2/ejb3/src/main/org/jboss/ejb3/service/ServiceContainer.java 2007-05-31 21:59:42 UTC (rev 63289)
+++ branches/Branch_4_2/ejb3/src/main/org/jboss/ejb3/service/ServiceContainer.java 2007-05-31 22:08:43 UTC (rev 63290)
@@ -152,10 +152,13 @@
injectDependencies(beanContext);
// TODO: EJBTHREE-655: shouldn't happen here, but in create
- registerManagementInterface();
+ registerManagementInterface();
+
+ // only restore timers if this is a restart to avoid duplicate timers
+ // when the timer is created during lifecycle
+ if (timerService.getTimers().size() == 0)
+ TimerServiceFactory.getInstance().restoreTimerService(timerService);
- TimerServiceFactory.getInstance().restoreTimerService(timerService);
-
invokeOptionalMethod("start");
}
catch (Exception e)
Added: branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/timer/LifecycleRemote.java
===================================================================
--- branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/timer/LifecycleRemote.java (rev 0)
+++ branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/timer/LifecycleRemote.java 2007-05-31 22:08:43 UTC (rev 63290)
@@ -0,0 +1,35 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.ejb3.test.timer;
+
+
+/**
+ * @author <a href="mailto:bdecoste at jboss.com">William DeCoste</a>
+ */
+public interface LifecycleRemote
+{
+ int timersStarted();
+
+ int timersFired();
+
+ void restartTimer();
+}
Added: branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/timer/LifecycleTimerTesterService.java
===================================================================
--- branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/timer/LifecycleTimerTesterService.java (rev 0)
+++ branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/timer/LifecycleTimerTesterService.java 2007-05-31 22:08:43 UTC (rev 63290)
@@ -0,0 +1,106 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.ejb3.test.timer;
+
+import java.util.Date;
+
+import javax.annotation.Resource;
+import javax.ejb.Remote;
+import javax.ejb.SessionContext;
+import javax.ejb.Timeout;
+import javax.ejb.Timer;
+import javax.ejb.TimerService;
+
+import org.jboss.annotation.ejb.Management;
+import org.jboss.annotation.ejb.Service;
+import org.jboss.logging.Logger;
+
+/**
+ * @author <a href="mailto:bdecoste at jboss.com">William DeCoste</a>
+ */
+ at Service
+ at Management(ServiceManagement.class)
+ at Remote(LifecycleRemote.class)
+public class LifecycleTimerTesterService implements ServiceManagement, LifecycleRemote
+{
+ private static final Logger log = Logger.getLogger(LifecycleTimerTesterService.class);
+
+ private @Resource TimerService timerService;
+
+ private Timer timer;
+ private int timersStarted = 0;
+ private int timersFired = 0;
+ private boolean restarted = false;
+
+ @Timeout
+ public void timeoutHandler(Timer timer)
+ {
+ log.info("*** EJB TIMEOUT " + timer + " " + timer.getInfo());
+ ++timersFired;
+
+ if (restarted)
+ timer = createTimer();
+ }
+
+ public void restartTimer()
+ {
+ timer = createTimer();
+ restarted = true;
+ }
+
+ public int timersStarted()
+ {
+ return timersStarted;
+ }
+
+ public int timersFired()
+ {
+ return timersFired;
+ }
+
+ public void create() throws Exception
+ {
+ ++timersStarted;
+ timer = createTimer();
+ log.info("*** created timer " + timer);
+ }
+
+ public void start() throws Exception
+ {
+
+ }
+
+ public void stop()
+ {
+
+ }
+
+ public void destroy()
+ {
+
+ }
+
+ protected Timer createTimer()
+ {
+ return timerService.createTimer(new Date(new Date().getTime() + 5000), "LifecycleTimerTesterService Timer #" + timersStarted);
+ }
+}
Added: branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/timer/ServiceManagement.java
===================================================================
--- branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/timer/ServiceManagement.java (rev 0)
+++ branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/timer/ServiceManagement.java 2007-05-31 22:08:43 UTC (rev 63290)
@@ -0,0 +1,33 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.ejb3.test.timer;
+
+/**
+ * @author <a href="mailto:bdecoste at jboss.com">William DeCoste</a>
+ */
+public interface ServiceManagement
+{
+ void create() throws Exception;
+ void start() throws Exception;
+ void stop();
+ void destroy();
+}
Modified: branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/timer/unit/RemoteUnitTestCase.java
===================================================================
--- branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/timer/unit/RemoteUnitTestCase.java 2007-05-31 21:59:42 UTC (rev 63289)
+++ branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/timer/unit/RemoteUnitTestCase.java 2007-05-31 22:08:43 UTC (rev 63290)
@@ -23,7 +23,11 @@
import java.util.Date;
+import javax.management.MBeanServerConnection;
+import javax.management.ObjectName;
+
import org.jboss.ejb3.test.timer.TimerTester;
+import org.jboss.ejb3.test.timer.LifecycleRemote;
import org.jboss.test.JBossTestCase;
import junit.framework.Test;
@@ -87,7 +91,7 @@
assertTrue(test.isTimerCalled());
}
- public void testSimple() throws Exception
+ public void atestSimple() throws Exception
{
TimerTester test = (TimerTester) this.getInitialContext().lookup("TimerTesterBean/remote");
test.startTimer(5000);
@@ -121,6 +125,32 @@
assertFalse(test.isTimerCalled());
}
+ public void testLifecycle() throws Exception
+ {
+ LifecycleRemote test = (LifecycleRemote) this.getInitialContext().lookup("LifecycleTimerTesterService/remote");
+
+ Thread.sleep(6000);
+ assertEquals(1, test.timersStarted());
+ assertEquals(1, test.timersFired());
+
+ test.restartTimer();
+ Thread.sleep(6000);
+
+ int numFired = test.timersFired();
+ assertTrue(numFired > 1);
+
+ MBeanServerConnection server = getServer();
+ ObjectName name = new ObjectName("jboss.j2ee:jar=timer-test.jar,name=LifecycleTimerTesterService,service=EJB3");
+ Object params[] = { };
+ String signature[] = { };
+ server.invoke(name, "stop", params, signature);
+ server.invoke(name, "start", params, signature);
+
+ Thread.sleep(3 * 6000);
+ assertTrue(test.timersFired() > numFired + 2);
+
+ }
+
public static Test suite() throws Exception
{
return getDeploySetup(RemoteUnitTestCase.class, "timer-test.jar");
More information about the jboss-cvs-commits
mailing list