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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines