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

Comparing jsr166/src/test/tck/LinkedTransferQueueTest.java (file contents):
Revision 1.65 by jsr166, Tue Oct 6 00:36:55 2015 UTC vs.
Revision 1.66 by jsr166, Sun Oct 18 04:48:32 2015 UTC

# Line 263 | Line 263 | public class LinkedTransferQueueTest ext
263       */
264      public void testTimedPoll() throws InterruptedException {
265          LinkedTransferQueue<Integer> q = populatedQueue(SIZE);
266        for (int i = 0; i < SIZE; ++i) {
267            long startTime = System.nanoTime();
268            assertEquals(i, (int) q.poll(LONG_DELAY_MS, MILLISECONDS));
269            assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS);
270        }
266          long startTime = System.nanoTime();
267 +        for (int i = 0; i < SIZE; ++i)
268 +            assertEquals(i, (int) q.poll(LONG_DELAY_MS, MILLISECONDS));
269 +        assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS);
270 +
271 +        startTime = System.nanoTime();
272          assertNull(q.poll(timeoutMillis(), MILLISECONDS));
273          assertTrue(millisElapsedSince(startTime) >= timeoutMillis());
274          checkEmpty(q);
# Line 284 | Line 284 | public class LinkedTransferQueueTest ext
284          Thread t = newStartedThread(new CheckedRunnable() {
285              public void realRun() throws InterruptedException {
286                  long startTime = System.nanoTime();
287 <                for (int i = 0; i < SIZE; ++i) {
287 >                for (int i = 0; i < SIZE; ++i)
288                      assertEquals(i, (int) q.poll(LONG_DELAY_MS, MILLISECONDS));
289                }
289                  aboutToWait.countDown();
290                  try {
291                      q.poll(LONG_DELAY_MS, MILLISECONDS);
292                      shouldThrow();
293 <                } catch (InterruptedException success) {
294 <                    assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS);
296 <                }
293 >                } catch (InterruptedException success) {}
294 >                assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS);
295              }});
296  
297          aboutToWait.await();
298 <        waitForThreadToEnterWaitState(t, LONG_DELAY_MS);
298 >        waitForThreadToEnterWaitState(t);
299          t.interrupt();
300          awaitTermination(t);
301          checkEmpty(q);
# Line 311 | Line 309 | public class LinkedTransferQueueTest ext
309          final BlockingQueue<Integer> q = populatedQueue(SIZE);
310          Thread t = newStartedThread(new CheckedRunnable() {
311              public void realRun() throws InterruptedException {
312 +                long startTime = System.nanoTime();
313                  Thread.currentThread().interrupt();
314 <                for (int i = 0; i < SIZE; ++i) {
316 <                    long startTime = System.nanoTime();
314 >                for (int i = 0; i < SIZE; ++i)
315                      assertEquals(i, (int) q.poll(LONG_DELAY_MS, MILLISECONDS));
318                    assertTrue(millisElapsedSince(startTime) < SMALL_DELAY_MS);
319                }
316                  try {
317 <                    q.poll(MEDIUM_DELAY_MS, MILLISECONDS);
317 >                    q.poll(LONG_DELAY_MS, MILLISECONDS);
318                      shouldThrow();
319                  } catch (InterruptedException success) {}
320 +                assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS);
321              }});
322  
323 <        awaitTermination(t, MEDIUM_DELAY_MS);
323 >        awaitTermination(t);
324          checkEmpty(q);
325      }
326  
# Line 600 | Line 597 | public class LinkedTransferQueueTest ext
597              executor.execute(new CheckedRunnable() {
598                  public void realRun() throws InterruptedException {
599                      threadsStarted.await();
600 +                    long startTime = System.nanoTime();
601                      assertTrue(q.offer(one, LONG_DELAY_MS, MILLISECONDS));
602 +                    assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS);
603                  }});
604  
605              executor.execute(new CheckedRunnable() {
# Line 625 | Line 624 | public class LinkedTransferQueueTest ext
624                  public void realRun() throws InterruptedException {
625                      assertNull(q.poll());
626                      threadsStarted.await();
627 +                    long startTime = System.nanoTime();
628                      assertSame(one, q.poll(LONG_DELAY_MS, MILLISECONDS));
629 +                    assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS);
630                      checkEmpty(q);
631                  }});
632  
# Line 695 | Line 696 | public class LinkedTransferQueueTest ext
696          assertTrue(l.size() >= SIZE);
697          for (int i = 0; i < SIZE; ++i)
698              assertEquals(i, l.get(i));
699 <        awaitTermination(t, MEDIUM_DELAY_MS);
699 >        awaitTermination(t);
700          assertTrue(q.size() + l.size() >= SIZE);
701      }
702  
# Line 732 | Line 733 | public class LinkedTransferQueueTest ext
733          Thread t = newStartedThread(new CheckedRunnable() {
734              public void realRun() throws InterruptedException {
735                  threadStarted.countDown();
736 +                long startTime = System.nanoTime();
737                  assertSame(one, q.poll(LONG_DELAY_MS, MILLISECONDS));
738                  assertEquals(0, q.getWaitingConsumerCount());
739                  assertFalse(q.hasWaitingConsumer());
740 +                assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS);
741              }});
742  
743          threadStarted.await();
744 <        waitForThreadToEnterWaitState(t, SMALL_DELAY_MS);
744 >        waitForThreadToEnterWaitState(t);
745          assertEquals(1, q.getWaitingConsumerCount());
746          assertTrue(q.hasWaitingConsumer());
747  
# Line 746 | Line 749 | public class LinkedTransferQueueTest ext
749          assertEquals(0, q.getWaitingConsumerCount());
750          assertFalse(q.hasWaitingConsumer());
751  
752 <        awaitTermination(t, MEDIUM_DELAY_MS);
752 >        awaitTermination(t);
753      }
754  
755      /**
# Line 777 | Line 780 | public class LinkedTransferQueueTest ext
780              }});
781  
782          threadStarted.await();
783 <        waitForThreadToEnterWaitState(t, SMALL_DELAY_MS);
783 >        waitForThreadToEnterWaitState(t);
784          assertEquals(1, q.size());
785          assertSame(five, q.poll());
786          checkEmpty(q);
787 <        awaitTermination(t, MEDIUM_DELAY_MS);
787 >        awaitTermination(t);
788      }
789  
790      /**
# Line 837 | Line 840 | public class LinkedTransferQueueTest ext
840          assertEquals(1, q.size());
841          assertTrue(q.offer(three));
842          assertSame(four, q.poll());
843 <        awaitTermination(t, MEDIUM_DELAY_MS);
843 >        awaitTermination(t);
844      }
845  
846      /**
# Line 860 | Line 863 | public class LinkedTransferQueueTest ext
863          assertEquals(1, q.size());
864          assertSame(four, q.take());
865          checkEmpty(q);
866 <        awaitTermination(t, MEDIUM_DELAY_MS);
866 >        awaitTermination(t);
867      }
868  
869      /**
# Line 902 | Line 905 | public class LinkedTransferQueueTest ext
905                  assertTrue(q.tryTransfer(hotPotato));
906              }});
907  
908 <        assertSame(hotPotato, q.poll(MEDIUM_DELAY_MS, MILLISECONDS));
908 >        long startTime = System.nanoTime();
909 >        assertSame(hotPotato, q.poll(LONG_DELAY_MS, MILLISECONDS));
910 >        assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS);
911          checkEmpty(q);
912 <        awaitTermination(t, MEDIUM_DELAY_MS);
912 >        awaitTermination(t);
913      }
914  
915      /**
# Line 926 | Line 931 | public class LinkedTransferQueueTest ext
931  
932          assertSame(q.take(), hotPotato);
933          checkEmpty(q);
934 <        awaitTermination(t, MEDIUM_DELAY_MS);
934 >        awaitTermination(t);
935      }
936  
937      /**
# Line 939 | Line 944 | public class LinkedTransferQueueTest ext
944  
945          Thread t = newStartedThread(new CheckedRunnable() {
946              public void realRun() throws InterruptedException {
947 +                long startTime = System.nanoTime();
948                  Thread.currentThread().interrupt();
949                  try {
950                      q.tryTransfer(new Object(), LONG_DELAY_MS, MILLISECONDS);
# Line 952 | Line 958 | public class LinkedTransferQueueTest ext
958                      shouldThrow();
959                  } catch (InterruptedException success) {}
960                  assertFalse(Thread.interrupted());
961 +                assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS);
962              }});
963  
964          await(pleaseInterrupt);
# Line 990 | Line 997 | public class LinkedTransferQueueTest ext
997  
998          Thread t = newStartedThread(new CheckedRunnable() {
999              public void realRun() throws InterruptedException {
1000 <                assertTrue(q.tryTransfer(five, MEDIUM_DELAY_MS, MILLISECONDS));
1000 >                long startTime = System.nanoTime();
1001 >                assertTrue(q.tryTransfer(five, LONG_DELAY_MS, MILLISECONDS));
1002 >                assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS);
1003                  checkEmpty(q);
1004              }});
1005  
# Line 1000 | Line 1009 | public class LinkedTransferQueueTest ext
1009          assertSame(four, q.poll());
1010          assertSame(five, q.poll());
1011          checkEmpty(q);
1012 <        awaitTermination(t, MEDIUM_DELAY_MS);
1012 >        awaitTermination(t);
1013      }
1014  
1015      /**

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines