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

Comparing jsr166/src/test/tck/AbstractQueuedLongSynchronizerTest.java (file contents):
Revision 1.4 by dl, Thu May 18 10:29:23 2006 UTC vs.
Revision 1.8 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 32 | Line 32 | public class AbstractQueuedLongSynchroni
32      static class Mutex extends AbstractQueuedLongSynchronizer {
33          // Use value > 32 bits for locked state
34          static final long LOCKED = 1 << 48;
35 <        public boolean isHeldExclusively() {
36 <            return getState() == LOCKED;
35 >        public boolean isHeldExclusively() {
36 >            return getState() == LOCKED;
37          }
38 <        
38 >
39          public boolean tryAcquire(long acquires) {
40              return compareAndSetState(0, LOCKED);
41          }
42 <        
42 >
43          public boolean tryRelease(long releases) {
44              if (getState() == 0) throw new IllegalMonitorStateException();
45              setState(0);
46              return true;
47          }
48 <        
48 >
49          public AbstractQueuedLongSynchronizer.ConditionObject newCondition() { return new AbstractQueuedLongSynchronizer.ConditionObject(); }
50  
51      }
52  
53 <    
53 >
54      /**
55       * A simple latch class, to test shared mode.
56       */
57 <    static class BooleanLatch extends AbstractQueuedLongSynchronizer {
57 >    static class BooleanLatch extends AbstractQueuedLongSynchronizer {
58          public boolean isSignalled() { return getState() != 0; }
59  
60          public long tryAcquireShared(long ignore) {
61              return isSignalled()? 1 : -1;
62          }
63 <        
63 >
64          public boolean tryReleaseShared(long ignore) {
65              setState(1 << 62);
66              return true;
# Line 76 | Line 76 | public class AbstractQueuedLongSynchroni
76          public void run() {
77              try {
78                  sync.acquireInterruptibly(1);
79 <            } catch(InterruptedException success){}
79 >            } catch (InterruptedException success) {}
80          }
81      }
82  
# Line 92 | Line 92 | public class AbstractQueuedLongSynchroni
92              try {
93                  sync.acquireInterruptibly(1);
94                  threadShouldThrow();
95 <            } catch(InterruptedException success){}
95 >            } catch (InterruptedException success) {}
96          }
97      }
98  
99      /**
100       * isHeldExclusively is false upon construction
101       */
102 <    public void testIsHeldExclusively() {
102 >    public void testIsHeldExclusively() {
103          Mutex rl = new Mutex();
104          assertFalse(rl.isHeldExclusively());
105      }
106 <    
106 >
107      /**
108       * acquiring released sync succeeds
109       */
110 <    public void testAcquire() {
110 >    public void testAcquire() {
111          Mutex rl = new Mutex();
112          rl.acquire(1);
113          assertTrue(rl.isHeldExclusively());
# Line 118 | Line 118 | public class AbstractQueuedLongSynchroni
118      /**
119       * tryAcquire on an released sync succeeds
120       */
121 <    public void testTryAcquire() {
121 >    public void testTryAcquire() {
122          Mutex rl = new Mutex();
123          assertTrue(rl.tryAcquire(1));
124          assertTrue(rl.isHeldExclusively());
# Line 128 | Line 128 | public class AbstractQueuedLongSynchroni
128      /**
129       * hasQueuedThreads reports whether there are waiting threads
130       */
131 <    public void testhasQueuedThreads() {
131 >    public void testhasQueuedThreads() {
132          final Mutex sync = new Mutex();
133          Thread t1 = new Thread(new InterruptedSyncRunnable(sync));
134          Thread t2 = new Thread(new InterruptibleSyncRunnable(sync));
# Line 149 | Line 149 | public class AbstractQueuedLongSynchroni
149              assertFalse(sync.hasQueuedThreads());
150              t1.join();
151              t2.join();
152 <        } catch(Exception e){
152 >        } catch (Exception e) {
153              unexpectedException();
154          }
155 <    }
155 >    }
156  
157      /**
158       * isQueued(null) throws NPE
159       */
160 <    public void testIsQueuedNPE() {
160 >    public void testIsQueuedNPE() {
161          final Mutex sync = new Mutex();
162          try {
163              sync.isQueued(null);
# Line 169 | Line 169 | public class AbstractQueuedLongSynchroni
169      /**
170       * isQueued reports whether a thread is queued.
171       */
172 <    public void testIsQueued() {
172 >    public void testIsQueued() {
173          final Mutex sync = new Mutex();
174          Thread t1 = new Thread(new InterruptedSyncRunnable(sync));
175          Thread t2 = new Thread(new InterruptibleSyncRunnable(sync));
# Line 195 | Line 195 | public class AbstractQueuedLongSynchroni
195              assertFalse(sync.isQueued(t2));
196              t1.join();
197              t2.join();
198 <        } catch(Exception e){
198 >        } catch (Exception e) {
199              unexpectedException();
200          }
201 <    }
201 >    }
202  
203      /**
204       * getFirstQueuedThread returns first waiting thread or null if none
205       */
206 <    public void testGetFirstQueuedThread() {
206 >    public void testGetFirstQueuedThread() {
207          final Mutex sync = new Mutex();
208          Thread t1 = new Thread(new InterruptedSyncRunnable(sync));
209          Thread t2 = new Thread(new InterruptibleSyncRunnable(sync));
# Line 225 | Line 225 | public class AbstractQueuedLongSynchroni
225              assertNull(sync.getFirstQueuedThread());
226              t1.join();
227              t2.join();
228 <        } catch(Exception e){
228 >        } catch (Exception e) {
229              unexpectedException();
230          }
231 <    }
231 >    }
232  
233  
234      /**
235       * hasContended reports false if no thread has ever blocked, else true
236       */
237 <    public void testHasContended() {
237 >    public void testHasContended() {
238          final Mutex sync = new Mutex();
239          Thread t1 = new Thread(new InterruptedSyncRunnable(sync));
240          Thread t2 = new Thread(new InterruptibleSyncRunnable(sync));
# Line 255 | Line 255 | public class AbstractQueuedLongSynchroni
255              assertTrue(sync.hasContended());
256              t1.join();
257              t2.join();
258 <        } catch(Exception e){
258 >        } catch (Exception e) {
259              unexpectedException();
260          }
261 <    }
261 >    }
262  
263      /**
264       * getQueuedThreads includes waiting threads
265       */
266 <    public void testGetQueuedThreads() {
266 >    public void testGetQueuedThreads() {
267          final Mutex sync = new Mutex();
268          Thread t1 = new Thread(new InterruptedSyncRunnable(sync));
269          Thread t2 = new Thread(new InterruptibleSyncRunnable(sync));
# Line 287 | Line 287 | public class AbstractQueuedLongSynchroni
287              assertTrue(sync.getQueuedThreads().isEmpty());
288              t1.join();
289              t2.join();
290 <        } catch(Exception e){
290 >        } catch (Exception e) {
291              unexpectedException();
292          }
293 <    }
293 >    }
294  
295      /**
296       * getExclusiveQueuedThreads includes waiting threads
297       */
298 <    public void testGetExclusiveQueuedThreads() {
298 >    public void testGetExclusiveQueuedThreads() {
299          final Mutex sync = new Mutex();
300          Thread t1 = new Thread(new InterruptedSyncRunnable(sync));
301          Thread t2 = new Thread(new InterruptibleSyncRunnable(sync));
# Line 319 | Line 319 | public class AbstractQueuedLongSynchroni
319              assertTrue(sync.getExclusiveQueuedThreads().isEmpty());
320              t1.join();
321              t2.join();
322 <        } catch(Exception e){
322 >        } catch (Exception e) {
323              unexpectedException();
324          }
325 <    }
325 >    }
326  
327      /**
328       * getSharedQueuedThreads does not include exclusively waiting threads
329       */
330 <    public void testGetSharedQueuedThreads() {
330 >    public void testGetSharedQueuedThreads() {
331          final Mutex sync = new Mutex();
332          Thread t1 = new Thread(new InterruptedSyncRunnable(sync));
333          Thread t2 = new Thread(new InterruptibleSyncRunnable(sync));
# Line 349 | Line 349 | public class AbstractQueuedLongSynchroni
349              assertTrue(sync.getSharedQueuedThreads().isEmpty());
350              t1.join();
351              t2.join();
352 <        } catch(Exception e){
352 >        } catch (Exception e) {
353              unexpectedException();
354          }
355 <    }
355 >    }
356  
357      /**
358       * tryAcquireNanos is interruptible.
359       */
360 <    public void testInterruptedException2() {
360 >    public void testInterruptedException2() {
361          final Mutex sync = new Mutex();
362          sync.acquire(1);
363          Thread t = new Thread(new Runnable() {
# Line 365 | Line 365 | public class AbstractQueuedLongSynchroni
365                      try {
366                          sync.tryAcquireNanos(1, MEDIUM_DELAY_MS * 1000 * 1000);
367                          threadShouldThrow();
368 <                    } catch(InterruptedException success){}
368 >                    } catch (InterruptedException success) {}
369                  }
370              });
371          try {
372              t.start();
373              t.interrupt();
374 <        } catch(Exception e){
374 >        } catch (Exception e) {
375              unexpectedException();
376          }
377      }
# Line 380 | Line 380 | public class AbstractQueuedLongSynchroni
380      /**
381       * TryAcquire on exclusively held sync fails
382       */
383 <    public void testTryAcquireWhenSynced() {
383 >    public void testTryAcquireWhenSynced() {
384          final Mutex sync = new Mutex();
385          sync.acquire(1);
386          Thread t = new Thread(new Runnable() {
# Line 392 | Line 392 | public class AbstractQueuedLongSynchroni
392              t.start();
393              t.join();
394              sync.release(1);
395 <        } catch(Exception e){
395 >        } catch (Exception e) {
396              unexpectedException();
397          }
398 <    }
398 >    }
399  
400      /**
401       * tryAcquireNanos on an exclusively held sync times out
402       */
403 <    public void testAcquireNanos_Timeout() {
403 >    public void testAcquireNanos_Timeout() {
404          final Mutex sync = new Mutex();
405          sync.acquire(1);
406          Thread t = new Thread(new Runnable() {
# Line 408 | Line 408 | public class AbstractQueuedLongSynchroni
408                      try {
409                          threadAssertFalse(sync.tryAcquireNanos(1, 1000 * 1000));
410                      } catch (Exception ex) {
411 <                        threadUnexpectedException();
411 >                        threadUnexpectedException(ex);
412                      }
413                  }
414              });
# Line 416 | Line 416 | public class AbstractQueuedLongSynchroni
416              t.start();
417              t.join();
418              sync.release(1);
419 <        } catch(Exception e){
419 >        } catch (Exception e) {
420              unexpectedException();
421          }
422 <    }
423 <    
424 <  
422 >    }
423 >
424 >
425      /**
426       * getState is true when acquired and false when not
427       */
# Line 431 | Line 431 | public class AbstractQueuedLongSynchroni
431          assertTrue(sync.isHeldExclusively());
432          sync.release(1);
433          assertFalse(sync.isHeldExclusively());
434 <        Thread t = new Thread(new Runnable() {
434 >        Thread t = new Thread(new Runnable() {
435                  public void run() {
436                      sync.acquire(1);
437                      try {
438                          Thread.sleep(SMALL_DELAY_MS);
439                      }
440 <                    catch(Exception e) {
441 <                        threadUnexpectedException();
440 >                    catch (Exception e) {
441 >                        threadUnexpectedException(e);
442                      }
443                      sync.release(1);
444                  }
# Line 449 | Line 449 | public class AbstractQueuedLongSynchroni
449              assertTrue(sync.isHeldExclusively());
450              t.join();
451              assertFalse(sync.isHeldExclusively());
452 <        } catch(Exception e){
452 >        } catch (Exception e) {
453              unexpectedException();
454          }
455      }
# Line 458 | Line 458 | public class AbstractQueuedLongSynchroni
458      /**
459       * acquireInterruptibly is interruptible.
460       */
461 <    public void testAcquireInterruptibly1() {
461 >    public void testAcquireInterruptibly1() {
462          final Mutex sync = new Mutex();
463          sync.acquire(1);
464          Thread t = new Thread(new InterruptedSyncRunnable(sync));
# Line 469 | Line 469 | public class AbstractQueuedLongSynchroni
469              Thread.sleep(SHORT_DELAY_MS);
470              sync.release(1);
471              t.join();
472 <        } catch(Exception e){
472 >        } catch (Exception e) {
473              unexpectedException();
474          }
475 <    }
475 >    }
476  
477      /**
478       * acquireInterruptibly succeeds when released, else is interruptible
479       */
480      public void testAcquireInterruptibly2() {
481 <        final Mutex sync = new Mutex();
481 >        final Mutex sync = new Mutex();
482          try {
483              sync.acquireInterruptibly(1);
484 <        } catch(Exception e) {
484 >        } catch (Exception e) {
485              unexpectedException();
486          }
487          Thread t = new Thread(new InterruptedSyncRunnable(sync));
# Line 490 | Line 490 | public class AbstractQueuedLongSynchroni
490              t.interrupt();
491              assertTrue(sync.isHeldExclusively());
492              t.join();
493 <        } catch(Exception e){
493 >        } catch (Exception e) {
494              unexpectedException();
495          }
496      }
# Line 499 | Line 499 | public class AbstractQueuedLongSynchroni
499       * owns is true for a condition created by sync else false
500       */
501      public void testOwns() {
502 <        final Mutex sync = new Mutex();
502 >        final Mutex sync = new Mutex();
503          final AbstractQueuedLongSynchronizer.ConditionObject c = sync.newCondition();
504          final Mutex sync2 = new Mutex();
505          assertTrue(sync.owns(c));
# Line 510 | Line 510 | public class AbstractQueuedLongSynchroni
510       * Calling await without holding sync throws IllegalMonitorStateException
511       */
512      public void testAwait_IllegalMonitor() {
513 <        final Mutex sync = new Mutex();
513 >        final Mutex sync = new Mutex();
514          final AbstractQueuedLongSynchronizer.ConditionObject c = sync.newCondition();
515          try {
516              c.await();
# Line 527 | Line 527 | public class AbstractQueuedLongSynchroni
527       * Calling signal without holding sync throws IllegalMonitorStateException
528       */
529      public void testSignal_IllegalMonitor() {
530 <        final Mutex sync = new Mutex();
530 >        final Mutex sync = new Mutex();
531          final AbstractQueuedLongSynchronizer.ConditionObject c = sync.newCondition();
532          try {
533              c.signal();
# Line 544 | Line 544 | public class AbstractQueuedLongSynchroni
544       * awaitNanos without a signal times out
545       */
546      public void testAwaitNanos_Timeout() {
547 <        final Mutex sync = new Mutex();
547 >        final Mutex sync = new Mutex();
548          final AbstractQueuedLongSynchronizer.ConditionObject c = sync.newCondition();
549          try {
550              sync.acquire(1);
# Line 561 | Line 561 | public class AbstractQueuedLongSynchroni
561       *  Timed await without a signal times out
562       */
563      public void testAwait_Timeout() {
564 <        final Mutex sync = new Mutex();
564 >        final Mutex sync = new Mutex();
565          final AbstractQueuedLongSynchronizer.ConditionObject c = sync.newCondition();
566          try {
567              sync.acquire(1);
# Line 577 | Line 577 | public class AbstractQueuedLongSynchroni
577       * awaitUntil without a signal times out
578       */
579      public void testAwaitUntil_Timeout() {
580 <        final Mutex sync = new Mutex();
580 >        final Mutex sync = new Mutex();
581          final AbstractQueuedLongSynchronizer.ConditionObject c = sync.newCondition();
582          try {
583              sync.acquire(1);
# Line 594 | Line 594 | public class AbstractQueuedLongSynchroni
594       * await returns when signalled
595       */
596      public void testAwait() {
597 <        final Mutex sync = new Mutex();
597 >        final Mutex sync = new Mutex();
598          final AbstractQueuedLongSynchronizer.ConditionObject c = sync.newCondition();
599 <        Thread t = new Thread(new Runnable() {
599 >        Thread t = new Thread(new Runnable() {
600                  public void run() {
601                      try {
602                          sync.acquire(1);
603                          c.await();
604                          sync.release(1);
605                      }
606 <                    catch(InterruptedException e) {
607 <                        threadUnexpectedException();
606 >                    catch (InterruptedException e) {
607 >                        threadUnexpectedException(e);
608                      }
609                  }
610              });
# Line 674 | Line 674 | public class AbstractQueuedLongSynchroni
674       */
675      public void testHasWaitersIAE() {
676          final Mutex sync = new Mutex();
677 <        final AbstractQueuedLongSynchronizer.ConditionObject c = (sync.newCondition());
677 >        final AbstractQueuedLongSynchronizer.ConditionObject c = sync.newCondition();
678          final Mutex sync2 = new Mutex();
679          try {
680              sync2.hasWaiters(c);
# Line 690 | Line 690 | public class AbstractQueuedLongSynchroni
690       */
691      public void testHasWaitersIMSE() {
692          final Mutex sync = new Mutex();
693 <        final AbstractQueuedLongSynchronizer.ConditionObject c = (sync.newCondition());
693 >        final AbstractQueuedLongSynchronizer.ConditionObject c = sync.newCondition();
694          try {
695              sync.hasWaiters(c);
696              shouldThrow();
# Line 706 | Line 706 | public class AbstractQueuedLongSynchroni
706       */
707      public void testGetWaitQueueLengthIAE() {
708          final Mutex sync = new Mutex();
709 <        final AbstractQueuedLongSynchronizer.ConditionObject c = (sync.newCondition());
709 >        final AbstractQueuedLongSynchronizer.ConditionObject c = sync.newCondition();
710          final Mutex sync2 = new Mutex();
711          try {
712              sync2.getWaitQueueLength(c);
# Line 722 | Line 722 | public class AbstractQueuedLongSynchroni
722       */
723      public void testGetWaitQueueLengthIMSE() {
724          final Mutex sync = new Mutex();
725 <        final AbstractQueuedLongSynchronizer.ConditionObject c = (sync.newCondition());
725 >        final AbstractQueuedLongSynchronizer.ConditionObject c = sync.newCondition();
726          try {
727              sync.getWaitQueueLength(c);
728              shouldThrow();
# Line 737 | Line 737 | public class AbstractQueuedLongSynchroni
737       * getWaitingThreads throws IAE if not owned
738       */
739      public void testGetWaitingThreadsIAE() {
740 <        final Mutex sync = new Mutex();
741 <        final AbstractQueuedLongSynchronizer.ConditionObject c = (sync.newCondition());
742 <        final Mutex sync2 = new Mutex();        
740 >        final Mutex sync = new Mutex();
741 >        final AbstractQueuedLongSynchronizer.ConditionObject c = sync.newCondition();
742 >        final Mutex sync2 = new Mutex();
743          try {
744              sync2.getWaitingThreads(c);
745              shouldThrow();
# Line 753 | Line 753 | public class AbstractQueuedLongSynchroni
753       * getWaitingThreads throws IMSE if not synced
754       */
755      public void testGetWaitingThreadsIMSE() {
756 <        final Mutex sync = new Mutex();
757 <        final AbstractQueuedLongSynchronizer.ConditionObject c = (sync.newCondition());
756 >        final Mutex sync = new Mutex();
757 >        final AbstractQueuedLongSynchronizer.ConditionObject c = sync.newCondition();
758          try {
759              sync.getWaitingThreads(c);
760              shouldThrow();
# Line 770 | Line 770 | public class AbstractQueuedLongSynchroni
770       * hasWaiters returns true when a thread is waiting, else false
771       */
772      public void testHasWaiters() {
773 <        final Mutex sync = new Mutex();
773 >        final Mutex sync = new Mutex();
774          final AbstractQueuedLongSynchronizer.ConditionObject c = sync.newCondition();
775 <        Thread t = new Thread(new Runnable() {
775 >        Thread t = new Thread(new Runnable() {
776                  public void run() {
777                      try {
778                          sync.acquire(1);
# Line 781 | Line 781 | public class AbstractQueuedLongSynchroni
781                          c.await();
782                          sync.release(1);
783                      }
784 <                    catch(InterruptedException e) {
785 <                        threadUnexpectedException();
784 >                    catch (InterruptedException e) {
785 >                        threadUnexpectedException(e);
786                      }
787                  }
788              });
# Line 812 | Line 812 | public class AbstractQueuedLongSynchroni
812       * getWaitQueueLength returns number of waiting threads
813       */
814      public void testGetWaitQueueLength() {
815 <        final Mutex sync = new Mutex();
815 >        final Mutex sync = new Mutex();
816          final AbstractQueuedLongSynchronizer.ConditionObject c = sync.newCondition();
817 <        Thread t1 = new Thread(new Runnable() {
817 >        Thread t1 = new Thread(new Runnable() {
818                  public void run() {
819                      try {
820                          sync.acquire(1);
# Line 823 | Line 823 | public class AbstractQueuedLongSynchroni
823                          c.await();
824                          sync.release(1);
825                      }
826 <                    catch(InterruptedException e) {
827 <                        threadUnexpectedException();
826 >                    catch (InterruptedException e) {
827 >                        threadUnexpectedException(e);
828                      }
829                  }
830              });
831  
832 <        Thread t2 = new Thread(new Runnable() {
832 >        Thread t2 = new Thread(new Runnable() {
833                  public void run() {
834                      try {
835                          sync.acquire(1);
# Line 838 | Line 838 | public class AbstractQueuedLongSynchroni
838                          c.await();
839                          sync.release(1);
840                      }
841 <                    catch(InterruptedException e) {
842 <                        threadUnexpectedException();
841 >                    catch (InterruptedException e) {
842 >                        threadUnexpectedException(e);
843                      }
844                  }
845              });
# Line 873 | Line 873 | public class AbstractQueuedLongSynchroni
873       * getWaitingThreads returns only and all waiting threads
874       */
875      public void testGetWaitingThreads() {
876 <        final Mutex sync = new Mutex();
876 >        final Mutex sync = new Mutex();
877          final AbstractQueuedLongSynchronizer.ConditionObject c = sync.newCondition();
878 <        Thread t1 = new Thread(new Runnable() {
878 >        Thread t1 = new Thread(new Runnable() {
879                  public void run() {
880                      try {
881                          sync.acquire(1);
# Line 883 | Line 883 | public class AbstractQueuedLongSynchroni
883                          c.await();
884                          sync.release(1);
885                      }
886 <                    catch(InterruptedException e) {
887 <                        threadUnexpectedException();
886 >                    catch (InterruptedException e) {
887 >                        threadUnexpectedException(e);
888                      }
889                  }
890              });
891  
892 <        Thread t2 = new Thread(new Runnable() {
892 >        Thread t2 = new Thread(new Runnable() {
893                  public void run() {
894                      try {
895                          sync.acquire(1);
# Line 897 | Line 897 | public class AbstractQueuedLongSynchroni
897                          c.await();
898                          sync.release(1);
899                      }
900 <                    catch(InterruptedException e) {
901 <                        threadUnexpectedException();
900 >                    catch (InterruptedException e) {
901 >                        threadUnexpectedException(e);
902                      }
903                  }
904              });
# Line 938 | Line 938 | public class AbstractQueuedLongSynchroni
938       * awaitUninterruptibly doesn't abort on interrupt
939       */
940      public void testAwaitUninterruptibly() {
941 <        final Mutex sync = new Mutex();
941 >        final Mutex sync = new Mutex();
942          final AbstractQueuedLongSynchronizer.ConditionObject c = sync.newCondition();
943 <        Thread t = new Thread(new Runnable() {
943 >        Thread t = new Thread(new Runnable() {
944                  public void run() {
945                      sync.acquire(1);
946                      c.awaitUninterruptibly();
# Line 967 | Line 967 | public class AbstractQueuedLongSynchroni
967       * await is interruptible
968       */
969      public void testAwait_Interrupt() {
970 <        final Mutex sync = new Mutex();
970 >        final Mutex sync = new Mutex();
971          final AbstractQueuedLongSynchronizer.ConditionObject c = sync.newCondition();
972 <        Thread t = new Thread(new Runnable() {
972 >        Thread t = new Thread(new Runnable() {
973                  public void run() {
974                      try {
975                          sync.acquire(1);
# Line 977 | Line 977 | public class AbstractQueuedLongSynchroni
977                          sync.release(1);
978                          threadShouldThrow();
979                      }
980 <                    catch(InterruptedException success) {
980 >                    catch (InterruptedException success) {
981                      }
982                  }
983              });
# Line 998 | Line 998 | public class AbstractQueuedLongSynchroni
998       * awaitNanos is interruptible
999       */
1000      public void testAwaitNanos_Interrupt() {
1001 <        final Mutex sync = new Mutex();
1001 >        final Mutex sync = new Mutex();
1002          final AbstractQueuedLongSynchronizer.ConditionObject c = sync.newCondition();
1003 <        Thread t = new Thread(new Runnable() {
1003 >        Thread t = new Thread(new Runnable() {
1004                  public void run() {
1005                      try {
1006                          sync.acquire(1);
# Line 1008 | Line 1008 | public class AbstractQueuedLongSynchroni
1008                          sync.release(1);
1009                          threadShouldThrow();
1010                      }
1011 <                    catch(InterruptedException success) {
1011 >                    catch (InterruptedException success) {
1012                      }
1013                  }
1014              });
# Line 1029 | Line 1029 | public class AbstractQueuedLongSynchroni
1029       * awaitUntil is interruptible
1030       */
1031      public void testAwaitUntil_Interrupt() {
1032 <        final Mutex sync = new Mutex();
1032 >        final Mutex sync = new Mutex();
1033          final AbstractQueuedLongSynchronizer.ConditionObject c = sync.newCondition();
1034 <        Thread t = new Thread(new Runnable() {
1034 >        Thread t = new Thread(new Runnable() {
1035                  public void run() {
1036                      try {
1037                          sync.acquire(1);
# Line 1040 | Line 1040 | public class AbstractQueuedLongSynchroni
1040                          sync.release(1);
1041                          threadShouldThrow();
1042                      }
1043 <                    catch(InterruptedException success) {
1043 >                    catch (InterruptedException success) {
1044                      }
1045                  }
1046              });
# Line 1061 | Line 1061 | public class AbstractQueuedLongSynchroni
1061       * signalAll wakes up all threads
1062       */
1063      public void testSignalAll() {
1064 <        final Mutex sync = new Mutex();
1064 >        final Mutex sync = new Mutex();
1065          final AbstractQueuedLongSynchronizer.ConditionObject c = sync.newCondition();
1066 <        Thread t1 = new Thread(new Runnable() {
1066 >        Thread t1 = new Thread(new Runnable() {
1067                  public void run() {
1068                      try {
1069                          sync.acquire(1);
1070                          c.await();
1071                          sync.release(1);
1072                      }
1073 <                    catch(InterruptedException e) {
1073 >                    catch (InterruptedException e) {
1074                          threadUnexpectedException();
1075                      }
1076                  }
1077              });
1078  
1079 <        Thread t2 = new Thread(new Runnable() {
1079 >        Thread t2 = new Thread(new Runnable() {
1080                  public void run() {
1081                      try {
1082                          sync.acquire(1);
1083                          c.await();
1084                          sync.release(1);
1085                      }
1086 <                    catch(InterruptedException e) {
1086 >                    catch (InterruptedException e) {
1087                          threadUnexpectedException();
1088                      }
1089                  }
# Line 1137 | Line 1137 | public class AbstractQueuedLongSynchroni
1137              ObjectInputStream in = new ObjectInputStream(new BufferedInputStream(bin));
1138              Mutex r = (Mutex) in.readObject();
1139              assertTrue(r.isHeldExclusively());
1140 <        } catch(Exception e){
1140 >        } catch (Exception e) {
1141              e.printStackTrace();
1142              unexpectedException();
1143          }
# Line 1178 | Line 1178 | public class AbstractQueuedLongSynchroni
1178                          threadAssertFalse(l.isSignalled());
1179                          l.acquireSharedInterruptibly(0);
1180                          threadAssertTrue(l.isSignalled());
1181 <                    } catch(InterruptedException e){
1181 >                    } catch (InterruptedException e) {
1182                          threadUnexpectedException();
1183                      }
1184                  }
# Line 1190 | Line 1190 | public class AbstractQueuedLongSynchroni
1190              l.releaseShared(0);
1191              assertTrue(l.isSignalled());
1192              t.join();
1193 <        } catch (InterruptedException e){
1193 >        } catch (InterruptedException e) {
1194              unexpectedException();
1195          }
1196      }
1197 <    
1197 >
1198  
1199      /**
1200       * acquireSharedTimed returns after release
# Line 1209 | Line 1209 | public class AbstractQueuedLongSynchroni
1209                          threadAssertTrue(l.tryAcquireSharedNanos(0, MEDIUM_DELAY_MS* 1000 * 1000));
1210                          threadAssertTrue(l.isSignalled());
1211  
1212 <                    } catch(InterruptedException e){
1212 >                    } catch (InterruptedException e) {
1213                          threadUnexpectedException();
1214                      }
1215                  }
# Line 1221 | Line 1221 | public class AbstractQueuedLongSynchroni
1221              l.releaseShared(0);
1222              assertTrue(l.isSignalled());
1223              t.join();
1224 <        } catch (InterruptedException e){
1224 >        } catch (InterruptedException e) {
1225              unexpectedException();
1226          }
1227      }
1228 <    
1228 >
1229      /**
1230       * acquireSharedInterruptibly throws IE if interrupted before released
1231       */
# Line 1237 | Line 1237 | public class AbstractQueuedLongSynchroni
1237                          threadAssertFalse(l.isSignalled());
1238                          l.acquireSharedInterruptibly(0);
1239                          threadShouldThrow();
1240 <                    } catch(InterruptedException success){}
1240 >                    } catch (InterruptedException success) {}
1241                  }
1242              });
1243          t.start();
# Line 1245 | Line 1245 | public class AbstractQueuedLongSynchroni
1245              assertFalse(l.isSignalled());
1246              t.interrupt();
1247              t.join();
1248 <        } catch (InterruptedException e){
1248 >        } catch (InterruptedException e) {
1249              unexpectedException();
1250          }
1251      }
# Line 1260 | Line 1260 | public class AbstractQueuedLongSynchroni
1260                      try {
1261                          threadAssertFalse(l.isSignalled());
1262                          l.tryAcquireSharedNanos(0, SMALL_DELAY_MS* 1000 * 1000);
1263 <                        threadShouldThrow();                        
1264 <                    } catch(InterruptedException success){}
1263 >                        threadShouldThrow();
1264 >                    } catch (InterruptedException success) {}
1265                  }
1266              });
1267          t.start();
# Line 1270 | Line 1270 | public class AbstractQueuedLongSynchroni
1270              assertFalse(l.isSignalled());
1271              t.interrupt();
1272              t.join();
1273 <        } catch (InterruptedException e){
1273 >        } catch (InterruptedException e) {
1274              unexpectedException();
1275          }
1276      }
# Line 1285 | Line 1285 | public class AbstractQueuedLongSynchroni
1285                      try {
1286                          threadAssertFalse(l.isSignalled());
1287                          threadAssertFalse(l.tryAcquireSharedNanos(0, SMALL_DELAY_MS* 1000 * 1000));
1288 <                    } catch(InterruptedException ie){
1288 >                    } catch (InterruptedException ie) {
1289                          threadUnexpectedException();
1290                      }
1291                  }
# Line 1295 | Line 1295 | public class AbstractQueuedLongSynchroni
1295              Thread.sleep(SHORT_DELAY_MS);
1296              assertFalse(l.isSignalled());
1297              t.join();
1298 <        } catch (InterruptedException e){
1298 >        } catch (InterruptedException e) {
1299              unexpectedException();
1300          }
1301      }
1302  
1303 <    
1303 >
1304   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines