ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/test/tck/LockSupportTest.java
(Generate patch)

Comparing jsr166/src/test/tck/LockSupportTest.java (file contents):
Revision 1.3 by dl, Sat Sep 20 18:20:08 2003 UTC vs.
Revision 1.6 by dl, Mon Dec 29 19:05:40 2003 UTC

# Line 1 | Line 1
1   /*
2 < * Written by members of JCP JSR-166 Expert Group and released to the
3 < * public domain. Use, modify, and redistribute this code in any way
4 < * without acknowledgement. Other contributors include Andrew Wright,
5 < * Jeffrey Hayes, Pat Fischer, Mike Judd.
2 > * Written by Doug Lea with assistance from members of JCP JSR-166
3 > * Expert Group and released to the public domain, as explained at
4 > * http://creativecommons.org/licenses/publicdomain
5 > * Other contributors include Andrew Wright, Jeffrey Hayes,
6 > * Pat Fisher, Mike Judd.
7   */
8  
9   import junit.framework.*;
# Line 19 | Line 20 | public class LockSupportTest extends JSR
20      }
21  
22      /**
23 <     *
23 >     * park is released by unpark occurring after park
24       */
25 <    public void testUnpark() {
25 >    public void testPark() {
26          Thread t = new Thread(new Runnable() {
27                  public void run() {
28                      try {
# Line 31 | Line 32 | public class LockSupportTest extends JSR
32                      }
33                  }
34              });
34        t.start();
35          try {
36 +            t.start();
37 +            Thread.sleep(SHORT_DELAY_MS);
38              LockSupport.unpark(t);
39              t.join();
40          }
# Line 42 | Line 44 | public class LockSupportTest extends JSR
44      }
45  
46      /**
47 <     *
47 >     * park is released by unpark occurring before park
48 >     */
49 >    public void testPark2() {
50 >        Thread t = new Thread(new Runnable() {
51 >                public void run() {
52 >                    try {
53 >                        Thread.sleep(SHORT_DELAY_MS);
54 >                        LockSupport.park();
55 >                    } catch(Exception e){
56 >                        threadUnexpectedException();
57 >                    }
58 >                }
59 >            });
60 >        try {
61 >            t.start();
62 >            LockSupport.unpark(t);
63 >            t.join();
64 >        }
65 >        catch(Exception e) {
66 >            unexpectedException();
67 >        }
68 >    }
69 >
70 >    /**
71 >     * park is released by interrupt
72 >     */
73 >    public void testPark3() {
74 >        Thread t = new Thread(new Runnable() {
75 >                public void run() {
76 >                    try {
77 >                        LockSupport.park();
78 >                        threadAssertTrue(Thread.interrupted());
79 >                    } catch(Exception e){
80 >                        threadUnexpectedException();
81 >                    }
82 >                }
83 >            });
84 >        try {
85 >            t.start();
86 >            Thread.sleep(SHORT_DELAY_MS);
87 >            t.interrupt();
88 >            t.join();
89 >        }
90 >        catch(Exception e) {
91 >            unexpectedException();
92 >        }
93 >    }
94 >
95 >    /**
96 >     * park returns if interrupted before park
97 >     */
98 >    public void testPark4() {
99 >        final ReentrantLock lock = new ReentrantLock();
100 >        lock.lock();
101 >        Thread t = new Thread(new Runnable() {
102 >                public void run() {
103 >                    try {
104 >                        lock.lock();
105 >                        LockSupport.park();
106 >                    } catch(Exception e){
107 >                        threadUnexpectedException();
108 >                    }
109 >                }
110 >            });
111 >        try {
112 >            t.start();
113 >            t.interrupt();
114 >            lock.unlock();
115 >            t.join();
116 >        }
117 >        catch(Exception e) {
118 >            unexpectedException();
119 >        }
120 >    }
121 >
122 >    /**
123 >     * parkNanos times out if not unparked
124       */
125      public void testParkNanos() {
126          Thread t = new Thread(new Runnable() {
# Line 65 | Line 143 | public class LockSupportTest extends JSR
143  
144  
145      /**
146 <     *
146 >     * parkUntil times out if not unparked
147       */
148      public void testParkUntil() {
149          Thread t = new Thread(new Runnable() {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines