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.32 by jsr166, Fri Oct 29 06:21:16 2010 UTC vs.
Revision 1.40 by jsr166, Thu Nov 18 18:37:55 2010 UTC

# Line 354 | Line 354 | public class LinkedTransferQueueTest ext
354                  for (int i = 0; i < SIZE; ++i) {
355                      long t0 = System.nanoTime();
356                      assertEquals(i, (int) q.poll(LONG_DELAY_MS, MILLISECONDS));
357 <                    assertTrue(millisElapsedSince(t0) < SHORT_DELAY_MS);
357 >                    assertTrue(millisElapsedSince(t0) < SMALL_DELAY_MS);
358                  }
359 +                long t0 = System.nanoTime();
360                  aboutToWait.countDown();
361                  try {
362                      q.poll(MEDIUM_DELAY_MS, MILLISECONDS);
363                      shouldThrow();
364 <                } catch (InterruptedException success) {}
364 >                } catch (InterruptedException success) {
365 >                    assertTrue(millisElapsedSince(t0) < MEDIUM_DELAY_MS);
366 >                }
367              }});
368  
369          aboutToWait.await();
# Line 382 | Line 385 | public class LinkedTransferQueueTest ext
385                  for (int i = 0; i < SIZE; ++i) {
386                      long t0 = System.nanoTime();
387                      assertEquals(i, (int) q.poll(LONG_DELAY_MS, MILLISECONDS));
388 <                    assertTrue(millisElapsedSince(t0) < SHORT_DELAY_MS);
388 >                    assertTrue(millisElapsedSince(t0) < SMALL_DELAY_MS);
389                  }
390                  try {
391                      q.poll(MEDIUM_DELAY_MS, MILLISECONDS);
# Line 547 | Line 550 | public class LinkedTransferQueueTest ext
550      }
551  
552      /**
553 <     * toArray() contains all elements
553 >     * toArray() contains all elements in FIFO order
554       */
555 <    public void testToArray() throws InterruptedException {
555 >    public void testToArray() {
556          LinkedTransferQueue q = populatedQueue(SIZE);
557          Object[] o = q.toArray();
558          for (int i = 0; i < o.length; i++) {
559 <            assertEquals(o[i], q.take());
559 >            assertSame(o[i], q.poll());
560          }
561      }
562  
563      /**
564 <     * toArray(a) contains all elements
564 >     * toArray(a) contains all elements in FIFO order
565       */
566 <    public void testToArray2() throws InterruptedException {
566 >    public void testToArray2() {
567          LinkedTransferQueue<Integer> q = populatedQueue(SIZE);
568          Integer[] ints = new Integer[SIZE];
569 <        ints = q.toArray(ints);
569 >        Integer[] array = q.toArray(ints);
570 >        assertSame(ints, array);
571          for (int i = 0; i < ints.length; i++) {
572 <            assertEquals(ints[i], q.take());
572 >            assertSame(ints[i], q.poll());
573          }
574      }
575  
576      /**
577       * toArray(null) throws NullPointerException
578       */
579 <    public void testToArray_BadArg() {
579 >    public void testToArray_NullArg() {
580          LinkedTransferQueue q = populatedQueue(SIZE);
581          try {
582 <            Object o[] = q.toArray(null);
582 >            q.toArray(null);
583              shouldThrow();
584          } catch (NullPointerException success) {}
585      }
586  
587      /**
588 <     * toArray(incompatible array type) throws CCE
588 >     * toArray(incompatible array type) throws ArrayStoreException
589       */
590      public void testToArray1_BadArg() {
591          LinkedTransferQueue q = populatedQueue(SIZE);
592          try {
593 <            Object o[] = q.toArray(new String[10]);
593 >            q.toArray(new String[10]);
594              shouldThrow();
595          } catch (ArrayStoreException success) {}
596      }
# Line 910 | Line 914 | public class LinkedTransferQueueTest ext
914          Thread t = newStartedThread(new CheckedRunnable() {
915              public void realRun() throws InterruptedException {
916                  threadStarted.countDown();
917 <                q.transfer(SIZE);
917 >                q.transfer(five);
918                  checkEmpty(q);
919              }});
920  
921          threadStarted.await();
922          waitForThreadToEnterWaitState(t, SMALL_DELAY_MS);
919        assertTrue(t.isAlive());
923          assertEquals(1, q.size());
924 <        assertEquals(SIZE, (int) q.poll());
924 >        assertSame(five, q.poll());
925          checkEmpty(q);
926          awaitTermination(t, MEDIUM_DELAY_MS);
927      }
# Line 1069 | Line 1072 | public class LinkedTransferQueueTest ext
1072      }
1073  
1074      /**
1075 <     * tryTransfer waits the amount given if interrupted, and
1076 <     * throws interrupted exception
1075 >     * tryTransfer waits the amount given, and throws
1076 >     * InterruptedException when interrupted.
1077       */
1078      public void testTryTransfer5() throws InterruptedException {
1079          final LinkedTransferQueue q = new LinkedTransferQueue();
1080          final CountDownLatch threadStarted = new CountDownLatch(1);
1081 +        assertTrue(q.isEmpty());
1082  
1083          Thread t = newStartedThread(new CheckedRunnable() {
1084              public void realRun() throws InterruptedException {
# Line 1085 | Line 1089 | public class LinkedTransferQueueTest ext
1089                      shouldThrow();
1090                  } catch (InterruptedException success) {}
1091                  assertTrue(millisElapsedSince(t0) >= SHORT_DELAY_MS);
1092 +                assertTrue(millisElapsedSince(t0) < MEDIUM_DELAY_MS);
1093              }});
1094  
1095          threadStarted.await();
1096 +        while (q.isEmpty())
1097 +            Thread.yield();
1098          Thread.sleep(SHORT_DELAY_MS);
1099          t.interrupt();
1100          awaitTermination(t, MEDIUM_DELAY_MS);
# Line 1095 | Line 1102 | public class LinkedTransferQueueTest ext
1102      }
1103  
1104      /**
1105 <     * tryTransfer gives up after the timeout and return false
1105 >     * tryTransfer gives up after the timeout and returns false
1106       */
1107      public void testTryTransfer6() throws InterruptedException {
1108          final LinkedTransferQueue q = new LinkedTransferQueue();

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines