[jboss-cvs] JBossRemoting/src/tests/org/jboss/test/remoting/util ...
Ron Sigal
ron_sigal at yahoo.com
Fri Jan 19 03:47:36 EST 2007
User: rsigal
Date: 07/01/19 03:47:36
Added: src/tests/org/jboss/test/remoting/util Tag: remoting_2_x
TimerUtilTestCase.java
Log:
JBREM-676: Unit tests for TimerUtil's treatment of StoppableTimerTasks.
Revision Changes Path
No revision
No revision
1.1.2.1 +123 -0 JBossRemoting/src/tests/org/jboss/test/remoting/util/Attic/TimerUtilTestCase.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: TimerUtilTestCase.java
===================================================================
RCS file: TimerUtilTestCase.java
diff -N TimerUtilTestCase.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ TimerUtilTestCase.java 19 Jan 2007 08:47:35 -0000 1.1.2.1
@@ -0,0 +1,123 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2005, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt 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.test.remoting.util;
+
+import java.util.TimerTask;
+
+import org.apache.log4j.Logger;
+import org.jboss.remoting.util.StoppableTimerTask;
+import org.jboss.remoting.util.TimerUtil;
+
+import junit.framework.TestCase;
+
+/**
+ * @author <a href="ron.sigal at jboss.com">Ron Sigal</a>
+ * @version $Revision: 1.1.2.1 $
+ * <p>
+ * Copyright Jan 18, 2007
+ * </p>
+ */
+public class TimerUtilTestCase extends TestCase
+{
+ private static Logger log = Logger.getLogger(TimerUtilTestCase.class);
+
+
+ public void testTimerTaskDestroy() throws Exception
+ {
+ log.info("entering " + getName());
+ TestTimerTask task = new TestTimerTask();
+ TimerUtil.schedule(task, 500);
+ Thread.sleep(1000);
+ assertTrue(task.ran);
+ assertFalse(task.stopped);
+ assertFalse(task.stoppedTwice);
+
+ TimerUtil.destroy();
+
+ assertTrue(task.stopped);
+ assertTrue(task.stoppedTwice);
+ log.info(getName() + " PASSED");
+ }
+
+
+ public void testTimerTaskUnschedule() throws Exception
+ {
+ log.info("entering " + getName());
+ TestTimerTask task = new TestTimerTask();
+ TimerUtil.schedule(task, 500);
+ Thread.sleep(1000);
+ assertTrue(task.ran);
+ assertFalse(task.stopped);
+ assertFalse(task.stoppedTwice);
+
+ TimerUtil.unschedule(task);
+
+ assertTrue(task.stopped);
+ assertTrue(task.stoppedTwice);
+ log.info(getName() + " PASSED");
+ }
+
+
+ public void testTimerTaskStop() throws Exception
+ {
+ log.info("entering " + getName());
+ TestTimerTask task = new TestTimerTask();
+ TimerUtil.schedule(task, 500);
+ Thread.sleep(1000);
+ assertTrue(task.ran);
+ assertFalse(task.stopped);
+ assertFalse(task.stoppedTwice);
+
+ task.stop();
+
+ assertTrue(task.stopped);
+ assertTrue(task.stoppedTwice);
+ log.info(getName() + " PASSED");
+ }
+
+
+ class TestTimerTask extends TimerTask implements StoppableTimerTask
+ {
+ public boolean ran;
+ public boolean stopped;
+ public boolean stoppedTwice;
+
+ public void run()
+ {
+ log.info("run called");
+ ran = true;
+ }
+
+ public void stop() throws Exception
+ {
+ log.info("stop called");
+ if (stopped)
+ stoppedTwice = true;
+ else
+ {
+ stopped = true;
+ TimerUtil.unschedule(this);
+ }
+ }
+
+ }
+}
More information about the jboss-cvs-commits
mailing list