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

Comparing jsr166/src/test/tck/AbstractQueuedSynchronizerTest.java (file contents):
Revision 1.20 by dl, Fri Feb 24 00:03:16 2006 UTC vs.
Revision 1.25 by jsr166, Tue Nov 17 13:40:14 2009 UTC

# Line 2 | Line 2
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.
5 > * Other contributors include Andrew Wright, Jeffrey Hayes,
6 > * Pat Fisher, Mike Judd.
7   */
8  
9  
# Line 31 | Line 31 | public class AbstractQueuedSynchronizerT
31       */
32      static class Mutex extends AbstractQueuedSynchronizer {
33          public boolean isHeldExclusively() { return getState() == 1; }
34 <        
34 >
35          public boolean tryAcquire(int acquires) {
36 <            assertTrue(acquires == 1);
36 >            assertTrue(acquires == 1);
37              return compareAndSetState(0, 1);
38          }
39 <        
39 >
40          public boolean tryRelease(int releases) {
41              if (getState() == 0) throw new IllegalMonitorStateException();
42              setState(0);
43              return true;
44          }
45 <        
45 >
46          public AbstractQueuedSynchronizer.ConditionObject newCondition() { return new AbstractQueuedSynchronizer.ConditionObject(); }
47  
48      }
49  
50 <    
50 >
51      /**
52       * A simple latch class, to test shared mode.
53       */
54 <    static class BooleanLatch extends AbstractQueuedSynchronizer {
54 >    static class BooleanLatch extends AbstractQueuedSynchronizer {
55          public boolean isSignalled() { return getState() != 0; }
56  
57          public int tryAcquireShared(int ignore) {
58              return isSignalled()? 1 : -1;
59          }
60 <        
60 >
61          public boolean tryReleaseShared(int ignore) {
62              setState(1);
63              return true;
# Line 73 | Line 73 | public class AbstractQueuedSynchronizerT
73          public void run() {
74              try {
75                  sync.acquireInterruptibly(1);
76 <            } catch(InterruptedException success){}
76 >            } catch (InterruptedException success) {}
77          }
78      }
79  
# Line 89 | Line 89 | public class AbstractQueuedSynchronizerT
89              try {
90                  sync.acquireInterruptibly(1);
91                  threadShouldThrow();
92 <            } catch(InterruptedException success){}
92 >            } catch (InterruptedException success) {}
93          }
94      }
95  
96      /**
97       * isHeldExclusively is false upon construction
98       */
99 <    public void testIsHeldExclusively() {
99 >    public void testIsHeldExclusively() {
100          Mutex rl = new Mutex();
101          assertFalse(rl.isHeldExclusively());
102      }
103 <    
103 >
104      /**
105       * acquiring released sync succeeds
106       */
107 <    public void testAcquire() {
107 >    public void testAcquire() {
108          Mutex rl = new Mutex();
109          rl.acquire(1);
110          assertTrue(rl.isHeldExclusively());
# Line 115 | Line 115 | public class AbstractQueuedSynchronizerT
115      /**
116       * tryAcquire on an released sync succeeds
117       */
118 <    public void testTryAcquire() {
118 >    public void testTryAcquire() {
119          Mutex rl = new Mutex();
120          assertTrue(rl.tryAcquire(1));
121          assertTrue(rl.isHeldExclusively());
# Line 125 | Line 125 | public class AbstractQueuedSynchronizerT
125      /**
126       * hasQueuedThreads reports whether there are waiting threads
127       */
128 <    public void testhasQueuedThreads() {
128 >    public void testhasQueuedThreads() {
129          final Mutex sync = new Mutex();
130          Thread t1 = new Thread(new InterruptedSyncRunnable(sync));
131          Thread t2 = new Thread(new InterruptibleSyncRunnable(sync));
# Line 146 | Line 146 | public class AbstractQueuedSynchronizerT
146              assertFalse(sync.hasQueuedThreads());
147              t1.join();
148              t2.join();
149 <        } catch(Exception e){
149 >        } catch (Exception e) {
150              unexpectedException();
151          }
152 <    }
152 >    }
153  
154      /**
155       * isQueued(null) throws NPE
156       */
157 <    public void testIsQueuedNPE() {
157 >    public void testIsQueuedNPE() {
158          final Mutex sync = new Mutex();
159          try {
160              sync.isQueued(null);
# Line 166 | Line 166 | public class AbstractQueuedSynchronizerT
166      /**
167       * isQueued reports whether a thread is queued.
168       */
169 <    public void testIsQueued() {
169 >    public void testIsQueued() {
170          final Mutex sync = new Mutex();
171          Thread t1 = new Thread(new InterruptedSyncRunnable(sync));
172          Thread t2 = new Thread(new InterruptibleSyncRunnable(sync));
# Line 192 | Line 192 | public class AbstractQueuedSynchronizerT
192              assertFalse(sync.isQueued(t2));
193              t1.join();
194              t2.join();
195 <        } catch(Exception e){
195 >        } catch (Exception e) {
196              unexpectedException();
197          }
198 <    }
198 >    }
199  
200      /**
201       * getFirstQueuedThread returns first waiting thread or null if none
202       */
203 <    public void testGetFirstQueuedThread() {
203 >    public void testGetFirstQueuedThread() {
204          final Mutex sync = new Mutex();
205          Thread t1 = new Thread(new InterruptedSyncRunnable(sync));
206          Thread t2 = new Thread(new InterruptibleSyncRunnable(sync));
# Line 222 | Line 222 | public class AbstractQueuedSynchronizerT
222              assertNull(sync.getFirstQueuedThread());
223              t1.join();
224              t2.join();
225 <        } catch(Exception e){
225 >        } catch (Exception e) {
226              unexpectedException();
227          }
228 <    }
228 >    }
229  
230  
231      /**
232       * hasContended reports false if no thread has ever blocked, else true
233       */
234 <    public void testHasContended() {
234 >    public void testHasContended() {
235          final Mutex sync = new Mutex();
236          Thread t1 = new Thread(new InterruptedSyncRunnable(sync));
237          Thread t2 = new Thread(new InterruptibleSyncRunnable(sync));
# Line 252 | Line 252 | public class AbstractQueuedSynchronizerT
252              assertTrue(sync.hasContended());
253              t1.join();
254              t2.join();
255 <        } catch(Exception e){
255 >        } catch (Exception e) {
256              unexpectedException();
257          }
258 <    }
258 >    }
259  
260      /**
261       * getQueuedThreads includes waiting threads
262       */
263 <    public void testGetQueuedThreads() {
263 >    public void testGetQueuedThreads() {
264          final Mutex sync = new Mutex();
265          Thread t1 = new Thread(new InterruptedSyncRunnable(sync));
266          Thread t2 = new Thread(new InterruptibleSyncRunnable(sync));
# Line 284 | Line 284 | public class AbstractQueuedSynchronizerT
284              assertTrue(sync.getQueuedThreads().isEmpty());
285              t1.join();
286              t2.join();
287 <        } catch(Exception e){
287 >        } catch (Exception e) {
288              unexpectedException();
289          }
290 <    }
290 >    }
291  
292      /**
293       * getExclusiveQueuedThreads includes waiting threads
294       */
295 <    public void testGetExclusiveQueuedThreads() {
295 >    public void testGetExclusiveQueuedThreads() {
296          final Mutex sync = new Mutex();
297          Thread t1 = new Thread(new InterruptedSyncRunnable(sync));
298          Thread t2 = new Thread(new InterruptibleSyncRunnable(sync));
# Line 316 | Line 316 | public class AbstractQueuedSynchronizerT
316              assertTrue(sync.getExclusiveQueuedThreads().isEmpty());
317              t1.join();
318              t2.join();
319 <        } catch(Exception e){
319 >        } catch (Exception e) {
320              unexpectedException();
321          }
322 <    }
322 >    }
323  
324      /**
325       * getSharedQueuedThreads does not include exclusively waiting threads
326       */
327 <    public void testGetSharedQueuedThreads() {
327 >    public void testGetSharedQueuedThreads() {
328          final Mutex sync = new Mutex();
329          Thread t1 = new Thread(new InterruptedSyncRunnable(sync));
330          Thread t2 = new Thread(new InterruptibleSyncRunnable(sync));
# Line 346 | Line 346 | public class AbstractQueuedSynchronizerT
346              assertTrue(sync.getSharedQueuedThreads().isEmpty());
347              t1.join();
348              t2.join();
349 <        } catch(Exception e){
349 >        } catch (Exception e) {
350              unexpectedException();
351          }
352 <    }
352 >    }
353  
354      /**
355       * tryAcquireNanos is interruptible.
356       */
357 <    public void testInterruptedException2() {
357 >    public void testInterruptedException2() {
358          final Mutex sync = new Mutex();
359          sync.acquire(1);
360          Thread t = new Thread(new Runnable() {
# Line 362 | Line 362 | public class AbstractQueuedSynchronizerT
362                      try {
363                          sync.tryAcquireNanos(1, MEDIUM_DELAY_MS * 1000 * 1000);
364                          threadShouldThrow();
365 <                    } catch(InterruptedException success){}
365 >                    } catch (InterruptedException success) {}
366                  }
367              });
368          try {
369              t.start();
370              t.interrupt();
371 <        } catch(Exception e){
371 >        } catch (Exception e) {
372              unexpectedException();
373          }
374      }
# Line 377 | Line 377 | public class AbstractQueuedSynchronizerT
377      /**
378       * TryAcquire on exclusively held sync fails
379       */
380 <    public void testTryAcquireWhenSynced() {
380 >    public void testTryAcquireWhenSynced() {
381          final Mutex sync = new Mutex();
382          sync.acquire(1);
383          Thread t = new Thread(new Runnable() {
# Line 389 | Line 389 | public class AbstractQueuedSynchronizerT
389              t.start();
390              t.join();
391              sync.release(1);
392 <        } catch(Exception e){
392 >        } catch (Exception e) {
393              unexpectedException();
394          }
395 <    }
395 >    }
396  
397      /**
398       * tryAcquireNanos on an exclusively held sync times out
399       */
400 <    public void testAcquireNanos_Timeout() {
400 >    public void testAcquireNanos_Timeout() {
401          final Mutex sync = new Mutex();
402          sync.acquire(1);
403          Thread t = new Thread(new Runnable() {
# Line 413 | Line 413 | public class AbstractQueuedSynchronizerT
413              t.start();
414              t.join();
415              sync.release(1);
416 <        } catch(Exception e){
416 >        } catch (Exception e) {
417              unexpectedException();
418          }
419 <    }
420 <    
421 <  
419 >    }
420 >
421 >
422      /**
423       * getState is true when acquired and false when not
424       */
# Line 428 | Line 428 | public class AbstractQueuedSynchronizerT
428          assertTrue(sync.isHeldExclusively());
429          sync.release(1);
430          assertFalse(sync.isHeldExclusively());
431 <        Thread t = new Thread(new Runnable() {
431 >        Thread t = new Thread(new Runnable() {
432                  public void run() {
433                      sync.acquire(1);
434                      try {
435                          Thread.sleep(SMALL_DELAY_MS);
436                      }
437 <                    catch(Exception e) {
437 >                    catch (Exception e) {
438                          threadUnexpectedException();
439                      }
440                      sync.release(1);
# Line 446 | Line 446 | public class AbstractQueuedSynchronizerT
446              assertTrue(sync.isHeldExclusively());
447              t.join();
448              assertFalse(sync.isHeldExclusively());
449 <        } catch(Exception e){
449 >        } catch (Exception e) {
450              unexpectedException();
451          }
452      }
# Line 455 | Line 455 | public class AbstractQueuedSynchronizerT
455      /**
456       * acquireInterruptibly is interruptible.
457       */
458 <    public void testAcquireInterruptibly1() {
458 >    public void testAcquireInterruptibly1() {
459          final Mutex sync = new Mutex();
460          sync.acquire(1);
461          Thread t = new Thread(new InterruptedSyncRunnable(sync));
# Line 463 | Line 463 | public class AbstractQueuedSynchronizerT
463              t.start();
464              Thread.sleep(SHORT_DELAY_MS);
465              t.interrupt();
466 +            Thread.sleep(SHORT_DELAY_MS);
467              sync.release(1);
468              t.join();
469 <        } catch(Exception e){
469 >        } catch (Exception e) {
470              unexpectedException();
471          }
472 <    }
472 >    }
473  
474      /**
475       * acquireInterruptibly succeeds when released, else is interruptible
476       */
477      public void testAcquireInterruptibly2() {
478 <        final Mutex sync = new Mutex();
478 >        final Mutex sync = new Mutex();
479          try {
480              sync.acquireInterruptibly(1);
481 <        } catch(Exception e) {
481 >        } catch (Exception e) {
482              unexpectedException();
483          }
484          Thread t = new Thread(new InterruptedSyncRunnable(sync));
# Line 486 | Line 487 | public class AbstractQueuedSynchronizerT
487              t.interrupt();
488              assertTrue(sync.isHeldExclusively());
489              t.join();
490 <        } catch(Exception e){
490 >        } catch (Exception e) {
491              unexpectedException();
492          }
493      }
# Line 495 | Line 496 | public class AbstractQueuedSynchronizerT
496       * owns is true for a condition created by sync else false
497       */
498      public void testOwns() {
499 <        final Mutex sync = new Mutex();
499 >        final Mutex sync = new Mutex();
500          final AbstractQueuedSynchronizer.ConditionObject c = sync.newCondition();
501          final Mutex sync2 = new Mutex();
502          assertTrue(sync.owns(c));
# Line 506 | Line 507 | public class AbstractQueuedSynchronizerT
507       * Calling await without holding sync throws IllegalMonitorStateException
508       */
509      public void testAwait_IllegalMonitor() {
510 <        final Mutex sync = new Mutex();
510 >        final Mutex sync = new Mutex();
511          final AbstractQueuedSynchronizer.ConditionObject c = sync.newCondition();
512          try {
513              c.await();
# Line 523 | Line 524 | public class AbstractQueuedSynchronizerT
524       * Calling signal without holding sync throws IllegalMonitorStateException
525       */
526      public void testSignal_IllegalMonitor() {
527 <        final Mutex sync = new Mutex();
527 >        final Mutex sync = new Mutex();
528          final AbstractQueuedSynchronizer.ConditionObject c = sync.newCondition();
529          try {
530              c.signal();
# Line 540 | Line 541 | public class AbstractQueuedSynchronizerT
541       * awaitNanos without a signal times out
542       */
543      public void testAwaitNanos_Timeout() {
544 <        final Mutex sync = new Mutex();
544 >        final Mutex sync = new Mutex();
545          final AbstractQueuedSynchronizer.ConditionObject c = sync.newCondition();
546          try {
547              sync.acquire(1);
# Line 557 | Line 558 | public class AbstractQueuedSynchronizerT
558       *  Timed await without a signal times out
559       */
560      public void testAwait_Timeout() {
561 <        final Mutex sync = new Mutex();
561 >        final Mutex sync = new Mutex();
562          final AbstractQueuedSynchronizer.ConditionObject c = sync.newCondition();
563          try {
564              sync.acquire(1);
# Line 573 | Line 574 | public class AbstractQueuedSynchronizerT
574       * awaitUntil without a signal times out
575       */
576      public void testAwaitUntil_Timeout() {
577 <        final Mutex sync = new Mutex();
577 >        final Mutex sync = new Mutex();
578          final AbstractQueuedSynchronizer.ConditionObject c = sync.newCondition();
579          try {
580              sync.acquire(1);
# Line 590 | Line 591 | public class AbstractQueuedSynchronizerT
591       * await returns when signalled
592       */
593      public void testAwait() {
594 <        final Mutex sync = new Mutex();
594 >        final Mutex sync = new Mutex();
595          final AbstractQueuedSynchronizer.ConditionObject c = sync.newCondition();
596 <        Thread t = new Thread(new Runnable() {
596 >        Thread t = new Thread(new Runnable() {
597                  public void run() {
598                      try {
599                          sync.acquire(1);
600                          c.await();
601                          sync.release(1);
602                      }
603 <                    catch(InterruptedException e) {
603 >                    catch (InterruptedException e) {
604                          threadUnexpectedException();
605                      }
606                  }
# Line 670 | Line 671 | public class AbstractQueuedSynchronizerT
671       */
672      public void testHasWaitersIAE() {
673          final Mutex sync = new Mutex();
674 <        final AbstractQueuedSynchronizer.ConditionObject c = (sync.newCondition());
674 >        final AbstractQueuedSynchronizer.ConditionObject c = sync.newCondition();
675          final Mutex sync2 = new Mutex();
676          try {
677              sync2.hasWaiters(c);
# Line 686 | Line 687 | public class AbstractQueuedSynchronizerT
687       */
688      public void testHasWaitersIMSE() {
689          final Mutex sync = new Mutex();
690 <        final AbstractQueuedSynchronizer.ConditionObject c = (sync.newCondition());
690 >        final AbstractQueuedSynchronizer.ConditionObject c = sync.newCondition();
691          try {
692              sync.hasWaiters(c);
693              shouldThrow();
# Line 702 | Line 703 | public class AbstractQueuedSynchronizerT
703       */
704      public void testGetWaitQueueLengthIAE() {
705          final Mutex sync = new Mutex();
706 <        final AbstractQueuedSynchronizer.ConditionObject c = (sync.newCondition());
706 >        final AbstractQueuedSynchronizer.ConditionObject c = sync.newCondition();
707          final Mutex sync2 = new Mutex();
708          try {
709              sync2.getWaitQueueLength(c);
# Line 718 | Line 719 | public class AbstractQueuedSynchronizerT
719       */
720      public void testGetWaitQueueLengthIMSE() {
721          final Mutex sync = new Mutex();
722 <        final AbstractQueuedSynchronizer.ConditionObject c = (sync.newCondition());
722 >        final AbstractQueuedSynchronizer.ConditionObject c = sync.newCondition();
723          try {
724              sync.getWaitQueueLength(c);
725              shouldThrow();
# Line 733 | Line 734 | public class AbstractQueuedSynchronizerT
734       * getWaitingThreads throws IAE if not owned
735       */
736      public void testGetWaitingThreadsIAE() {
737 <        final Mutex sync = new Mutex();
738 <        final AbstractQueuedSynchronizer.ConditionObject c = (sync.newCondition());
739 <        final Mutex sync2 = new Mutex();        
737 >        final Mutex sync = new Mutex();
738 >        final AbstractQueuedSynchronizer.ConditionObject c = sync.newCondition();
739 >        final Mutex sync2 = new Mutex();
740          try {
741              sync2.getWaitingThreads(c);
742              shouldThrow();
# Line 749 | Line 750 | public class AbstractQueuedSynchronizerT
750       * getWaitingThreads throws IMSE if not synced
751       */
752      public void testGetWaitingThreadsIMSE() {
753 <        final Mutex sync = new Mutex();
754 <        final AbstractQueuedSynchronizer.ConditionObject c = (sync.newCondition());
753 >        final Mutex sync = new Mutex();
754 >        final AbstractQueuedSynchronizer.ConditionObject c = sync.newCondition();
755          try {
756              sync.getWaitingThreads(c);
757              shouldThrow();
# Line 766 | Line 767 | public class AbstractQueuedSynchronizerT
767       * hasWaiters returns true when a thread is waiting, else false
768       */
769      public void testHasWaiters() {
770 <        final Mutex sync = new Mutex();
770 >        final Mutex sync = new Mutex();
771          final AbstractQueuedSynchronizer.ConditionObject c = sync.newCondition();
772 <        Thread t = new Thread(new Runnable() {
772 >        Thread t = new Thread(new Runnable() {
773                  public void run() {
774                      try {
775                          sync.acquire(1);
# Line 777 | Line 778 | public class AbstractQueuedSynchronizerT
778                          c.await();
779                          sync.release(1);
780                      }
781 <                    catch(InterruptedException e) {
781 >                    catch (InterruptedException e) {
782                          threadUnexpectedException();
783                      }
784                  }
# Line 808 | Line 809 | public class AbstractQueuedSynchronizerT
809       * getWaitQueueLength returns number of waiting threads
810       */
811      public void testGetWaitQueueLength() {
812 <        final Mutex sync = new Mutex();
812 >        final Mutex sync = new Mutex();
813          final AbstractQueuedSynchronizer.ConditionObject c = sync.newCondition();
814 <        Thread t1 = new Thread(new Runnable() {
814 >        Thread t1 = new Thread(new Runnable() {
815                  public void run() {
816                      try {
817                          sync.acquire(1);
# Line 819 | Line 820 | public class AbstractQueuedSynchronizerT
820                          c.await();
821                          sync.release(1);
822                      }
823 <                    catch(InterruptedException e) {
823 >                    catch (InterruptedException e) {
824                          threadUnexpectedException();
825                      }
826                  }
827              });
828  
829 <        Thread t2 = new Thread(new Runnable() {
829 >        Thread t2 = new Thread(new Runnable() {
830                  public void run() {
831                      try {
832                          sync.acquire(1);
# Line 834 | Line 835 | public class AbstractQueuedSynchronizerT
835                          c.await();
836                          sync.release(1);
837                      }
838 <                    catch(InterruptedException e) {
838 >                    catch (InterruptedException e) {
839                          threadUnexpectedException();
840                      }
841                  }
# Line 869 | Line 870 | public class AbstractQueuedSynchronizerT
870       * getWaitingThreads returns only and all waiting threads
871       */
872      public void testGetWaitingThreads() {
873 <        final Mutex sync = new Mutex();
873 >        final Mutex sync = new Mutex();
874          final AbstractQueuedSynchronizer.ConditionObject c = sync.newCondition();
875 <        Thread t1 = new Thread(new Runnable() {
875 >        Thread t1 = new Thread(new Runnable() {
876                  public void run() {
877                      try {
878                          sync.acquire(1);
# Line 879 | Line 880 | public class AbstractQueuedSynchronizerT
880                          c.await();
881                          sync.release(1);
882                      }
883 <                    catch(InterruptedException e) {
883 >                    catch (InterruptedException e) {
884                          threadUnexpectedException();
885                      }
886                  }
887              });
888  
889 <        Thread t2 = new Thread(new Runnable() {
889 >        Thread t2 = new Thread(new Runnable() {
890                  public void run() {
891                      try {
892                          sync.acquire(1);
# Line 893 | Line 894 | public class AbstractQueuedSynchronizerT
894                          c.await();
895                          sync.release(1);
896                      }
897 <                    catch(InterruptedException e) {
897 >                    catch (InterruptedException e) {
898                          threadUnexpectedException();
899                      }
900                  }
# Line 934 | Line 935 | public class AbstractQueuedSynchronizerT
935       * awaitUninterruptibly doesn't abort on interrupt
936       */
937      public void testAwaitUninterruptibly() {
938 <        final Mutex sync = new Mutex();
938 >        final Mutex sync = new Mutex();
939          final AbstractQueuedSynchronizer.ConditionObject c = sync.newCondition();
940 <        Thread t = new Thread(new Runnable() {
940 >        Thread t = new Thread(new Runnable() {
941                  public void run() {
942                      sync.acquire(1);
943                      c.awaitUninterruptibly();
# Line 963 | Line 964 | public class AbstractQueuedSynchronizerT
964       * await is interruptible
965       */
966      public void testAwait_Interrupt() {
967 <        final Mutex sync = new Mutex();
967 >        final Mutex sync = new Mutex();
968          final AbstractQueuedSynchronizer.ConditionObject c = sync.newCondition();
969 <        Thread t = new Thread(new Runnable() {
969 >        Thread t = new Thread(new Runnable() {
970                  public void run() {
971                      try {
972                          sync.acquire(1);
# Line 973 | Line 974 | public class AbstractQueuedSynchronizerT
974                          sync.release(1);
975                          threadShouldThrow();
976                      }
977 <                    catch(InterruptedException success) {
977 >                    catch (InterruptedException success) {
978                      }
979                  }
980              });
# Line 994 | Line 995 | public class AbstractQueuedSynchronizerT
995       * awaitNanos is interruptible
996       */
997      public void testAwaitNanos_Interrupt() {
998 <        final Mutex sync = new Mutex();
998 >        final Mutex sync = new Mutex();
999          final AbstractQueuedSynchronizer.ConditionObject c = sync.newCondition();
1000 <        Thread t = new Thread(new Runnable() {
1000 >        Thread t = new Thread(new Runnable() {
1001                  public void run() {
1002                      try {
1003                          sync.acquire(1);
# Line 1004 | Line 1005 | public class AbstractQueuedSynchronizerT
1005                          sync.release(1);
1006                          threadShouldThrow();
1007                      }
1008 <                    catch(InterruptedException success) {
1008 >                    catch (InterruptedException success) {
1009                      }
1010                  }
1011              });
# Line 1025 | Line 1026 | public class AbstractQueuedSynchronizerT
1026       * awaitUntil is interruptible
1027       */
1028      public void testAwaitUntil_Interrupt() {
1029 <        final Mutex sync = new Mutex();
1029 >        final Mutex sync = new Mutex();
1030          final AbstractQueuedSynchronizer.ConditionObject c = sync.newCondition();
1031 <        Thread t = new Thread(new Runnable() {
1031 >        Thread t = new Thread(new Runnable() {
1032                  public void run() {
1033                      try {
1034                          sync.acquire(1);
# Line 1036 | Line 1037 | public class AbstractQueuedSynchronizerT
1037                          sync.release(1);
1038                          threadShouldThrow();
1039                      }
1040 <                    catch(InterruptedException success) {
1040 >                    catch (InterruptedException success) {
1041                      }
1042                  }
1043              });
# Line 1057 | Line 1058 | public class AbstractQueuedSynchronizerT
1058       * signalAll wakes up all threads
1059       */
1060      public void testSignalAll() {
1061 <        final Mutex sync = new Mutex();
1061 >        final Mutex sync = new Mutex();
1062          final AbstractQueuedSynchronizer.ConditionObject c = sync.newCondition();
1063 <        Thread t1 = new Thread(new Runnable() {
1063 >        Thread t1 = new Thread(new Runnable() {
1064                  public void run() {
1065                      try {
1066                          sync.acquire(1);
1067                          c.await();
1068                          sync.release(1);
1069                      }
1070 <                    catch(InterruptedException e) {
1070 >                    catch (InterruptedException e) {
1071                          threadUnexpectedException();
1072                      }
1073                  }
1074              });
1075  
1076 <        Thread t2 = new Thread(new Runnable() {
1076 >        Thread t2 = new Thread(new Runnable() {
1077                  public void run() {
1078                      try {
1079                          sync.acquire(1);
1080                          c.await();
1081                          sync.release(1);
1082                      }
1083 <                    catch(InterruptedException e) {
1083 >                    catch (InterruptedException e) {
1084                          threadUnexpectedException();
1085                      }
1086                  }
# Line 1133 | Line 1134 | public class AbstractQueuedSynchronizerT
1134              ObjectInputStream in = new ObjectInputStream(new BufferedInputStream(bin));
1135              Mutex r = (Mutex) in.readObject();
1136              assertTrue(r.isHeldExclusively());
1137 <        } catch(Exception e){
1137 >        } catch (Exception e) {
1138              e.printStackTrace();
1139              unexpectedException();
1140          }
# Line 1174 | Line 1175 | public class AbstractQueuedSynchronizerT
1175                          threadAssertFalse(l.isSignalled());
1176                          l.acquireSharedInterruptibly(0);
1177                          threadAssertTrue(l.isSignalled());
1178 <                    } catch(InterruptedException e){
1178 >                    } catch (InterruptedException e) {
1179                          threadUnexpectedException();
1180                      }
1181                  }
# Line 1186 | Line 1187 | public class AbstractQueuedSynchronizerT
1187              l.releaseShared(0);
1188              assertTrue(l.isSignalled());
1189              t.join();
1190 <        } catch (InterruptedException e){
1190 >        } catch (InterruptedException e) {
1191              unexpectedException();
1192          }
1193      }
1194 <    
1194 >
1195  
1196      /**
1197       * acquireSharedTimed returns after release
# Line 1205 | Line 1206 | public class AbstractQueuedSynchronizerT
1206                          threadAssertTrue(l.tryAcquireSharedNanos(0, MEDIUM_DELAY_MS* 1000 * 1000));
1207                          threadAssertTrue(l.isSignalled());
1208  
1209 <                    } catch(InterruptedException e){
1209 >                    } catch (InterruptedException e) {
1210                          threadUnexpectedException();
1211                      }
1212                  }
# Line 1217 | Line 1218 | public class AbstractQueuedSynchronizerT
1218              l.releaseShared(0);
1219              assertTrue(l.isSignalled());
1220              t.join();
1221 <        } catch (InterruptedException e){
1221 >        } catch (InterruptedException e) {
1222              unexpectedException();
1223          }
1224      }
1225 <    
1225 >
1226      /**
1227       * acquireSharedInterruptibly throws IE if interrupted before released
1228       */
# Line 1233 | Line 1234 | public class AbstractQueuedSynchronizerT
1234                          threadAssertFalse(l.isSignalled());
1235                          l.acquireSharedInterruptibly(0);
1236                          threadShouldThrow();
1237 <                    } catch(InterruptedException success){}
1237 >                    } catch (InterruptedException success) {}
1238                  }
1239              });
1240          t.start();
# Line 1241 | Line 1242 | public class AbstractQueuedSynchronizerT
1242              assertFalse(l.isSignalled());
1243              t.interrupt();
1244              t.join();
1245 <        } catch (InterruptedException e){
1245 >        } catch (InterruptedException e) {
1246              unexpectedException();
1247          }
1248      }
# Line 1256 | Line 1257 | public class AbstractQueuedSynchronizerT
1257                      try {
1258                          threadAssertFalse(l.isSignalled());
1259                          l.tryAcquireSharedNanos(0, SMALL_DELAY_MS* 1000 * 1000);
1260 <                        threadShouldThrow();                        
1261 <                    } catch(InterruptedException success){}
1260 >                        threadShouldThrow();
1261 >                    } catch (InterruptedException success) {}
1262                  }
1263              });
1264          t.start();
# Line 1266 | Line 1267 | public class AbstractQueuedSynchronizerT
1267              assertFalse(l.isSignalled());
1268              t.interrupt();
1269              t.join();
1270 <        } catch (InterruptedException e){
1270 >        } catch (InterruptedException e) {
1271              unexpectedException();
1272          }
1273      }
# Line 1281 | Line 1282 | public class AbstractQueuedSynchronizerT
1282                      try {
1283                          threadAssertFalse(l.isSignalled());
1284                          threadAssertFalse(l.tryAcquireSharedNanos(0, SMALL_DELAY_MS* 1000 * 1000));
1285 <                    } catch(InterruptedException ie){
1285 >                    } catch (InterruptedException ie) {
1286                          threadUnexpectedException();
1287                      }
1288                  }
# Line 1291 | Line 1292 | public class AbstractQueuedSynchronizerT
1292              Thread.sleep(SHORT_DELAY_MS);
1293              assertFalse(l.isSignalled());
1294              t.join();
1295 <        } catch (InterruptedException e){
1295 >        } catch (InterruptedException e) {
1296              unexpectedException();
1297          }
1298      }
1299  
1300 <    
1300 >
1301   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines