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

Comparing jsr166/src/test/tck/ReentrantLockTest.java (file contents):
Revision 1.3 by dl, Sun Sep 7 20:39:11 2003 UTC vs.
Revision 1.4 by dl, Sun Sep 14 20:42:40 2003 UTC

# Line 10 | Line 10 | import java.util.concurrent.locks.*;
10   import java.util.concurrent.*;
11   import java.io.*;
12  
13 < public class ReentrantLockTest extends TestCase {
13 > public class ReentrantLockTest extends JSR166TestCase {
14      static int HOLD_COUNT_TEST_LIMIT = 20;
15  
16      public static void main(String[] args) {
# Line 21 | Line 21 | public class ReentrantLockTest extends T
21          return new TestSuite(ReentrantLockTest.class);
22      }
23  
24    private static long SHORT_DELAY_MS = 100;
25    private static long MEDIUM_DELAY_MS = 1000;
26    private static long LONG_DELAY_MS = 10000;
27
24      /*
25       * Unlocks an unlocked lock, throws Illegal Monitor State
26       *
27       */
32    
28      public void testIllegalMonitorStateException(){
29          ReentrantLock rl = new ReentrantLock();
30          try{
# Line 54 | Line 49 | public class ReentrantLockTest extends T
49                  public void run(){
50                      try{
51                          lock.lockInterruptibly();
52 <                        fail("should throw");
52 >                        threadFail("should throw");
53                      } catch(InterruptedException success){}
54                  }
55              });
56 <        t.start();
57 <        t.interrupt();
58 <        lock.unlock();
56 >        try {
57 >            t.start();
58 >            t.interrupt();
59 >            lock.unlock();
60 >            t.join();
61 >        } catch(Exception e){
62 >            fail("unexpected exception");
63 >        }
64      }
65  
66      /*
# Line 75 | Line 75 | public class ReentrantLockTest extends T
75          Thread t = new Thread(new Runnable() {
76                  public void run(){
77                      try{
78 <                        lock.tryLock(1000,TimeUnit.MILLISECONDS);
79 <                        fail("should throw");
78 >                        lock.tryLock(MEDIUM_DELAY_MS,TimeUnit.MILLISECONDS);
79 >                        threadFail("should throw");
80                      } catch(InterruptedException success){}
81                  }
82              });
83 <        t.start();
84 <        t.interrupt();
83 >        try {
84 >            t.start();
85 >            t.interrupt();
86 >        } catch(Exception e){
87 >            fail("unexpected exception");
88 >        }
89      }
90  
91  
# Line 90 | Line 94 | public class ReentrantLockTest extends T
94          lock.lock();
95          Thread t = new Thread(new Runnable() {
96                  public void run(){
97 <                    assertFalse(lock.tryLock());
97 >                    threadAssertFalse(lock.tryLock());
98                  }
99              });
100          try {
# Line 108 | Line 112 | public class ReentrantLockTest extends T
112          Thread t = new Thread(new Runnable() {
113                  public void run(){
114                      try {
115 <                        assertFalse(lock.tryLock(1, TimeUnit.MILLISECONDS));
115 >                        threadAssertFalse(lock.tryLock(1, TimeUnit.MILLISECONDS));
116                      } catch (Exception ex) {
117 <                        fail("unexpected exception");
117 >                        threadFail("unexpected exception");
118                      }
119                  }
120              });
# Line 148 | Line 152 | public class ReentrantLockTest extends T
152                  public void run() {
153                      lock.lock();
154                      try {
155 <                        Thread.sleep(SHORT_DELAY_MS * 2);
155 >                        Thread.sleep(SMALL_DELAY_MS);
156                      }
157 <                    catch(Exception e) {}
157 >                    catch(Exception e) {
158 >                        threadFail("unexpected exception");
159 >                    }
160                      lock.unlock();
161                  }
162              });
# Line 177 | Line 183 | public class ReentrantLockTest extends T
183                  public void run() {
184                      try {
185                          lock.lockInterruptibly();
186 <                        fail("should throw");
186 >                        threadFail("should throw");
187                      }
188                      catch(InterruptedException e) {}
189                  }
# Line 240 | Line 246 | public class ReentrantLockTest extends T
246          final Condition c = lock.newCondition();
247          try {
248              lock.lock();
249 <            assertFalse(c.await(10, TimeUnit.MILLISECONDS));
249 >            assertFalse(c.await(SHORT_DELAY_MS, TimeUnit.MILLISECONDS));
250              lock.unlock();
251          }
252          catch (Exception ex) {
# Line 273 | Line 279 | public class ReentrantLockTest extends T
279                          lock.unlock();
280                      }
281                      catch(InterruptedException e) {
282 <                        fail("unexpected exception");
282 >                        threadFail("unexpected exception");
283                      }
284                  }
285              });
# Line 327 | Line 333 | public class ReentrantLockTest extends T
333                          lock.lock();
334                          c.await();
335                          lock.unlock();
336 <                        fail("should throw");
336 >                        threadFail("should throw");
337                      }
338                      catch(InterruptedException success) {
339                      }
# Line 355 | Line 361 | public class ReentrantLockTest extends T
361                          lock.lock();
362                          c.awaitNanos(SHORT_DELAY_MS * 2 * 1000000);
363                          lock.unlock();
364 <                        fail("should throw");
364 >                        threadFail("should throw");
365                      }
366                      catch(InterruptedException success) {
367                      }
# Line 384 | Line 390 | public class ReentrantLockTest extends T
390                          java.util.Date d = new java.util.Date();
391                          c.awaitUntil(new java.util.Date(d.getTime() + 10000));
392                          lock.unlock();
393 <                        fail("should throw");
393 >                        threadFail("should throw");
394                      }
395                      catch(InterruptedException success) {
396                      }
# Line 414 | Line 420 | public class ReentrantLockTest extends T
420                          lock.unlock();
421                      }
422                      catch(InterruptedException e) {
423 <                        fail("unexpected exception");
423 >                        threadFail("unexpected exception");
424                      }
425                  }
426              });
# Line 427 | Line 433 | public class ReentrantLockTest extends T
433                          lock.unlock();
434                      }
435                      catch(InterruptedException e) {
436 <                        fail("unexpected exception");
436 >                        threadFail("unexpected exception");
437                      }
438                  }
439              });

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines