ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/test/tck/LockSupportTest.java
Revision: 1.2
Committed: Sun Sep 14 20:42:40 2003 UTC (20 years, 8 months ago) by dl
Branch: MAIN
Changes since 1.1: +4 -9 lines
Log Message:
New base class JSR166TestCase

File Contents

# User Rev Content
1 dl 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.
6     */
7    
8     import junit.framework.*;
9     import java.util.*;
10     import java.util.concurrent.*;
11     import java.util.concurrent.locks.*;
12    
13 dl 1.2 public class LockSupportTest extends JSR166TestCase{
14 dl 1.1 public static void main(String[] args) {
15     junit.textui.TestRunner.run (suite());
16     }
17     public static Test suite() {
18     return new TestSuite(LockSupportTest.class);
19     }
20    
21     public void testUnpark() {
22     Thread t = new Thread(new Runnable(){
23     public void run(){
24     try{
25     LockSupport.park();
26     }catch(Exception e){
27 dl 1.2 threadFail("unexpected exception");
28 dl 1.1 }
29     }
30     });
31     t.start();
32     try{
33     LockSupport.unpark(t);
34     t.join();
35     }
36     catch(Exception e) {
37     fail("unexpected exception");
38     }
39     }
40    
41     public void testParkNanos() {
42     Thread t = new Thread(new Runnable(){
43     public void run(){
44     try{
45     LockSupport.parkNanos(1000);
46     }catch(Exception e){
47 dl 1.2 threadFail("unexpected exception");
48 dl 1.1 }
49     }
50     });
51     try{
52     t.start();
53     t.join();
54     }
55     catch(Exception e) {
56     fail("unexpected exception");
57     }
58     }
59    
60    
61     public void testParkUntil() {
62     Thread t = new Thread(new Runnable(){
63     public void run(){
64     try{
65     long d = new Date().getTime() + 100;
66     LockSupport.parkUntil(d);
67     }catch(Exception e){
68 dl 1.2 threadFail("unexpected exception");
69 dl 1.1 }
70     }
71     });
72     try{
73     t.start();
74     t.join();
75     }
76     catch(Exception e) {
77     fail("unexpected exception");
78     }
79     }
80     }