KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > sapia > ubik > rmi > server > command > ExecQueueTest


1 package org.sapia.ubik.rmi.server.command;
2
3 import junit.framework.TestCase;
4
5 import org.sapia.ubik.rmi.server.ShutdownException;
6
7
8 /**
9  * @author Yanick Duchesne
10  *
11  * <dl>
12  * <dt><b>Copyright:</b><dd>Copyright &#169; 2002-2003 <a HREF="http://www.sapia-oss.org">Sapia Open Source Software</a>. All Rights Reserved.</dd></dt>
13  * <dt><b>License:</b><dd>Read the license.txt file of the jar or visit the
14  * <a HREF="http://www.sapia-oss.org/license.html">license page</a> at the Sapia OSS web site</dd></dt>
15  * </dl>
16  */

17 public class ExecQueueTest extends TestCase {
18   public ExecQueueTest(String JavaDoc name) {
19     super(name);
20   }
21
22   public void testShutdown() throws Exception JavaDoc {
23     ExecQueue queue = new ExecQueue();
24     queue.add(new Executable() {
25         public Object JavaDoc execute() throws Throwable JavaDoc {
26           return null;
27         }
28       });
29
30     long start = System.currentTimeMillis();
31     queue.shutdown(1000);
32
33     try {
34       queue.add(null);
35       throw new Exception JavaDoc("ShutdownException not thrown");
36     } catch (ShutdownException e) {
37       //ok;
38
}
39
40     super.assertTrue((System.currentTimeMillis() - start) > 700);
41   }
42
43   public void testShutdownWithRemoveAll() throws Exception JavaDoc {
44     final ExecQueue queue = new ExecQueue();
45     queue.add(new Executable() {
46         public Object JavaDoc execute() throws Throwable JavaDoc {
47           return null;
48         }
49       });
50
51     Thread JavaDoc remover = new Thread JavaDoc(new Runnable JavaDoc() {
52           public void run() {
53             try {
54               Thread.sleep(700);
55               queue.removeAll();
56             } catch (Throwable JavaDoc t) {
57             }
58           }
59         });
60     remover.start();
61
62     long start = System.currentTimeMillis();
63     queue.shutdown(2000);
64     super.assertEquals(0, queue.size());
65
66     try {
67       queue.add(null);
68       throw new Exception JavaDoc("ShutdownException not thrown");
69     } catch (ShutdownException e) {
70       //ok;
71
}
72   }
73
74   public void testShutdownWithRemove() throws Exception JavaDoc {
75     final ExecQueue queue = new ExecQueue();
76     queue.add(new Executable() {
77         public Object JavaDoc execute() throws Throwable JavaDoc {
78           return null;
79         }
80       });
81
82     Thread JavaDoc remover = new Thread JavaDoc(new Runnable JavaDoc() {
83           public void run() {
84             try {
85               Thread.sleep(700);
86               queue.remove();
87             } catch (Throwable JavaDoc t) {
88             }
89           }
90         });
91     remover.start();
92
93     long start = System.currentTimeMillis();
94     queue.shutdown(2000);
95     super.assertEquals(0, queue.size());
96
97     try {
98       queue.add(null);
99       throw new Exception JavaDoc("ShutdownException not thrown");
100     } catch (ShutdownException e) {
101       //ok;
102
}
103
104     super.assertTrue((System.currentTimeMillis() - start) > 700);
105   }
106 }
107
Popular Tags