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.19 by dl, Tue May 3 16:02:00 2005 UTC vs.
Revision 1.26 by jsr166, Wed Nov 18 08:22:57 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() throws InterruptedException {
129          final Mutex sync = new Mutex();
130          Thread t1 = new Thread(new InterruptedSyncRunnable(sync));
131          Thread t2 = new Thread(new InterruptibleSyncRunnable(sync));
132 <        try {
133 <            assertFalse(sync.hasQueuedThreads());
134 <            sync.acquire(1);
135 <            t1.start();
136 <            Thread.sleep(SHORT_DELAY_MS);
137 <            assertTrue(sync.hasQueuedThreads());
138 <            t2.start();
139 <            Thread.sleep(SHORT_DELAY_MS);
140 <            assertTrue(sync.hasQueuedThreads());
141 <            t1.interrupt();
142 <            Thread.sleep(SHORT_DELAY_MS);
143 <            assertTrue(sync.hasQueuedThreads());
144 <            sync.release(1);
145 <            Thread.sleep(SHORT_DELAY_MS);
146 <            assertFalse(sync.hasQueuedThreads());
147 <            t1.join();
148 <            t2.join();
149 <        } catch(Exception e){
150 <            unexpectedException();
151 <        }
152 <    }
132 >        assertFalse(sync.hasQueuedThreads());
133 >        sync.acquire(1);
134 >        t1.start();
135 >        Thread.sleep(SHORT_DELAY_MS);
136 >        assertTrue(sync.hasQueuedThreads());
137 >        t2.start();
138 >        Thread.sleep(SHORT_DELAY_MS);
139 >        assertTrue(sync.hasQueuedThreads());
140 >        t1.interrupt();
141 >        Thread.sleep(SHORT_DELAY_MS);
142 >        assertTrue(sync.hasQueuedThreads());
143 >        sync.release(1);
144 >        Thread.sleep(SHORT_DELAY_MS);
145 >        assertFalse(sync.hasQueuedThreads());
146 >        t1.join();
147 >        t2.join();
148 >    }
149  
150      /**
151       * isQueued(null) throws NPE
152       */
153 <    public void testIsQueuedNPE() {
153 >    public void testIsQueuedNPE() {
154          final Mutex sync = new Mutex();
155          try {
156              sync.isQueued(null);
157              shouldThrow();
158 <        } catch (NullPointerException success) {
163 <        }
158 >        } catch (NullPointerException success) {}
159      }
160  
161      /**
162       * isQueued reports whether a thread is queued.
163       */
164 <    public void testIsQueued() {
164 >    public void testIsQueued() throws InterruptedException {
165          final Mutex sync = new Mutex();
166          Thread t1 = new Thread(new InterruptedSyncRunnable(sync));
167          Thread t2 = new Thread(new InterruptibleSyncRunnable(sync));
168 <        try {
169 <            assertFalse(sync.isQueued(t1));
170 <            assertFalse(sync.isQueued(t2));
171 <            sync.acquire(1);
172 <            t1.start();
173 <            Thread.sleep(SHORT_DELAY_MS);
174 <            assertTrue(sync.isQueued(t1));
175 <            t2.start();
176 <            Thread.sleep(SHORT_DELAY_MS);
177 <            assertTrue(sync.isQueued(t1));
178 <            assertTrue(sync.isQueued(t2));
179 <            t1.interrupt();
180 <            Thread.sleep(SHORT_DELAY_MS);
181 <            assertFalse(sync.isQueued(t1));
182 <            assertTrue(sync.isQueued(t2));
183 <            sync.release(1);
184 <            Thread.sleep(SHORT_DELAY_MS);
185 <            assertFalse(sync.isQueued(t1));
186 <            Thread.sleep(SHORT_DELAY_MS);
187 <            assertFalse(sync.isQueued(t2));
188 <            t1.join();
189 <            t2.join();
195 <        } catch(Exception e){
196 <            unexpectedException();
197 <        }
198 <    }
168 >        assertFalse(sync.isQueued(t1));
169 >        assertFalse(sync.isQueued(t2));
170 >        sync.acquire(1);
171 >        t1.start();
172 >        Thread.sleep(SHORT_DELAY_MS);
173 >        assertTrue(sync.isQueued(t1));
174 >        t2.start();
175 >        Thread.sleep(SHORT_DELAY_MS);
176 >        assertTrue(sync.isQueued(t1));
177 >        assertTrue(sync.isQueued(t2));
178 >        t1.interrupt();
179 >        Thread.sleep(SHORT_DELAY_MS);
180 >        assertFalse(sync.isQueued(t1));
181 >        assertTrue(sync.isQueued(t2));
182 >        sync.release(1);
183 >        Thread.sleep(SHORT_DELAY_MS);
184 >        assertFalse(sync.isQueued(t1));
185 >        Thread.sleep(SHORT_DELAY_MS);
186 >        assertFalse(sync.isQueued(t2));
187 >        t1.join();
188 >        t2.join();
189 >    }
190  
191      /**
192       * getFirstQueuedThread returns first waiting thread or null if none
193       */
194 <    public void testGetFirstQueuedThread() {
194 >    public void testGetFirstQueuedThread() throws InterruptedException {
195          final Mutex sync = new Mutex();
196          Thread t1 = new Thread(new InterruptedSyncRunnable(sync));
197          Thread t2 = new Thread(new InterruptibleSyncRunnable(sync));
198 <        try {
199 <            assertNull(sync.getFirstQueuedThread());
200 <            sync.acquire(1);
201 <            t1.start();
202 <            Thread.sleep(SHORT_DELAY_MS);
203 <            assertEquals(t1, sync.getFirstQueuedThread());
204 <            t2.start();
205 <            Thread.sleep(SHORT_DELAY_MS);
206 <            assertEquals(t1, sync.getFirstQueuedThread());
207 <            t1.interrupt();
208 <            Thread.sleep(SHORT_DELAY_MS);
209 <            Thread.sleep(SHORT_DELAY_MS);
210 <            assertEquals(t2, sync.getFirstQueuedThread());
211 <            sync.release(1);
212 <            Thread.sleep(SHORT_DELAY_MS);
213 <            assertNull(sync.getFirstQueuedThread());
214 <            t1.join();
215 <            t2.join();
225 <        } catch(Exception e){
226 <            unexpectedException();
227 <        }
228 <    }
198 >        assertNull(sync.getFirstQueuedThread());
199 >        sync.acquire(1);
200 >        t1.start();
201 >        Thread.sleep(SHORT_DELAY_MS);
202 >        assertEquals(t1, sync.getFirstQueuedThread());
203 >        t2.start();
204 >        Thread.sleep(SHORT_DELAY_MS);
205 >        assertEquals(t1, sync.getFirstQueuedThread());
206 >        t1.interrupt();
207 >        Thread.sleep(SHORT_DELAY_MS);
208 >        Thread.sleep(SHORT_DELAY_MS);
209 >        assertEquals(t2, sync.getFirstQueuedThread());
210 >        sync.release(1);
211 >        Thread.sleep(SHORT_DELAY_MS);
212 >        assertNull(sync.getFirstQueuedThread());
213 >        t1.join();
214 >        t2.join();
215 >    }
216  
217  
218      /**
219       * hasContended reports false if no thread has ever blocked, else true
220       */
221 <    public void testHasContended() {
221 >    public void testHasContended() throws InterruptedException {
222          final Mutex sync = new Mutex();
223          Thread t1 = new Thread(new InterruptedSyncRunnable(sync));
224          Thread t2 = new Thread(new InterruptibleSyncRunnable(sync));
225 <        try {
226 <            assertFalse(sync.hasContended());
227 <            sync.acquire(1);
228 <            t1.start();
229 <            Thread.sleep(SHORT_DELAY_MS);
230 <            assertTrue(sync.hasContended());
231 <            t2.start();
232 <            Thread.sleep(SHORT_DELAY_MS);
233 <            assertTrue(sync.hasContended());
234 <            t1.interrupt();
235 <            Thread.sleep(SHORT_DELAY_MS);
236 <            assertTrue(sync.hasContended());
237 <            sync.release(1);
238 <            Thread.sleep(SHORT_DELAY_MS);
239 <            assertTrue(sync.hasContended());
240 <            t1.join();
241 <            t2.join();
255 <        } catch(Exception e){
256 <            unexpectedException();
257 <        }
258 <    }
225 >        assertFalse(sync.hasContended());
226 >        sync.acquire(1);
227 >        t1.start();
228 >        Thread.sleep(SHORT_DELAY_MS);
229 >        assertTrue(sync.hasContended());
230 >        t2.start();
231 >        Thread.sleep(SHORT_DELAY_MS);
232 >        assertTrue(sync.hasContended());
233 >        t1.interrupt();
234 >        Thread.sleep(SHORT_DELAY_MS);
235 >        assertTrue(sync.hasContended());
236 >        sync.release(1);
237 >        Thread.sleep(SHORT_DELAY_MS);
238 >        assertTrue(sync.hasContended());
239 >        t1.join();
240 >        t2.join();
241 >    }
242  
243      /**
244       * getQueuedThreads includes waiting threads
245       */
246 <    public void testGetQueuedThreads() {
246 >    public void testGetQueuedThreads() throws InterruptedException {
247          final Mutex sync = new Mutex();
248          Thread t1 = new Thread(new InterruptedSyncRunnable(sync));
249          Thread t2 = new Thread(new InterruptibleSyncRunnable(sync));
250 <        try {
251 <            assertTrue(sync.getQueuedThreads().isEmpty());
252 <            sync.acquire(1);
253 <            assertTrue(sync.getQueuedThreads().isEmpty());
254 <            t1.start();
255 <            Thread.sleep(SHORT_DELAY_MS);
256 <            assertTrue(sync.getQueuedThreads().contains(t1));
257 <            t2.start();
258 <            Thread.sleep(SHORT_DELAY_MS);
259 <            assertTrue(sync.getQueuedThreads().contains(t1));
260 <            assertTrue(sync.getQueuedThreads().contains(t2));
261 <            t1.interrupt();
262 <            Thread.sleep(SHORT_DELAY_MS);
263 <            assertFalse(sync.getQueuedThreads().contains(t1));
264 <            assertTrue(sync.getQueuedThreads().contains(t2));
265 <            sync.release(1);
266 <            Thread.sleep(SHORT_DELAY_MS);
267 <            assertTrue(sync.getQueuedThreads().isEmpty());
268 <            t1.join();
269 <            t2.join();
287 <        } catch(Exception e){
288 <            unexpectedException();
289 <        }
290 <    }
250 >        assertTrue(sync.getQueuedThreads().isEmpty());
251 >        sync.acquire(1);
252 >        assertTrue(sync.getQueuedThreads().isEmpty());
253 >        t1.start();
254 >        Thread.sleep(SHORT_DELAY_MS);
255 >        assertTrue(sync.getQueuedThreads().contains(t1));
256 >        t2.start();
257 >        Thread.sleep(SHORT_DELAY_MS);
258 >        assertTrue(sync.getQueuedThreads().contains(t1));
259 >        assertTrue(sync.getQueuedThreads().contains(t2));
260 >        t1.interrupt();
261 >        Thread.sleep(SHORT_DELAY_MS);
262 >        assertFalse(sync.getQueuedThreads().contains(t1));
263 >        assertTrue(sync.getQueuedThreads().contains(t2));
264 >        sync.release(1);
265 >        Thread.sleep(SHORT_DELAY_MS);
266 >        assertTrue(sync.getQueuedThreads().isEmpty());
267 >        t1.join();
268 >        t2.join();
269 >    }
270  
271      /**
272       * getExclusiveQueuedThreads includes waiting threads
273       */
274 <    public void testGetExclusiveQueuedThreads() {
274 >    public void testGetExclusiveQueuedThreads() throws InterruptedException {
275          final Mutex sync = new Mutex();
276          Thread t1 = new Thread(new InterruptedSyncRunnable(sync));
277          Thread t2 = new Thread(new InterruptibleSyncRunnable(sync));
278 <        try {
279 <            assertTrue(sync.getExclusiveQueuedThreads().isEmpty());
280 <            sync.acquire(1);
281 <            assertTrue(sync.getExclusiveQueuedThreads().isEmpty());
282 <            t1.start();
283 <            Thread.sleep(SHORT_DELAY_MS);
284 <            assertTrue(sync.getExclusiveQueuedThreads().contains(t1));
285 <            t2.start();
286 <            Thread.sleep(SHORT_DELAY_MS);
287 <            assertTrue(sync.getExclusiveQueuedThreads().contains(t1));
288 <            assertTrue(sync.getExclusiveQueuedThreads().contains(t2));
289 <            t1.interrupt();
290 <            Thread.sleep(SHORT_DELAY_MS);
291 <            assertFalse(sync.getExclusiveQueuedThreads().contains(t1));
292 <            assertTrue(sync.getExclusiveQueuedThreads().contains(t2));
293 <            sync.release(1);
294 <            Thread.sleep(SHORT_DELAY_MS);
295 <            assertTrue(sync.getExclusiveQueuedThreads().isEmpty());
296 <            t1.join();
297 <            t2.join();
319 <        } catch(Exception e){
320 <            unexpectedException();
321 <        }
322 <    }
278 >        assertTrue(sync.getExclusiveQueuedThreads().isEmpty());
279 >        sync.acquire(1);
280 >        assertTrue(sync.getExclusiveQueuedThreads().isEmpty());
281 >        t1.start();
282 >        Thread.sleep(SHORT_DELAY_MS);
283 >        assertTrue(sync.getExclusiveQueuedThreads().contains(t1));
284 >        t2.start();
285 >        Thread.sleep(SHORT_DELAY_MS);
286 >        assertTrue(sync.getExclusiveQueuedThreads().contains(t1));
287 >        assertTrue(sync.getExclusiveQueuedThreads().contains(t2));
288 >        t1.interrupt();
289 >        Thread.sleep(SHORT_DELAY_MS);
290 >        assertFalse(sync.getExclusiveQueuedThreads().contains(t1));
291 >        assertTrue(sync.getExclusiveQueuedThreads().contains(t2));
292 >        sync.release(1);
293 >        Thread.sleep(SHORT_DELAY_MS);
294 >        assertTrue(sync.getExclusiveQueuedThreads().isEmpty());
295 >        t1.join();
296 >        t2.join();
297 >    }
298  
299      /**
300       * getSharedQueuedThreads does not include exclusively waiting threads
301       */
302 <    public void testGetSharedQueuedThreads() {
302 >    public void testGetSharedQueuedThreads() throws InterruptedException {
303          final Mutex sync = new Mutex();
304          Thread t1 = new Thread(new InterruptedSyncRunnable(sync));
305          Thread t2 = new Thread(new InterruptibleSyncRunnable(sync));
306 <        try {
307 <            assertTrue(sync.getSharedQueuedThreads().isEmpty());
308 <            sync.acquire(1);
309 <            assertTrue(sync.getSharedQueuedThreads().isEmpty());
310 <            t1.start();
311 <            Thread.sleep(SHORT_DELAY_MS);
312 <            assertTrue(sync.getSharedQueuedThreads().isEmpty());
313 <            t2.start();
314 <            Thread.sleep(SHORT_DELAY_MS);
315 <            assertTrue(sync.getSharedQueuedThreads().isEmpty());
316 <            t1.interrupt();
317 <            Thread.sleep(SHORT_DELAY_MS);
318 <            assertTrue(sync.getSharedQueuedThreads().isEmpty());
319 <            sync.release(1);
320 <            Thread.sleep(SHORT_DELAY_MS);
321 <            assertTrue(sync.getSharedQueuedThreads().isEmpty());
322 <            t1.join();
323 <            t2.join();
349 <        } catch(Exception e){
350 <            unexpectedException();
351 <        }
352 <    }
306 >        assertTrue(sync.getSharedQueuedThreads().isEmpty());
307 >        sync.acquire(1);
308 >        assertTrue(sync.getSharedQueuedThreads().isEmpty());
309 >        t1.start();
310 >        Thread.sleep(SHORT_DELAY_MS);
311 >        assertTrue(sync.getSharedQueuedThreads().isEmpty());
312 >        t2.start();
313 >        Thread.sleep(SHORT_DELAY_MS);
314 >        assertTrue(sync.getSharedQueuedThreads().isEmpty());
315 >        t1.interrupt();
316 >        Thread.sleep(SHORT_DELAY_MS);
317 >        assertTrue(sync.getSharedQueuedThreads().isEmpty());
318 >        sync.release(1);
319 >        Thread.sleep(SHORT_DELAY_MS);
320 >        assertTrue(sync.getSharedQueuedThreads().isEmpty());
321 >        t1.join();
322 >        t2.join();
323 >    }
324  
325      /**
326       * tryAcquireNanos is interruptible.
327       */
328 <    public void testInterruptedException2() {
328 >    public void testInterruptedException2() {
329          final Mutex sync = new Mutex();
330          sync.acquire(1);
331          Thread t = new Thread(new Runnable() {
# Line 362 | Line 333 | public class AbstractQueuedSynchronizerT
333                      try {
334                          sync.tryAcquireNanos(1, MEDIUM_DELAY_MS * 1000 * 1000);
335                          threadShouldThrow();
336 <                    } catch(InterruptedException success){}
336 >                    } catch (InterruptedException success) {}
337                  }
338              });
339 <        try {
340 <            t.start();
341 <            t.interrupt();
371 <        } catch(Exception e){
372 <            unexpectedException();
373 <        }
339 >
340 >        t.start();
341 >        t.interrupt();
342      }
343  
344  
345      /**
346       * TryAcquire on exclusively held sync fails
347       */
348 <    public void testTryAcquireWhenSynced() {
348 >    public void testTryAcquireWhenSynced() throws InterruptedException {
349          final Mutex sync = new Mutex();
350          sync.acquire(1);
351          Thread t = new Thread(new Runnable() {
# Line 385 | Line 353 | public class AbstractQueuedSynchronizerT
353                      threadAssertFalse(sync.tryAcquire(1));
354                  }
355              });
356 <        try {
357 <            t.start();
358 <            t.join();
359 <            sync.release(1);
360 <        } catch(Exception e){
393 <            unexpectedException();
394 <        }
395 <    }
356 >
357 >        t.start();
358 >        t.join();
359 >        sync.release(1);
360 >    }
361  
362      /**
363       * tryAcquireNanos on an exclusively held sync times out
364       */
365 <    public void testAcquireNanos_Timeout() {
365 >    public void testAcquireNanos_Timeout() throws InterruptedException {
366          final Mutex sync = new Mutex();
367          sync.acquire(1);
368          Thread t = new Thread(new Runnable() {
# Line 409 | Line 374 | public class AbstractQueuedSynchronizerT
374                      }
375                  }
376              });
377 <        try {
378 <            t.start();
379 <            t.join();
380 <            sync.release(1);
381 <        } catch(Exception e){
382 <            unexpectedException();
383 <        }
419 <    }
420 <    
421 <  
377 >
378 >        t.start();
379 >        t.join();
380 >        sync.release(1);
381 >    }
382 >
383 >
384      /**
385       * getState is true when acquired and false when not
386       */
387 <    public void testGetState() {
387 >    public void testGetState() throws InterruptedException {
388          final Mutex sync = new Mutex();
389          sync.acquire(1);
390          assertTrue(sync.isHeldExclusively());
391          sync.release(1);
392          assertFalse(sync.isHeldExclusively());
393 <        Thread t = new Thread(new Runnable() {
393 >        Thread t = new Thread(new Runnable() {
394                  public void run() {
395                      sync.acquire(1);
396                      try {
397                          Thread.sleep(SMALL_DELAY_MS);
398                      }
399 <                    catch(Exception e) {
399 >                    catch (Exception e) {
400                          threadUnexpectedException();
401                      }
402                      sync.release(1);
403                  }
404              });
405 <        try {
406 <            t.start();
407 <            Thread.sleep(SHORT_DELAY_MS);
408 <            assertTrue(sync.isHeldExclusively());
409 <            t.join();
410 <            assertFalse(sync.isHeldExclusively());
449 <        } catch(Exception e){
450 <            unexpectedException();
451 <        }
405 >
406 >        t.start();
407 >        Thread.sleep(SHORT_DELAY_MS);
408 >        assertTrue(sync.isHeldExclusively());
409 >        t.join();
410 >        assertFalse(sync.isHeldExclusively());
411      }
412  
413  
414      /**
415       * acquireInterruptibly is interruptible.
416       */
417 <    public void testAcquireInterruptibly1() {
417 >    public void testAcquireInterruptibly1() throws InterruptedException {
418          final Mutex sync = new Mutex();
419          sync.acquire(1);
420          Thread t = new Thread(new InterruptedSyncRunnable(sync));
421 <        try {
422 <            t.start();
423 <            t.interrupt();
424 <            sync.release(1);
425 <            t.join();
426 <        } catch(Exception e){
427 <            unexpectedException();
428 <        }
470 <    }
421 >
422 >        t.start();
423 >        Thread.sleep(SHORT_DELAY_MS);
424 >        t.interrupt();
425 >        Thread.sleep(SHORT_DELAY_MS);
426 >        sync.release(1);
427 >        t.join();
428 >    }
429  
430      /**
431       * acquireInterruptibly succeeds when released, else is interruptible
432       */
433 <    public void testAcquireInterruptibly2() {
434 <        final Mutex sync = new Mutex();
435 <        try {
478 <            sync.acquireInterruptibly(1);
479 <        } catch(Exception e) {
480 <            unexpectedException();
481 <        }
433 >    public void testAcquireInterruptibly2() throws InterruptedException {
434 >        final Mutex sync = new Mutex();
435 >        sync.acquireInterruptibly(1);
436          Thread t = new Thread(new InterruptedSyncRunnable(sync));
437 <        try {
438 <            t.start();
439 <            t.interrupt();
440 <            assertTrue(sync.isHeldExclusively());
487 <            t.join();
488 <        } catch(Exception e){
489 <            unexpectedException();
490 <        }
437 >        t.start();
438 >        t.interrupt();
439 >        assertTrue(sync.isHeldExclusively());
440 >        t.join();
441      }
442  
443      /**
444       * owns is true for a condition created by sync else false
445       */
446      public void testOwns() {
447 <        final Mutex sync = new Mutex();
447 >        final Mutex sync = new Mutex();
448          final AbstractQueuedSynchronizer.ConditionObject c = sync.newCondition();
449          final Mutex sync2 = new Mutex();
450          assertTrue(sync.owns(c));
# Line 504 | Line 454 | public class AbstractQueuedSynchronizerT
454      /**
455       * Calling await without holding sync throws IllegalMonitorStateException
456       */
457 <    public void testAwait_IllegalMonitor() {
458 <        final Mutex sync = new Mutex();
457 >    public void testAwait_IllegalMonitor() throws InterruptedException {
458 >        final Mutex sync = new Mutex();
459          final AbstractQueuedSynchronizer.ConditionObject c = sync.newCondition();
460          try {
461              c.await();
462              shouldThrow();
463          }
464 <        catch (IllegalMonitorStateException success) {
515 <        }
516 <        catch (Exception ex) {
517 <            unexpectedException();
518 <        }
464 >        catch (IllegalMonitorStateException success) {}
465      }
466  
467      /**
468       * Calling signal without holding sync throws IllegalMonitorStateException
469       */
470      public void testSignal_IllegalMonitor() {
471 <        final Mutex sync = new Mutex();
471 >        final Mutex sync = new Mutex();
472          final AbstractQueuedSynchronizer.ConditionObject c = sync.newCondition();
473          try {
474              c.signal();
475              shouldThrow();
476          }
477 <        catch (IllegalMonitorStateException success) {
532 <        }
533 <        catch (Exception ex) {
534 <            unexpectedException();
535 <        }
477 >        catch (IllegalMonitorStateException success) {}
478      }
479  
480      /**
481       * awaitNanos without a signal times out
482       */
483 <    public void testAwaitNanos_Timeout() {
484 <        final Mutex sync = new Mutex();
483 >    public void testAwaitNanos_Timeout() throws InterruptedException {
484 >        final Mutex sync = new Mutex();
485          final AbstractQueuedSynchronizer.ConditionObject c = sync.newCondition();
486 <        try {
487 <            sync.acquire(1);
488 <            long t = c.awaitNanos(100);
489 <            assertTrue(t <= 0);
548 <            sync.release(1);
549 <        }
550 <        catch (Exception ex) {
551 <            unexpectedException();
552 <        }
486 >        sync.acquire(1);
487 >        long t = c.awaitNanos(100);
488 >        assertTrue(t <= 0);
489 >        sync.release(1);
490      }
491  
492      /**
493       *  Timed await without a signal times out
494       */
495 <    public void testAwait_Timeout() {
496 <        final Mutex sync = new Mutex();
495 >    public void testAwait_Timeout() throws InterruptedException {
496 >        final Mutex sync = new Mutex();
497          final AbstractQueuedSynchronizer.ConditionObject c = sync.newCondition();
498 <        try {
499 <            sync.acquire(1);
500 <            assertFalse(c.await(SHORT_DELAY_MS, TimeUnit.MILLISECONDS));
564 <            sync.release(1);
565 <        }
566 <        catch (Exception ex) {
567 <            unexpectedException();
568 <        }
498 >        sync.acquire(1);
499 >        assertFalse(c.await(SHORT_DELAY_MS, TimeUnit.MILLISECONDS));
500 >        sync.release(1);
501      }
502  
503      /**
504       * awaitUntil without a signal times out
505       */
506 <    public void testAwaitUntil_Timeout() {
507 <        final Mutex sync = new Mutex();
506 >    public void testAwaitUntil_Timeout() throws InterruptedException {
507 >        final Mutex sync = new Mutex();
508          final AbstractQueuedSynchronizer.ConditionObject c = sync.newCondition();
509 <        try {
510 <            sync.acquire(1);
511 <            java.util.Date d = new java.util.Date();
512 <            assertFalse(c.awaitUntil(new java.util.Date(d.getTime() + 10)));
581 <            sync.release(1);
582 <        }
583 <        catch (Exception ex) {
584 <            unexpectedException();
585 <        }
509 >        sync.acquire(1);
510 >        java.util.Date d = new java.util.Date();
511 >        assertFalse(c.awaitUntil(new java.util.Date(d.getTime() + 10)));
512 >        sync.release(1);
513      }
514  
515      /**
516       * await returns when signalled
517       */
518 <    public void testAwait() {
519 <        final Mutex sync = new Mutex();
518 >    public void testAwait() throws InterruptedException {
519 >        final Mutex sync = new Mutex();
520          final AbstractQueuedSynchronizer.ConditionObject c = sync.newCondition();
521 <        Thread t = new Thread(new Runnable() {
521 >        Thread t = new Thread(new Runnable() {
522                  public void run() {
523                      try {
524                          sync.acquire(1);
525                          c.await();
526                          sync.release(1);
527                      }
528 <                    catch(InterruptedException e) {
528 >                    catch (InterruptedException e) {
529                          threadUnexpectedException();
530                      }
531                  }
532              });
533  
534 <        try {
535 <            t.start();
536 <            Thread.sleep(SHORT_DELAY_MS);
537 <            sync.acquire(1);
538 <            c.signal();
539 <            sync.release(1);
540 <            t.join(SHORT_DELAY_MS);
614 <            assertFalse(t.isAlive());
615 <        }
616 <        catch (Exception ex) {
617 <            unexpectedException();
618 <        }
534 >        t.start();
535 >        Thread.sleep(SHORT_DELAY_MS);
536 >        sync.acquire(1);
537 >        c.signal();
538 >        sync.release(1);
539 >        t.join(SHORT_DELAY_MS);
540 >        assertFalse(t.isAlive());
541      }
542  
543  
# Line 628 | Line 550 | public class AbstractQueuedSynchronizerT
550          try {
551              sync.hasWaiters(null);
552              shouldThrow();
553 <        } catch (NullPointerException success) {
632 <        } catch (Exception ex) {
633 <            unexpectedException();
634 <        }
553 >        } catch (NullPointerException success) {}
554      }
555  
556      /**
# Line 642 | Line 561 | public class AbstractQueuedSynchronizerT
561          try {
562              sync.getWaitQueueLength(null);
563              shouldThrow();
564 <        } catch (NullPointerException success) {
646 <        } catch (Exception ex) {
647 <            unexpectedException();
648 <        }
564 >        } catch (NullPointerException success) {}
565      }
566  
567  
# Line 657 | Line 573 | public class AbstractQueuedSynchronizerT
573          try {
574              sync.getWaitingThreads(null);
575              shouldThrow();
576 <        } catch (NullPointerException success) {
661 <        } catch (Exception ex) {
662 <            unexpectedException();
663 <        }
576 >        } catch (NullPointerException success) {}
577      }
578  
579  
# Line 669 | Line 582 | public class AbstractQueuedSynchronizerT
582       */
583      public void testHasWaitersIAE() {
584          final Mutex sync = new Mutex();
585 <        final AbstractQueuedSynchronizer.ConditionObject c = (sync.newCondition());
585 >        final AbstractQueuedSynchronizer.ConditionObject c = sync.newCondition();
586          final Mutex sync2 = new Mutex();
587          try {
588              sync2.hasWaiters(c);
589              shouldThrow();
590 <        } catch (IllegalArgumentException success) {
678 <        } catch (Exception ex) {
679 <            unexpectedException();
680 <        }
590 >        } catch (IllegalArgumentException success) {}
591      }
592  
593      /**
# Line 685 | Line 595 | public class AbstractQueuedSynchronizerT
595       */
596      public void testHasWaitersIMSE() {
597          final Mutex sync = new Mutex();
598 <        final AbstractQueuedSynchronizer.ConditionObject c = (sync.newCondition());
598 >        final AbstractQueuedSynchronizer.ConditionObject c = sync.newCondition();
599          try {
600              sync.hasWaiters(c);
601              shouldThrow();
602 <        } catch (IllegalMonitorStateException success) {
693 <        } catch (Exception ex) {
694 <            unexpectedException();
695 <        }
602 >        } catch (IllegalMonitorStateException success) {}
603      }
604  
605  
# Line 701 | Line 608 | public class AbstractQueuedSynchronizerT
608       */
609      public void testGetWaitQueueLengthIAE() {
610          final Mutex sync = new Mutex();
611 <        final AbstractQueuedSynchronizer.ConditionObject c = (sync.newCondition());
611 >        final AbstractQueuedSynchronizer.ConditionObject c = sync.newCondition();
612          final Mutex sync2 = new Mutex();
613          try {
614              sync2.getWaitQueueLength(c);
615              shouldThrow();
616 <        } catch (IllegalArgumentException success) {
710 <        } catch (Exception ex) {
711 <            unexpectedException();
712 <        }
616 >        } catch (IllegalArgumentException success) {}
617      }
618  
619      /**
# Line 717 | Line 621 | public class AbstractQueuedSynchronizerT
621       */
622      public void testGetWaitQueueLengthIMSE() {
623          final Mutex sync = new Mutex();
624 <        final AbstractQueuedSynchronizer.ConditionObject c = (sync.newCondition());
624 >        final AbstractQueuedSynchronizer.ConditionObject c = sync.newCondition();
625          try {
626              sync.getWaitQueueLength(c);
627              shouldThrow();
628 <        } catch (IllegalMonitorStateException success) {
725 <        } catch (Exception ex) {
726 <            unexpectedException();
727 <        }
628 >        } catch (IllegalMonitorStateException success) {}
629      }
630  
631  
# Line 732 | Line 633 | public class AbstractQueuedSynchronizerT
633       * getWaitingThreads throws IAE if not owned
634       */
635      public void testGetWaitingThreadsIAE() {
636 <        final Mutex sync = new Mutex();
637 <        final AbstractQueuedSynchronizer.ConditionObject c = (sync.newCondition());
638 <        final Mutex sync2 = new Mutex();        
636 >        final Mutex sync = new Mutex();
637 >        final AbstractQueuedSynchronizer.ConditionObject c = sync.newCondition();
638 >        final Mutex sync2 = new Mutex();
639          try {
640              sync2.getWaitingThreads(c);
641              shouldThrow();
642 <        } catch (IllegalArgumentException success) {
742 <        } catch (Exception ex) {
743 <            unexpectedException();
744 <        }
642 >        } catch (IllegalArgumentException success) {}
643      }
644  
645      /**
646       * getWaitingThreads throws IMSE if not synced
647       */
648      public void testGetWaitingThreadsIMSE() {
649 <        final Mutex sync = new Mutex();
650 <        final AbstractQueuedSynchronizer.ConditionObject c = (sync.newCondition());
649 >        final Mutex sync = new Mutex();
650 >        final AbstractQueuedSynchronizer.ConditionObject c = sync.newCondition();
651          try {
652              sync.getWaitingThreads(c);
653              shouldThrow();
654 <        } catch (IllegalMonitorStateException success) {
757 <        } catch (Exception ex) {
758 <            unexpectedException();
759 <        }
654 >        } catch (IllegalMonitorStateException success) {}
655      }
656  
657  
# Line 764 | Line 659 | public class AbstractQueuedSynchronizerT
659      /**
660       * hasWaiters returns true when a thread is waiting, else false
661       */
662 <    public void testHasWaiters() {
663 <        final Mutex sync = new Mutex();
662 >    public void testHasWaiters() throws InterruptedException {
663 >        final Mutex sync = new Mutex();
664          final AbstractQueuedSynchronizer.ConditionObject c = sync.newCondition();
665 <        Thread t = new Thread(new Runnable() {
665 >        Thread t = new Thread(new Runnable() {
666                  public void run() {
667                      try {
668                          sync.acquire(1);
# Line 776 | Line 671 | public class AbstractQueuedSynchronizerT
671                          c.await();
672                          sync.release(1);
673                      }
674 <                    catch(InterruptedException e) {
674 >                    catch (InterruptedException e) {
675                          threadUnexpectedException();
676                      }
677                  }
678              });
679  
680 <        try {
681 <            t.start();
682 <            Thread.sleep(SHORT_DELAY_MS);
683 <            sync.acquire(1);
684 <            assertTrue(sync.hasWaiters(c));
685 <            assertEquals(1, sync.getWaitQueueLength(c));
686 <            c.signal();
687 <            sync.release(1);
688 <            Thread.sleep(SHORT_DELAY_MS);
689 <            sync.acquire(1);
690 <            assertFalse(sync.hasWaiters(c));
691 <            assertEquals(0, sync.getWaitQueueLength(c));
692 <            sync.release(1);
693 <            t.join(SHORT_DELAY_MS);
799 <            assertFalse(t.isAlive());
800 <        }
801 <        catch (Exception ex) {
802 <            unexpectedException();
803 <        }
680 >        t.start();
681 >        Thread.sleep(SHORT_DELAY_MS);
682 >        sync.acquire(1);
683 >        assertTrue(sync.hasWaiters(c));
684 >        assertEquals(1, sync.getWaitQueueLength(c));
685 >        c.signal();
686 >        sync.release(1);
687 >        Thread.sleep(SHORT_DELAY_MS);
688 >        sync.acquire(1);
689 >        assertFalse(sync.hasWaiters(c));
690 >        assertEquals(0, sync.getWaitQueueLength(c));
691 >        sync.release(1);
692 >        t.join(SHORT_DELAY_MS);
693 >        assertFalse(t.isAlive());
694      }
695  
696      /**
697       * getWaitQueueLength returns number of waiting threads
698       */
699 <    public void testGetWaitQueueLength() {
700 <        final Mutex sync = new Mutex();
699 >    public void testGetWaitQueueLength() throws InterruptedException {
700 >        final Mutex sync = new Mutex();
701          final AbstractQueuedSynchronizer.ConditionObject c = sync.newCondition();
702 <        Thread t1 = new Thread(new Runnable() {
702 >        Thread t1 = new Thread(new Runnable() {
703                  public void run() {
704                      try {
705                          sync.acquire(1);
# Line 818 | Line 708 | public class AbstractQueuedSynchronizerT
708                          c.await();
709                          sync.release(1);
710                      }
711 <                    catch(InterruptedException e) {
711 >                    catch (InterruptedException e) {
712                          threadUnexpectedException();
713                      }
714                  }
715              });
716  
717 <        Thread t2 = new Thread(new Runnable() {
717 >        Thread t2 = new Thread(new Runnable() {
718                  public void run() {
719                      try {
720                          sync.acquire(1);
# Line 833 | Line 723 | public class AbstractQueuedSynchronizerT
723                          c.await();
724                          sync.release(1);
725                      }
726 <                    catch(InterruptedException e) {
726 >                    catch (InterruptedException e) {
727                          threadUnexpectedException();
728                      }
729                  }
730              });
731  
732 <        try {
733 <            t1.start();
734 <            Thread.sleep(SHORT_DELAY_MS);
735 <            t2.start();
736 <            Thread.sleep(SHORT_DELAY_MS);
737 <            sync.acquire(1);
738 <            assertTrue(sync.hasWaiters(c));
739 <            assertEquals(2, sync.getWaitQueueLength(c));
740 <            c.signalAll();
741 <            sync.release(1);
742 <            Thread.sleep(SHORT_DELAY_MS);
743 <            sync.acquire(1);
744 <            assertFalse(sync.hasWaiters(c));
745 <            assertEquals(0, sync.getWaitQueueLength(c));
746 <            sync.release(1);
747 <            t1.join(SHORT_DELAY_MS);
748 <            t2.join(SHORT_DELAY_MS);
749 <            assertFalse(t1.isAlive());
860 <            assertFalse(t2.isAlive());
861 <        }
862 <        catch (Exception ex) {
863 <            unexpectedException();
864 <        }
732 >        t1.start();
733 >        Thread.sleep(SHORT_DELAY_MS);
734 >        t2.start();
735 >        Thread.sleep(SHORT_DELAY_MS);
736 >        sync.acquire(1);
737 >        assertTrue(sync.hasWaiters(c));
738 >        assertEquals(2, sync.getWaitQueueLength(c));
739 >        c.signalAll();
740 >        sync.release(1);
741 >        Thread.sleep(SHORT_DELAY_MS);
742 >        sync.acquire(1);
743 >        assertFalse(sync.hasWaiters(c));
744 >        assertEquals(0, sync.getWaitQueueLength(c));
745 >        sync.release(1);
746 >        t1.join(SHORT_DELAY_MS);
747 >        t2.join(SHORT_DELAY_MS);
748 >        assertFalse(t1.isAlive());
749 >        assertFalse(t2.isAlive());
750      }
751  
752      /**
753       * getWaitingThreads returns only and all waiting threads
754       */
755 <    public void testGetWaitingThreads() {
756 <        final Mutex sync = new Mutex();
755 >    public void testGetWaitingThreads() throws InterruptedException {
756 >        final Mutex sync = new Mutex();
757          final AbstractQueuedSynchronizer.ConditionObject c = sync.newCondition();
758 <        Thread t1 = new Thread(new Runnable() {
758 >        Thread t1 = new Thread(new Runnable() {
759                  public void run() {
760                      try {
761                          sync.acquire(1);
# Line 878 | Line 763 | public class AbstractQueuedSynchronizerT
763                          c.await();
764                          sync.release(1);
765                      }
766 <                    catch(InterruptedException e) {
766 >                    catch (InterruptedException e) {
767                          threadUnexpectedException();
768                      }
769                  }
770              });
771  
772 <        Thread t2 = new Thread(new Runnable() {
772 >        Thread t2 = new Thread(new Runnable() {
773                  public void run() {
774                      try {
775                          sync.acquire(1);
# Line 892 | Line 777 | public class AbstractQueuedSynchronizerT
777                          c.await();
778                          sync.release(1);
779                      }
780 <                    catch(InterruptedException e) {
780 >                    catch (InterruptedException e) {
781                          threadUnexpectedException();
782                      }
783                  }
784              });
785  
786 <        try {
787 <            sync.acquire(1);
788 <            assertTrue(sync.getWaitingThreads(c).isEmpty());
789 <            sync.release(1);
790 <            t1.start();
791 <            Thread.sleep(SHORT_DELAY_MS);
792 <            t2.start();
793 <            Thread.sleep(SHORT_DELAY_MS);
794 <            sync.acquire(1);
795 <            assertTrue(sync.hasWaiters(c));
796 <            assertTrue(sync.getWaitingThreads(c).contains(t1));
797 <            assertTrue(sync.getWaitingThreads(c).contains(t2));
798 <            c.signalAll();
799 <            sync.release(1);
800 <            Thread.sleep(SHORT_DELAY_MS);
801 <            sync.acquire(1);
802 <            assertFalse(sync.hasWaiters(c));
803 <            assertTrue(sync.getWaitingThreads(c).isEmpty());
804 <            sync.release(1);
805 <            t1.join(SHORT_DELAY_MS);
806 <            t2.join(SHORT_DELAY_MS);
807 <            assertFalse(t1.isAlive());
923 <            assertFalse(t2.isAlive());
924 <        }
925 <        catch (Exception ex) {
926 <            unexpectedException();
927 <        }
786 >        sync.acquire(1);
787 >        assertTrue(sync.getWaitingThreads(c).isEmpty());
788 >        sync.release(1);
789 >        t1.start();
790 >        Thread.sleep(SHORT_DELAY_MS);
791 >        t2.start();
792 >        Thread.sleep(SHORT_DELAY_MS);
793 >        sync.acquire(1);
794 >        assertTrue(sync.hasWaiters(c));
795 >        assertTrue(sync.getWaitingThreads(c).contains(t1));
796 >        assertTrue(sync.getWaitingThreads(c).contains(t2));
797 >        c.signalAll();
798 >        sync.release(1);
799 >        Thread.sleep(SHORT_DELAY_MS);
800 >        sync.acquire(1);
801 >        assertFalse(sync.hasWaiters(c));
802 >        assertTrue(sync.getWaitingThreads(c).isEmpty());
803 >        sync.release(1);
804 >        t1.join(SHORT_DELAY_MS);
805 >        t2.join(SHORT_DELAY_MS);
806 >        assertFalse(t1.isAlive());
807 >        assertFalse(t2.isAlive());
808      }
809  
810  
# Line 932 | Line 812 | public class AbstractQueuedSynchronizerT
812      /**
813       * awaitUninterruptibly doesn't abort on interrupt
814       */
815 <    public void testAwaitUninterruptibly() {
816 <        final Mutex sync = new Mutex();
815 >    public void testAwaitUninterruptibly() throws InterruptedException {
816 >        final Mutex sync = new Mutex();
817          final AbstractQueuedSynchronizer.ConditionObject c = sync.newCondition();
818 <        Thread t = new Thread(new Runnable() {
818 >        Thread t = new Thread(new Runnable() {
819                  public void run() {
820                      sync.acquire(1);
821                      c.awaitUninterruptibly();
# Line 943 | Line 823 | public class AbstractQueuedSynchronizerT
823                  }
824              });
825  
826 <        try {
827 <            t.start();
828 <            Thread.sleep(SHORT_DELAY_MS);
829 <            t.interrupt();
830 <            sync.acquire(1);
831 <            c.signal();
832 <            sync.release(1);
833 <            t.join(SHORT_DELAY_MS);
954 <            assertFalse(t.isAlive());
955 <        }
956 <        catch (Exception ex) {
957 <            unexpectedException();
958 <        }
826 >        t.start();
827 >        Thread.sleep(SHORT_DELAY_MS);
828 >        t.interrupt();
829 >        sync.acquire(1);
830 >        c.signal();
831 >        sync.release(1);
832 >        t.join(SHORT_DELAY_MS);
833 >        assertFalse(t.isAlive());
834      }
835  
836      /**
837       * await is interruptible
838       */
839 <    public void testAwait_Interrupt() {
840 <        final Mutex sync = new Mutex();
839 >    public void testAwait_Interrupt() throws InterruptedException {
840 >        final Mutex sync = new Mutex();
841          final AbstractQueuedSynchronizer.ConditionObject c = sync.newCondition();
842 <        Thread t = new Thread(new Runnable() {
842 >        Thread t = new Thread(new Runnable() {
843                  public void run() {
844                      try {
845                          sync.acquire(1);
# Line 972 | Line 847 | public class AbstractQueuedSynchronizerT
847                          sync.release(1);
848                          threadShouldThrow();
849                      }
850 <                    catch(InterruptedException success) {
850 >                    catch (InterruptedException success) {
851                      }
852                  }
853              });
854  
855 <        try {
856 <            t.start();
857 <            Thread.sleep(SHORT_DELAY_MS);
858 <            t.interrupt();
859 <            t.join(SHORT_DELAY_MS);
985 <            assertFalse(t.isAlive());
986 <        }
987 <        catch (Exception ex) {
988 <            unexpectedException();
989 <        }
855 >        t.start();
856 >        Thread.sleep(SHORT_DELAY_MS);
857 >        t.interrupt();
858 >        t.join(SHORT_DELAY_MS);
859 >        assertFalse(t.isAlive());
860      }
861  
862      /**
863       * awaitNanos is interruptible
864       */
865 <    public void testAwaitNanos_Interrupt() {
866 <        final Mutex sync = new Mutex();
865 >    public void testAwaitNanos_Interrupt() throws InterruptedException {
866 >        final Mutex sync = new Mutex();
867          final AbstractQueuedSynchronizer.ConditionObject c = sync.newCondition();
868 <        Thread t = new Thread(new Runnable() {
868 >        Thread t = new Thread(new Runnable() {
869                  public void run() {
870                      try {
871                          sync.acquire(1);
# Line 1003 | Line 873 | public class AbstractQueuedSynchronizerT
873                          sync.release(1);
874                          threadShouldThrow();
875                      }
876 <                    catch(InterruptedException success) {
876 >                    catch (InterruptedException success) {
877                      }
878                  }
879              });
880  
881 <        try {
882 <            t.start();
883 <            Thread.sleep(SHORT_DELAY_MS);
884 <            t.interrupt();
885 <            t.join(SHORT_DELAY_MS);
1016 <            assertFalse(t.isAlive());
1017 <        }
1018 <        catch (Exception ex) {
1019 <            unexpectedException();
1020 <        }
881 >        t.start();
882 >        Thread.sleep(SHORT_DELAY_MS);
883 >        t.interrupt();
884 >        t.join(SHORT_DELAY_MS);
885 >        assertFalse(t.isAlive());
886      }
887  
888      /**
889       * awaitUntil is interruptible
890       */
891 <    public void testAwaitUntil_Interrupt() {
892 <        final Mutex sync = new Mutex();
891 >    public void testAwaitUntil_Interrupt() throws InterruptedException {
892 >        final Mutex sync = new Mutex();
893          final AbstractQueuedSynchronizer.ConditionObject c = sync.newCondition();
894 <        Thread t = new Thread(new Runnable() {
894 >        Thread t = new Thread(new Runnable() {
895                  public void run() {
896                      try {
897                          sync.acquire(1);
# Line 1035 | Line 900 | public class AbstractQueuedSynchronizerT
900                          sync.release(1);
901                          threadShouldThrow();
902                      }
903 <                    catch(InterruptedException success) {
903 >                    catch (InterruptedException success) {
904                      }
905                  }
906              });
907  
908 <        try {
909 <            t.start();
910 <            Thread.sleep(SHORT_DELAY_MS);
911 <            t.interrupt();
912 <            t.join(SHORT_DELAY_MS);
1048 <            assertFalse(t.isAlive());
1049 <        }
1050 <        catch (Exception ex) {
1051 <            unexpectedException();
1052 <        }
908 >        t.start();
909 >        Thread.sleep(SHORT_DELAY_MS);
910 >        t.interrupt();
911 >        t.join(SHORT_DELAY_MS);
912 >        assertFalse(t.isAlive());
913      }
914  
915      /**
916       * signalAll wakes up all threads
917       */
918 <    public void testSignalAll() {
919 <        final Mutex sync = new Mutex();
918 >    public void testSignalAll() throws InterruptedException {
919 >        final Mutex sync = new Mutex();
920          final AbstractQueuedSynchronizer.ConditionObject c = sync.newCondition();
921 <        Thread t1 = new Thread(new Runnable() {
921 >        Thread t1 = new Thread(new Runnable() {
922                  public void run() {
923                      try {
924                          sync.acquire(1);
925                          c.await();
926                          sync.release(1);
927                      }
928 <                    catch(InterruptedException e) {
928 >                    catch (InterruptedException e) {
929                          threadUnexpectedException();
930                      }
931                  }
932              });
933  
934 <        Thread t2 = new Thread(new Runnable() {
934 >        Thread t2 = new Thread(new Runnable() {
935                  public void run() {
936                      try {
937                          sync.acquire(1);
938                          c.await();
939                          sync.release(1);
940                      }
941 <                    catch(InterruptedException e) {
941 >                    catch (InterruptedException e) {
942                          threadUnexpectedException();
943                      }
944                  }
945              });
946  
947 <        try {
948 <            t1.start();
949 <            t2.start();
950 <            Thread.sleep(SHORT_DELAY_MS);
951 <            sync.acquire(1);
952 <            c.signalAll();
953 <            sync.release(1);
954 <            t1.join(SHORT_DELAY_MS);
955 <            t2.join(SHORT_DELAY_MS);
956 <            assertFalse(t1.isAlive());
1097 <            assertFalse(t2.isAlive());
1098 <        }
1099 <        catch (Exception ex) {
1100 <            unexpectedException();
1101 <        }
947 >        t1.start();
948 >        t2.start();
949 >        Thread.sleep(SHORT_DELAY_MS);
950 >        sync.acquire(1);
951 >        c.signalAll();
952 >        sync.release(1);
953 >        t1.join(SHORT_DELAY_MS);
954 >        t2.join(SHORT_DELAY_MS);
955 >        assertFalse(t1.isAlive());
956 >        assertFalse(t2.isAlive());
957      }
958  
959  
# Line 1117 | Line 972 | public class AbstractQueuedSynchronizerT
972      /**
973       * A serialized AQS deserializes with current state
974       */
975 <    public void testSerialization() {
975 >    public void testSerialization() throws Exception {
976          Mutex l = new Mutex();
977          l.acquire(1);
978          assertTrue(l.isHeldExclusively());
979  
980 <        try {
981 <            ByteArrayOutputStream bout = new ByteArrayOutputStream(10000);
982 <            ObjectOutputStream out = new ObjectOutputStream(new BufferedOutputStream(bout));
983 <            out.writeObject(l);
984 <            out.close();
985 <
986 <            ByteArrayInputStream bin = new ByteArrayInputStream(bout.toByteArray());
987 <            ObjectInputStream in = new ObjectInputStream(new BufferedInputStream(bin));
988 <            Mutex r = (Mutex) in.readObject();
1134 <            assertTrue(r.isHeldExclusively());
1135 <        } catch(Exception e){
1136 <            e.printStackTrace();
1137 <            unexpectedException();
1138 <        }
980 >        ByteArrayOutputStream bout = new ByteArrayOutputStream(10000);
981 >        ObjectOutputStream out = new ObjectOutputStream(new BufferedOutputStream(bout));
982 >        out.writeObject(l);
983 >        out.close();
984 >
985 >        ByteArrayInputStream bin = new ByteArrayInputStream(bout.toByteArray());
986 >        ObjectInputStream in = new ObjectInputStream(new BufferedInputStream(bin));
987 >        Mutex r = (Mutex) in.readObject();
988 >        assertTrue(r.isHeldExclusively());
989      }
990  
991  
# Line 1164 | Line 1014 | public class AbstractQueuedSynchronizerT
1014      /**
1015       * acquireSharedInterruptibly returns after release, but not before
1016       */
1017 <    public void testAcquireSharedInterruptibly() {
1017 >    public void testAcquireSharedInterruptibly() throws InterruptedException {
1018          final BooleanLatch l = new BooleanLatch();
1019  
1020          Thread t = new Thread(new Runnable() {
# Line 1173 | Line 1023 | public class AbstractQueuedSynchronizerT
1023                          threadAssertFalse(l.isSignalled());
1024                          l.acquireSharedInterruptibly(0);
1025                          threadAssertTrue(l.isSignalled());
1026 <                    } catch(InterruptedException e){
1026 >                    } catch (InterruptedException e) {
1027                          threadUnexpectedException();
1028                      }
1029                  }
1030              });
1031 <        try {
1032 <            t.start();
1033 <            assertFalse(l.isSignalled());
1034 <            Thread.sleep(SHORT_DELAY_MS);
1035 <            l.releaseShared(0);
1036 <            assertTrue(l.isSignalled());
1037 <            t.join();
1188 <        } catch (InterruptedException e){
1189 <            unexpectedException();
1190 <        }
1031 >
1032 >        t.start();
1033 >        assertFalse(l.isSignalled());
1034 >        Thread.sleep(SHORT_DELAY_MS);
1035 >        l.releaseShared(0);
1036 >        assertTrue(l.isSignalled());
1037 >        t.join();
1038      }
1039 <    
1039 >
1040  
1041      /**
1042       * acquireSharedTimed returns after release
1043       */
1044 <    public void testAsquireSharedTimed() {
1044 >    public void testAsquireSharedTimed() throws InterruptedException {
1045          final BooleanLatch l = new BooleanLatch();
1046  
1047          Thread t = new Thread(new Runnable() {
# Line 1204 | Line 1051 | public class AbstractQueuedSynchronizerT
1051                          threadAssertTrue(l.tryAcquireSharedNanos(0, MEDIUM_DELAY_MS* 1000 * 1000));
1052                          threadAssertTrue(l.isSignalled());
1053  
1054 <                    } catch(InterruptedException e){
1054 >                    } catch (InterruptedException e) {
1055                          threadUnexpectedException();
1056                      }
1057                  }
1058              });
1059 <        try {
1060 <            t.start();
1061 <            assertFalse(l.isSignalled());
1062 <            Thread.sleep(SHORT_DELAY_MS);
1063 <            l.releaseShared(0);
1064 <            assertTrue(l.isSignalled());
1065 <            t.join();
1219 <        } catch (InterruptedException e){
1220 <            unexpectedException();
1221 <        }
1059 >
1060 >        t.start();
1061 >        assertFalse(l.isSignalled());
1062 >        Thread.sleep(SHORT_DELAY_MS);
1063 >        l.releaseShared(0);
1064 >        assertTrue(l.isSignalled());
1065 >        t.join();
1066      }
1067 <    
1067 >
1068      /**
1069       * acquireSharedInterruptibly throws IE if interrupted before released
1070       */
1071 <    public void testAcquireSharedInterruptibly_InterruptedException() {
1071 >    public void testAcquireSharedInterruptibly_InterruptedException() throws InterruptedException {
1072          final BooleanLatch l = new BooleanLatch();
1073          Thread t = new Thread(new Runnable() {
1074                  public void run() {
# Line 1232 | Line 1076 | public class AbstractQueuedSynchronizerT
1076                          threadAssertFalse(l.isSignalled());
1077                          l.acquireSharedInterruptibly(0);
1078                          threadShouldThrow();
1079 <                    } catch(InterruptedException success){}
1079 >                    } catch (InterruptedException success) {}
1080                  }
1081              });
1082          t.start();
1083 <        try {
1084 <            assertFalse(l.isSignalled());
1085 <            t.interrupt();
1242 <            t.join();
1243 <        } catch (InterruptedException e){
1244 <            unexpectedException();
1245 <        }
1083 >        assertFalse(l.isSignalled());
1084 >        t.interrupt();
1085 >        t.join();
1086      }
1087  
1088      /**
1089       * acquireSharedTimed throws IE if interrupted before released
1090       */
1091 <    public void testAcquireSharedNanos_InterruptedException() {
1091 >    public void testAcquireSharedNanos_InterruptedException() throws InterruptedException {
1092          final BooleanLatch l = new BooleanLatch();
1093          Thread t = new Thread(new Runnable() {
1094                  public void run() {
1095                      try {
1096                          threadAssertFalse(l.isSignalled());
1097                          l.tryAcquireSharedNanos(0, SMALL_DELAY_MS* 1000 * 1000);
1098 <                        threadShouldThrow();                        
1099 <                    } catch(InterruptedException success){}
1098 >                        threadShouldThrow();
1099 >                    } catch (InterruptedException success) {}
1100                  }
1101              });
1102          t.start();
1103 <        try {
1104 <            Thread.sleep(SHORT_DELAY_MS);
1105 <            assertFalse(l.isSignalled());
1106 <            t.interrupt();
1267 <            t.join();
1268 <        } catch (InterruptedException e){
1269 <            unexpectedException();
1270 <        }
1103 >        Thread.sleep(SHORT_DELAY_MS);
1104 >        assertFalse(l.isSignalled());
1105 >        t.interrupt();
1106 >        t.join();
1107      }
1108  
1109      /**
1110       * acquireSharedTimed times out if not released before timeout
1111       */
1112 <    public void testAcquireSharedNanos_Timeout() {
1112 >    public void testAcquireSharedNanos_Timeout() throws InterruptedException {
1113          final BooleanLatch l = new BooleanLatch();
1114          Thread t = new Thread(new Runnable() {
1115                  public void run() {
1116                      try {
1117                          threadAssertFalse(l.isSignalled());
1118                          threadAssertFalse(l.tryAcquireSharedNanos(0, SMALL_DELAY_MS* 1000 * 1000));
1119 <                    } catch(InterruptedException ie){
1119 >                    } catch (InterruptedException ie) {
1120                          threadUnexpectedException();
1121                      }
1122                  }
1123              });
1124          t.start();
1125 <        try {
1126 <            Thread.sleep(SHORT_DELAY_MS);
1127 <            assertFalse(l.isSignalled());
1292 <            t.join();
1293 <        } catch (InterruptedException e){
1294 <            unexpectedException();
1295 <        }
1125 >        Thread.sleep(SHORT_DELAY_MS);
1126 >        assertFalse(l.isSignalled());
1127 >        t.join();
1128      }
1129  
1130 <    
1130 >
1131   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines