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.52 by jsr166, Thu May 30 03:28:55 2013 UTC vs.
Revision 1.57 by jsr166, Fri Feb 27 21:43:18 2015 UTC

# Line 6 | Line 6
6   * Pat Fisher, Mike Judd.
7   */
8  
9 < import junit.framework.*;
10 < import java.util.concurrent.locks.Condition;
11 < import java.util.concurrent.locks.ReentrantLock;
9 > import static java.util.concurrent.TimeUnit.MILLISECONDS;
10 >
11 > import java.util.Arrays;
12 > import java.util.Collection;
13 > import java.util.HashSet;
14   import java.util.concurrent.CountDownLatch;
15   import java.util.concurrent.CyclicBarrier;
16 < import static java.util.concurrent.TimeUnit.MILLISECONDS;
17 < import java.util.*;
16 > import java.util.concurrent.locks.Condition;
17 > import java.util.concurrent.locks.ReentrantLock;
18 >
19 > import junit.framework.AssertionFailedError;
20 > import junit.framework.Test;
21 > import junit.framework.TestSuite;
22  
23   public class ReentrantLockTest extends JSR166TestCase {
24      public static void main(String[] args) {
# Line 23 | Line 29 | public class ReentrantLockTest extends J
29      }
30  
31      /**
32 <     * A runnable calling lockInterruptibly
32 >     * A checked runnable calling lockInterruptibly
33       */
34      class InterruptibleLockRunnable extends CheckedRunnable {
35          final ReentrantLock lock;
36 <        InterruptibleLockRunnable(ReentrantLock l) { lock = l; }
36 >        InterruptibleLockRunnable(ReentrantLock lock) { this.lock = lock; }
37          public void realRun() throws InterruptedException {
38              lock.lockInterruptibly();
39          }
40      }
41  
42      /**
43 <     * A runnable calling lockInterruptibly that expects to be
43 >     * A checked runnable calling lockInterruptibly that expects to be
44       * interrupted
45       */
46      class InterruptedLockRunnable extends CheckedInterruptedRunnable {
47          final ReentrantLock lock;
48 <        InterruptedLockRunnable(ReentrantLock l) { lock = l; }
48 >        InterruptedLockRunnable(ReentrantLock lock) { this.lock = lock; }
49          public void realRun() throws InterruptedException {
50              lock.lockInterruptibly();
51          }
# Line 137 | Line 143 | public class ReentrantLockTest extends J
143          lock.unlock();
144      }
145  
146 <    enum AwaitMethod { await, awaitTimed, awaitNanos, awaitUntil };
146 >    enum AwaitMethod { await, awaitTimed, awaitNanos, awaitUntil }
147  
148      /**
149       * Awaits condition using the specified AwaitMethod.
# Line 160 | Line 166 | public class ReentrantLockTest extends J
166          case awaitUntil:
167              assertTrue(c.awaitUntil(delayedDate(timeoutMillis)));
168              break;
169 +        default:
170 +            throw new AssertionError();
171          }
172      }
173  
# Line 452 | Line 460 | public class ReentrantLockTest extends J
460              barrier.await();
461              awaitTermination(t);
462              assertFalse(lock.isLocked());
463 <        } catch (Exception e) {
456 <            threadUnexpectedException(e);
457 <        }
463 >        } catch (Exception fail) { threadUnexpectedException(fail); }
464      }
465  
466      /**
# Line 466 | Line 472 | public class ReentrantLockTest extends J
472          final PublicReentrantLock lock = new PublicReentrantLock(fair);
473          try {
474              lock.lockInterruptibly();
475 <        } catch (InterruptedException ie) {
470 <            threadUnexpectedException(ie);
471 <        }
475 >        } catch (InterruptedException fail) { threadUnexpectedException(fail); }
476          assertLockedByMoi(lock);
477          Thread t = newStartedThread(new InterruptedLockRunnable(lock));
478          waitForQueuedThread(lock, t);
# Line 529 | Line 533 | public class ReentrantLockTest extends J
533              assertTrue(nanosRemaining <= 0);
534              assertTrue(millisElapsedSince(startTime) >= timeoutMillis);
535              lock.unlock();
536 <        } catch (InterruptedException e) {
533 <            threadUnexpectedException(e);
534 <        }
536 >        } catch (InterruptedException fail) { threadUnexpectedException(fail); }
537      }
538  
539      /**
# Line 549 | Line 551 | public class ReentrantLockTest extends J
551              assertFalse(c.await(timeoutMillis, MILLISECONDS));
552              assertTrue(millisElapsedSince(startTime) >= timeoutMillis);
553              lock.unlock();
554 <        } catch (InterruptedException e) {
553 <            threadUnexpectedException(e);
554 <        }
554 >        } catch (InterruptedException fail) { threadUnexpectedException(fail); }
555      }
556  
557      /**
# Line 570 | Line 570 | public class ReentrantLockTest extends J
570              assertFalse(c.awaitUntil(new java.util.Date(d.getTime() + timeoutMillis)));
571              assertTrue(millisElapsedSince(startTime) >= timeoutMillis);
572              lock.unlock();
573 <        } catch (InterruptedException e) {
574 <            threadUnexpectedException(e);
575 <        }
573 >        } catch (InterruptedException fail) { threadUnexpectedException(fail); }
574      }
575  
576      /**

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines