KickJava   Java API By Example, From Geeks To Geeks.

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


1 package org.sapia.ubik.rmi.server.command;
2
3 import junit.framework.TestCase;
4
5 import java.util.ArrayList JavaDoc;
6 import java.util.List JavaDoc;
7
8
9 /**
10  * @author Yanick Duchesne
11  *
12  * <dl>
13  * <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>
14  * <dt><b>License:</b><dd>Read the license.txt file of the jar or visit the
15  * <a HREF="http://www.sapia-oss.org/license.html">license page</a> at the Sapia OSS web site</dd></dt>
16  * </dl>
17  */

18 public class ResponseQueueTest extends TestCase {
19   public ResponseQueueTest(String JavaDoc name) {
20     super(name);
21   }
22
23   public void testShutdown() throws Exception JavaDoc {
24     ResponseQueue queue = new ResponseQueue();
25     ResponseLock lock = queue.createResponseLock();
26     long start = System.currentTimeMillis();
27     queue.shutdown(1000);
28     super.assertTrue((System.currentTimeMillis() - start) > 700);
29     super.assertEquals(1, queue.size());
30   }
31
32   public void testShutdownWithResponse() throws Exception JavaDoc {
33     final ResponseQueue queue = new ResponseQueue();
34     final ResponseLock lock = queue.createResponseLock();
35     long start = System.currentTimeMillis();
36     Thread JavaDoc adder = new Thread JavaDoc(new Runnable JavaDoc() {
37           public void run() {
38             try {
39               Thread.sleep(1000);
40
41               List JavaDoc responses = new ArrayList JavaDoc();
42               responses.add(new Response(lock.getId(), null));
43               queue.onResponses(responses);
44               lock.waitResponse(1000);
45             } catch (Exception JavaDoc e) {
46               e.printStackTrace();
47             }
48           }
49         });
50     adder.start();
51     queue.shutdown(2000);
52     super.assertEquals(0, queue.size());
53   }
54 }
55
Popular Tags