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.12 by jsr166, Sat Aug 15 00:35:01 2009 UTC vs.
Revision 1.13 by jsr166, Sat Aug 15 00:48:10 2009 UTC

# Line 545 | Line 545 | public class LinkedTransferQueueTest ext
545      }
546  
547      /**
548 <     * toArray contains all elements
548 >     * toArray() contains all elements
549       */
550      public void testToArray() throws InterruptedException {
551          LinkedTransferQueue q = populatedQueue(SIZE);
# Line 580 | Line 580 | public class LinkedTransferQueueTest ext
580      }
581  
582      /**
583 <     * toArray with incompatible array type throws CCE
583 >     * toArray(incompatible array type) throws CCE
584       */
585      public void testToArray1_BadArg() {
586          try {
# Line 692 | Line 692 | public class LinkedTransferQueueTest ext
692      }
693  
694      /**
695 <     * poll retrieves elements across Executor threads
695 >     * timed poll retrieves elements across Executor threads
696       */
697      public void testPollInExecutor() {
698          final LinkedTransferQueue q = new LinkedTransferQueue();
# Line 790 | Line 790 | public class LinkedTransferQueueTest ext
790      }
791  
792      /**
793 <     * drainTo empties full queue, unblocking a waiting put.
793 >     * drainTo(c) empties full queue, unblocking a waiting put.
794       */
795      public void testDrainToWithActivePut() throws InterruptedException {
796          final LinkedTransferQueue q = populatedQueue(SIZE);
# Line 855 | Line 855 | public class LinkedTransferQueueTest ext
855      }
856  
857      /**
858 <     * poll and take decrement the waiting consumer count
858 >     * timed poll() or take() increments the waiting consumer count;
859 >     * offer(e) decrements the waiting consumer count
860       */
861      public void testWaitingConsumer() throws InterruptedException {
862          final LinkedTransferQueue q = new LinkedTransferQueue();
863 <        final ConsumerObserver waiting = new ConsumerObserver();
863 >        assertEquals(q.getWaitingConsumerCount(), 0);
864 >        assertFalse(q.hasWaitingConsumer());
865  
866          Thread t = newStartedThread(new CheckedRunnable() {
867              void realRun() throws InterruptedException {
868                  Thread.sleep(SMALL_DELAY_MS);
869                  threadAssertTrue(q.hasWaitingConsumer());
870 <                waiting.setWaitingConsumer(q.getWaitingConsumerCount());
870 >                threadAssertEquals(q.getWaitingConsumerCount(), 1);
871                  threadAssertTrue(q.offer(new Object()));
872 +                threadAssertFalse(q.hasWaitingConsumer());
873 +                threadAssertEquals(q.getWaitingConsumerCount(), 0);
874              }});
875  
876          assertTrue(q.poll(LONG_DELAY_MS, MILLISECONDS) != null);
877 <        assertTrue(q.getWaitingConsumerCount()
878 <                   < waiting.getWaitingConsumers());
877 >        assertEquals(q.getWaitingConsumerCount(), 0);
878 >        assertFalse(q.hasWaitingConsumer());
879          t.join();
880      }
881  
# Line 1121 | Line 1125 | public class LinkedTransferQueueTest ext
1125          assertFalse(q.tryTransfer(five, SHORT_DELAY_MS, MILLISECONDS));
1126          assertEquals(1, q.size());
1127          assertEquals(four, q.poll());
1124        checkEmpty(q);
1128          assertNull(q.poll());
1129 +        checkEmpty(q);
1130      }
1131  
1132      private LinkedTransferQueue<Integer> populatedQueue(int n) {
# Line 1136 | Line 1140 | public class LinkedTransferQueueTest ext
1140          assertFalse(q.isEmpty());
1141          return q;
1142      }
1139
1140    private static class ConsumerObserver {
1141
1142        private int waitingConsumers;
1143
1144        private ConsumerObserver() {
1145        }
1146
1147        private void setWaitingConsumer(int i) {
1148            this.waitingConsumers = i;
1149        }
1150
1151        private int getWaitingConsumers() {
1152            return waitingConsumers;
1153        }
1154    }
1143   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines