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

Comparing jsr166/src/test/tck/ArrayBlockingQueueTest.java (file contents):
Revision 1.41 by jsr166, Fri Nov 5 00:17:22 2010 UTC vs.
Revision 1.46 by jsr166, Sat May 21 06:24:33 2011 UTC

# Line 1 | Line 1
1   /*
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
4 > * http://creativecommons.org/publicdomain/zero/1.0/
5   * Other contributors include Andrew Wright, Jeffrey Hayes,
6   * Pat Fisher, Mike Judd.
7   */
# Line 294 | Line 294 | public class ArrayBlockingQueueTest exte
294              q.put(null);
295              shouldThrow();
296          } catch (NullPointerException success) {}
297 <     }
297 >    }
298  
299      /**
300       * all elements successfully put are contained
# Line 327 | Line 327 | public class ArrayBlockingQueueTest exte
327              }});
328  
329          t.start();
330 <        Thread.sleep(SHORT_DELAY_MS);
330 >        delay(SHORT_DELAY_MS);
331          t.interrupt();
332          t.join();
333          assertEquals(SIZE, q.size());
# Line 351 | Line 351 | public class ArrayBlockingQueueTest exte
351              }});
352  
353          t.start();
354 <        Thread.sleep(SHORT_DELAY_MS);
354 >        delay(SHORT_DELAY_MS);
355          assertEquals(q.remainingCapacity(), 0);
356          assertEquals(0, q.take());
357 <        Thread.sleep(SHORT_DELAY_MS);
357 >        delay(SHORT_DELAY_MS);
358          t.interrupt();
359          t.join();
360          assertEquals(q.remainingCapacity(), 0);
# Line 365 | Line 365 | public class ArrayBlockingQueueTest exte
365       */
366      public void testTimedOffer() throws InterruptedException {
367          final ArrayBlockingQueue q = new ArrayBlockingQueue(2);
368 <        Thread t = new Thread(new CheckedRunnable() {
368 >        final CountDownLatch pleaseInterrupt = new CountDownLatch(1);
369 >        Thread t = newStartedThread(new CheckedRunnable() {
370              public void realRun() throws InterruptedException {
371                  q.put(new Object());
372                  q.put(new Object());
373 <                assertFalse(q.offer(new Object(), SHORT_DELAY_MS/2, MILLISECONDS));
373 >                long startTime = System.nanoTime();
374 >                assertFalse(q.offer(new Object(), timeoutMillis(), MILLISECONDS));
375 >                assertTrue(millisElapsedSince(startTime) >= timeoutMillis());
376 >                pleaseInterrupt.countDown();
377                  try {
378 <                    q.offer(new Object(), LONG_DELAY_MS, MILLISECONDS);
378 >                    q.offer(new Object(), 2 * LONG_DELAY_MS, MILLISECONDS);
379                      shouldThrow();
380                  } catch (InterruptedException success) {}
381              }});
382  
383 <        t.start();
380 <        Thread.sleep(SHORT_DELAY_MS);
383 >        await(pleaseInterrupt);
384          t.interrupt();
385 <        t.join();
385 >        awaitTermination(t);
386      }
387  
388      /**
# Line 409 | Line 412 | public class ArrayBlockingQueueTest exte
412              }});
413  
414          t.start();
415 <        Thread.sleep(SHORT_DELAY_MS);
415 >        delay(SHORT_DELAY_MS);
416          t.interrupt();
417          t.join();
418      }
# Line 453 | Line 456 | public class ArrayBlockingQueueTest exte
456       * returning timeout status
457       */
458      public void testInterruptedTimedPoll() throws InterruptedException {
459 <        Thread t = new Thread(new CheckedRunnable() {
459 >        final BlockingQueue<Integer> q = populatedQueue(SIZE);
460 >        final CountDownLatch aboutToWait = new CountDownLatch(1);
461 >        Thread t = newStartedThread(new CheckedRunnable() {
462              public void realRun() throws InterruptedException {
458                ArrayBlockingQueue q = populatedQueue(SIZE);
463                  for (int i = 0; i < SIZE; ++i) {
464 <                    assertEquals(i, q.poll(SHORT_DELAY_MS, MILLISECONDS));;
464 >                    long t0 = System.nanoTime();
465 >                    assertEquals(i, (int) q.poll(LONG_DELAY_MS, MILLISECONDS));
466 >                    assertTrue(millisElapsedSince(t0) < SMALL_DELAY_MS);
467                  }
468 +                long t0 = System.nanoTime();
469 +                aboutToWait.countDown();
470                  try {
471 <                    q.poll(SMALL_DELAY_MS, MILLISECONDS);
471 >                    q.poll(MEDIUM_DELAY_MS, MILLISECONDS);
472                      shouldThrow();
473 <                } catch (InterruptedException success) {}
473 >                } catch (InterruptedException success) {
474 >                    assertTrue(millisElapsedSince(t0) < MEDIUM_DELAY_MS);
475 >                }
476              }});
477  
478 <        t.start();
479 <        Thread.sleep(SHORT_DELAY_MS);
478 >        aboutToWait.await();
479 >        waitForThreadToEnterWaitState(t, SMALL_DELAY_MS);
480          t.interrupt();
481 <        t.join();
481 >        awaitTermination(t, MEDIUM_DELAY_MS);
482 >        checkEmpty(q);
483      }
484  
485      /**
# Line 744 | Line 755 | public class ArrayBlockingQueueTest exte
755  
756          executor.execute(new CheckedRunnable() {
757              public void realRun() throws InterruptedException {
758 <                Thread.sleep(SMALL_DELAY_MS);
758 >                delay(SMALL_DELAY_MS);
759                  assertSame(one, q.take());
760              }});
761  
# Line 766 | Line 777 | public class ArrayBlockingQueueTest exte
777  
778          executor.execute(new CheckedRunnable() {
779              public void realRun() throws InterruptedException {
780 <                Thread.sleep(SMALL_DELAY_MS);
780 >                delay(SMALL_DELAY_MS);
781                  q.put(one);
782              }});
783  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines