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.33 by jsr166, Fri Oct 29 06:22:12 2010 UTC vs.
Revision 1.42 by jsr166, Thu Nov 18 20:21:53 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 445 | Line 448 | public class LinkedTransferQueueTest ext
448       */
449      public void testRemoveElement() throws InterruptedException {
450          LinkedTransferQueue q = populatedQueue(SIZE);
451 <        for (int i = 1; i < SIZE; i += 2) {
451 >        for (int i = 1; i < SIZE; i+=2) {
452 >            assertTrue(q.contains(i));
453              assertTrue(q.remove(i));
454 +            assertFalse(q.contains(i));
455 +            assertTrue(q.contains(i-1));
456          }
457 <        for (int i = 0; i < SIZE; i += 2) {
457 >        for (int i = 0; i < SIZE; i+=2) {
458 >            assertTrue(q.contains(i));
459              assertTrue(q.remove(i));
460 <            assertFalse(q.remove(i + 1));
460 >            assertFalse(q.contains(i));
461 >            assertFalse(q.remove(i+1));
462 >            assertFalse(q.contains(i+1));
463          }
464          checkEmpty(q);
465      }
# Line 547 | Line 556 | public class LinkedTransferQueueTest ext
556      }
557  
558      /**
559 <     * toArray() contains all elements
559 >     * toArray() contains all elements in FIFO order
560       */
561 <    public void testToArray() throws InterruptedException {
561 >    public void testToArray() {
562          LinkedTransferQueue q = populatedQueue(SIZE);
563          Object[] o = q.toArray();
564          for (int i = 0; i < o.length; i++) {
565 <            assertEquals(o[i], q.take());
565 >            assertSame(o[i], q.poll());
566          }
567      }
568  
569      /**
570 <     * toArray(a) contains all elements
570 >     * toArray(a) contains all elements in FIFO order
571       */
572 <    public void testToArray2() throws InterruptedException {
572 >    public void testToArray2() {
573          LinkedTransferQueue<Integer> q = populatedQueue(SIZE);
574          Integer[] ints = new Integer[SIZE];
575 <        ints = q.toArray(ints);
575 >        Integer[] array = q.toArray(ints);
576 >        assertSame(ints, array);
577          for (int i = 0; i < ints.length; i++) {
578 <            assertEquals(ints[i], q.take());
578 >            assertSame(ints[i], q.poll());
579          }
580      }
581  
582      /**
583       * toArray(null) throws NullPointerException
584       */
585 <    public void testToArray_BadArg() {
585 >    public void testToArray_NullArg() {
586          LinkedTransferQueue q = populatedQueue(SIZE);
587          try {
588 <            Object o[] = q.toArray(null);
588 >            q.toArray(null);
589              shouldThrow();
590          } catch (NullPointerException success) {}
591      }
592  
593      /**
594 <     * toArray(incompatible array type) throws CCE
594 >     * toArray(incompatible array type) throws ArrayStoreException
595       */
596      public void testToArray1_BadArg() {
597          LinkedTransferQueue q = populatedQueue(SIZE);
598          try {
599 <            Object o[] = q.toArray(new String[10]);
599 >            q.toArray(new String[10]);
600              shouldThrow();
601          } catch (ArrayStoreException success) {}
602      }
# Line 910 | Line 920 | public class LinkedTransferQueueTest ext
920          Thread t = newStartedThread(new CheckedRunnable() {
921              public void realRun() throws InterruptedException {
922                  threadStarted.countDown();
923 <                q.transfer(SIZE);
923 >                q.transfer(five);
924                  checkEmpty(q);
925              }});
926  
927          threadStarted.await();
928          waitForThreadToEnterWaitState(t, SMALL_DELAY_MS);
919        assertTrue(t.isAlive());
929          assertEquals(1, q.size());
930 <        assertEquals(SIZE, (int) q.poll());
930 >        assertSame(five, q.poll());
931          checkEmpty(q);
932          awaitTermination(t, MEDIUM_DELAY_MS);
933      }
# Line 1069 | Line 1078 | public class LinkedTransferQueueTest ext
1078      }
1079  
1080      /**
1081 <     * tryTransfer waits the amount given if interrupted, and
1082 <     * throws interrupted exception
1081 >     * tryTransfer waits the amount given, and throws
1082 >     * InterruptedException when interrupted.
1083       */
1084      public void testTryTransfer5() throws InterruptedException {
1085          final LinkedTransferQueue q = new LinkedTransferQueue();
1086          final CountDownLatch threadStarted = new CountDownLatch(1);
1087 +        assertTrue(q.isEmpty());
1088  
1089          Thread t = newStartedThread(new CheckedRunnable() {
1090              public void realRun() throws InterruptedException {
# Line 1085 | Line 1095 | public class LinkedTransferQueueTest ext
1095                      shouldThrow();
1096                  } catch (InterruptedException success) {}
1097                  assertTrue(millisElapsedSince(t0) >= SHORT_DELAY_MS);
1098 +                assertTrue(millisElapsedSince(t0) < MEDIUM_DELAY_MS);
1099              }});
1100  
1101          threadStarted.await();
1102 +        while (q.isEmpty())
1103 +            Thread.yield();
1104          Thread.sleep(SHORT_DELAY_MS);
1105          t.interrupt();
1106          awaitTermination(t, MEDIUM_DELAY_MS);
# Line 1137 | Line 1150 | public class LinkedTransferQueueTest ext
1150      }
1151  
1152      /**
1153 <     * tryTransfer attempts to enqueue into the q and fails returning
1154 <     * false not enqueueing and the successive poll is null
1153 >     * tryTransfer attempts to enqueue into the queue and fails
1154 >     * returning false not enqueueing and the successive poll is null
1155       */
1156      public void testTryTransfer8() throws InterruptedException {
1157          final LinkedTransferQueue q = new LinkedTransferQueue();

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines