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

Comparing jsr166/src/test/tck/LinkedBlockingDequeTest.java (file contents):
Revision 1.37 by dl, Fri May 6 11:22:07 2011 UTC vs.
Revision 1.38 by jsr166, Sat May 21 06:24:33 2011 UTC

# Line 655 | Line 655 | public class LinkedBlockingDequeTest ext
655       */
656      public void testTimedOffer() throws InterruptedException {
657          final LinkedBlockingDeque q = new LinkedBlockingDeque(2);
658 <        Thread t = new Thread(new CheckedRunnable() {
658 >        final CountDownLatch pleaseInterrupt = new CountDownLatch(1);
659 >        Thread t = newStartedThread(new CheckedRunnable() {
660              public void realRun() throws InterruptedException {
661                  q.put(new Object());
662                  q.put(new Object());
663 <                assertFalse(q.offer(new Object(), SHORT_DELAY_MS, MILLISECONDS));
663 >                long startTime = System.nanoTime();
664 >                assertFalse(q.offer(new Object(), timeoutMillis(), MILLISECONDS));
665 >                assertTrue(millisElapsedSince(startTime) >= timeoutMillis());
666 >                pleaseInterrupt.countDown();
667                  try {
668 <                    q.offer(new Object(), LONG_DELAY_MS, MILLISECONDS);
668 >                    q.offer(new Object(), 2 * LONG_DELAY_MS, MILLISECONDS);
669                      shouldThrow();
670                  } catch (InterruptedException success) {}
671              }});
672  
673 <        t.start();
670 <        delay(SMALL_DELAY_MS);
673 >        await(pleaseInterrupt);
674          t.interrupt();
675 <        t.join();
675 >        awaitTermination(t);
676      }
677  
678      /**
# Line 849 | Line 852 | public class LinkedBlockingDequeTest ext
852       */
853      public void testTimedOfferFirst() throws InterruptedException {
854          final LinkedBlockingDeque q = new LinkedBlockingDeque(2);
855 <        Thread t = new Thread(new CheckedRunnable() {
855 >        final CountDownLatch pleaseInterrupt = new CountDownLatch(1);
856 >        Thread t = newStartedThread(new CheckedRunnable() {
857              public void realRun() throws InterruptedException {
858                  q.putFirst(new Object());
859                  q.putFirst(new Object());
860 <                assertFalse(q.offerFirst(new Object(), SHORT_DELAY_MS, MILLISECONDS));
860 >                long startTime = System.nanoTime();
861 >                assertFalse(q.offerFirst(new Object(), timeoutMillis(), MILLISECONDS));
862 >                assertTrue(millisElapsedSince(startTime) >= timeoutMillis());
863 >                pleaseInterrupt.countDown();
864                  try {
865 <                    q.offerFirst(new Object(), LONG_DELAY_MS, MILLISECONDS);
865 >                    q.offerFirst(new Object(), 2 * LONG_DELAY_MS, MILLISECONDS);
866                      shouldThrow();
867                  } catch (InterruptedException success) {}
868              }});
869  
870 <        t.start();
864 <        delay(SMALL_DELAY_MS);
870 >        await(pleaseInterrupt);
871          t.interrupt();
872 <        t.join();
872 >        awaitTermination(t);
873      }
874  
875      /**
# Line 1062 | Line 1068 | public class LinkedBlockingDequeTest ext
1068       */
1069      public void testTimedOfferLast() throws InterruptedException {
1070          final LinkedBlockingDeque q = new LinkedBlockingDeque(2);
1071 <        Thread t = new Thread(new CheckedRunnable() {
1071 >        final CountDownLatch pleaseInterrupt = new CountDownLatch(1);
1072 >        Thread t = newStartedThread(new CheckedRunnable() {
1073              public void realRun() throws InterruptedException {
1074                  q.putLast(new Object());
1075                  q.putLast(new Object());
1076 <                assertFalse(q.offerLast(new Object(), SHORT_DELAY_MS, MILLISECONDS));
1076 >                long startTime = System.nanoTime();
1077 >                assertFalse(q.offerLast(new Object(), timeoutMillis(), MILLISECONDS));
1078 >                assertTrue(millisElapsedSince(startTime) >= timeoutMillis());
1079 >                pleaseInterrupt.countDown();
1080                  try {
1081 <                    q.offerLast(new Object(), LONG_DELAY_MS, MILLISECONDS);
1081 >                    q.offerLast(new Object(), 2 * LONG_DELAY_MS, MILLISECONDS);
1082                      shouldThrow();
1083                  } catch (InterruptedException success) {}
1084              }});
1085  
1086 <        t.start();
1077 <        delay(SMALL_DELAY_MS);
1086 >        await(pleaseInterrupt);
1087          t.interrupt();
1088 <        t.join();
1088 >        awaitTermination(t);
1089      }
1090  
1091      /**

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines