ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/test/TimerExecutorTest.java
Revision: 1.1
Committed: Wed May 14 21:30:49 2003 UTC (21 years, 1 month ago) by tim
Branch: MAIN
Log Message:
Moved main source rooted at . to ./src/main
Moved test source rooted at ./etc/testcases to ./src/test

File Contents

# User Rev Content
1 tim 1.1
2     import java.util.Date;
3     import java.util.TimerTask;
4     import java.util.concurrent.*;
5     import junit.framework.TestCase;
6    
7     /**
8     * Tests the TimerExecutor method
9     */
10     public class TimerExecutorTest extends TestCase {
11    
12     public void testTimedExecute () {
13     TimerExecutor te = TimerExecutors.newTimerExecutor(new DirectExecutor());
14     Date inASecond= new Date(System.currentTimeMillis() + 1000);
15     flag = false;
16     TimerTask timerTask = te.schedule(new Runnable() {
17     public void run () {
18     flag = true;
19     }
20     }, inASecond);
21     try {
22     Thread.sleep(3000);
23     }
24     catch (InterruptedException e) {
25     fail("task interrupted");
26     }
27     assertTrue("flag should have been set", flag);
28     }
29    
30     public void testTimerThreadedExecutorConstruction () {
31     TimerThreadedExecutor tte = TimerExecutors.newTimerExecutor(new SingleThreadedExecutor());
32     flag = false;
33     tte.execute(new Runnable() {
34     public void run () {
35     flag = true;
36     }
37     });
38     //assertTrue("flag should have been set", flag);
39     }
40    
41     private static class DirectExecutor implements Executor {
42     public void execute (Runnable r) {
43     r.run();
44     }
45     }
46    
47     private boolean flag = false;
48     }