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.16 by jsr166, Sat Nov 21 19:11:53 2009 UTC

# Line 13 | Line 13 | import java.io.ObjectInputStream;
13   import java.io.ObjectOutputStream;
14   import java.util.ArrayList;
15   import java.util.Arrays;
16 import java.util.ConcurrentModificationException;
16   import java.util.Iterator;
17   import java.util.List;
18   import java.util.NoSuchElementException;
# Line 355 | Line 354 | public class LinkedTransferQueueTest ext
354       */
355      public void testInterruptedTimedPoll() throws InterruptedException {
356          final LinkedTransferQueue<Integer> q = populatedQueue(SIZE);
357 <        Thread t = newStartedThread(new CheckedInterruptedRunnable() {
357 >        Thread t = newStartedThread(new CheckedRunnable() {
358              void realRun() throws InterruptedException {
359                  for (int i = 0; i < SIZE; ++i) {
360                      long t0 = System.nanoTime();
# Line 364 | Line 363 | public class LinkedTransferQueueTest ext
363                      long millisElapsed = (System.nanoTime() - t0)/(1024 * 1024);
364                      assertTrue(millisElapsed < SMALL_DELAY_MS);
365                  }
366 <                q.poll(LONG_DELAY_MS, MILLISECONDS);
366 >                try {
367 >                    q.poll(LONG_DELAY_MS, MILLISECONDS);
368 >                } catch (InterruptedException success) {}
369              }});
370          Thread.sleep(SMALL_DELAY_MS);
371          t.interrupt();
# Line 545 | Line 546 | public class LinkedTransferQueueTest ext
546      }
547  
548      /**
549 <     * toArray contains all elements
549 >     * toArray() contains all elements
550       */
551      public void testToArray() throws InterruptedException {
552          LinkedTransferQueue q = populatedQueue(SIZE);
# Line 580 | Line 581 | public class LinkedTransferQueueTest ext
581      }
582  
583      /**
584 <     * toArray with incompatible array type throws CCE
584 >     * toArray(incompatible array type) throws CCE
585       */
586      public void testToArray1_BadArg() {
587          try {
# Line 692 | Line 693 | public class LinkedTransferQueueTest ext
693      }
694  
695      /**
696 <     * poll retrieves elements across Executor threads
696 >     * timed poll retrieves elements across Executor threads
697       */
698      public void testPollInExecutor() {
699          final LinkedTransferQueue q = new LinkedTransferQueue();
# Line 790 | Line 791 | public class LinkedTransferQueueTest ext
791      }
792  
793      /**
794 <     * drainTo empties full queue, unblocking a waiting put.
794 >     * drainTo(c) empties full queue, unblocking a waiting put.
795       */
796      public void testDrainToWithActivePut() throws InterruptedException {
797          final LinkedTransferQueue q = populatedQueue(SIZE);
# Line 855 | Line 856 | public class LinkedTransferQueueTest ext
856      }
857  
858      /**
859 <     * poll and take decrement the waiting consumer count
859 >     * timed poll() or take() increments the waiting consumer count;
860 >     * offer(e) decrements the waiting consumer count
861       */
862      public void testWaitingConsumer() throws InterruptedException {
863          final LinkedTransferQueue q = new LinkedTransferQueue();
864 <        final ConsumerObserver waiting = new ConsumerObserver();
864 >        assertEquals(q.getWaitingConsumerCount(), 0);
865 >        assertFalse(q.hasWaitingConsumer());
866  
867          Thread t = newStartedThread(new CheckedRunnable() {
868              void realRun() throws InterruptedException {
869                  Thread.sleep(SMALL_DELAY_MS);
870                  threadAssertTrue(q.hasWaitingConsumer());
871 <                waiting.setWaitingConsumer(q.getWaitingConsumerCount());
871 >                threadAssertEquals(q.getWaitingConsumerCount(), 1);
872                  threadAssertTrue(q.offer(new Object()));
873 +                threadAssertFalse(q.hasWaitingConsumer());
874 +                threadAssertEquals(q.getWaitingConsumerCount(), 0);
875              }});
876  
877          assertTrue(q.poll(LONG_DELAY_MS, MILLISECONDS) != null);
878 <        assertTrue(q.getWaitingConsumerCount()
879 <                   < waiting.getWaitingConsumers());
878 >        assertEquals(q.getWaitingConsumerCount(), 0);
879 >        assertFalse(q.hasWaitingConsumer());
880          t.join();
881      }
882  
# Line 883 | Line 888 | public class LinkedTransferQueueTest ext
888              LinkedTransferQueue q = new LinkedTransferQueue();
889              q.transfer(null);
890              shouldThrow();
891 <        } catch (NullPointerException ex) {
887 <        }
891 >        } catch (NullPointerException success) {}
892      }
893  
894      /**
# Line 991 | Line 995 | public class LinkedTransferQueueTest ext
995              final LinkedTransferQueue q = new LinkedTransferQueue();
996              q.tryTransfer(null);
997              shouldThrow();
998 <        } catch (NullPointerException ex) {
995 <        }
998 >        } catch (NullPointerException success) {}
999      }
1000  
1001      /**
# Line 1121 | Line 1124 | public class LinkedTransferQueueTest ext
1124          assertFalse(q.tryTransfer(five, SHORT_DELAY_MS, MILLISECONDS));
1125          assertEquals(1, q.size());
1126          assertEquals(four, q.poll());
1124        checkEmpty(q);
1127          assertNull(q.poll());
1128 +        checkEmpty(q);
1129      }
1130  
1131      private LinkedTransferQueue<Integer> populatedQueue(int n) {
# Line 1136 | Line 1139 | public class LinkedTransferQueueTest ext
1139          assertFalse(q.isEmpty());
1140          return q;
1141      }
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    }
1142   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines