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.44 by jsr166, Thu Apr 14 22:55:08 2011 UTC vs.
Revision 1.46 by jsr166, Sat May 21 06:24:33 2011 UTC

# 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 752 | 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 774 | 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