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.17 by jsr166, Sat Nov 21 19:45:16 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 45 | Line 44 | public class LinkedTransferQueueTest ext
44          try {
45              q.element();
46              shouldThrow();
47 <        } catch (NoSuchElementException success) {
49 <        }
47 >        } catch (NoSuchElementException success) {}
48          try {
49              q.iterator().next();
50              shouldThrow();
51 <        } catch (NoSuchElementException success) {
54 <        }
51 >        } catch (NoSuchElementException success) {}
52          try {
53              q.remove();
54              shouldThrow();
55 <        } catch (NoSuchElementException success) {
59 <        }
55 >        } catch (NoSuchElementException success) {}
56      }
57  
58      /**
# Line 76 | Line 72 | public class LinkedTransferQueueTest ext
72          try {
73              new LinkedTransferQueue(null);
74              shouldThrow();
75 <        } catch (NullPointerException success) {
80 <        }
75 >        } catch (NullPointerException success) {}
76      }
77  
78      /**
# Line 89 | Line 84 | public class LinkedTransferQueueTest ext
84              Integer[] ints = new Integer[SIZE];
85              new LinkedTransferQueue(Arrays.asList(ints));
86              shouldThrow();
87 <        } catch (NullPointerException success) {
93 <        }
87 >        } catch (NullPointerException success) {}
88      }
89  
90      /**
# Line 105 | Line 99 | public class LinkedTransferQueueTest ext
99              }
100              new LinkedTransferQueue(Arrays.asList(ints));
101              shouldThrow();
102 <        } catch (NullPointerException success) {
109 <        }
102 >        } catch (NullPointerException success) {}
103      }
104  
105      /**
# Line 158 | Line 151 | public class LinkedTransferQueueTest ext
151              LinkedTransferQueue q = new LinkedTransferQueue();
152              q.offer(null);
153              shouldThrow();
154 <        } catch (NullPointerException success) {
162 <        }
154 >        } catch (NullPointerException success) {}
155      }
156  
157      /**
# Line 170 | Line 162 | public class LinkedTransferQueueTest ext
162              LinkedTransferQueue q = new LinkedTransferQueue();
163              q.add(null);
164              shouldThrow();
165 <        } catch (NullPointerException success) {
174 <        }
165 >        } catch (NullPointerException success) {}
166      }
167  
168      /**
# Line 182 | Line 173 | public class LinkedTransferQueueTest ext
173              LinkedTransferQueue q = new LinkedTransferQueue();
174              q.addAll(null);
175              shouldThrow();
176 <        } catch (NullPointerException success) {
186 <        }
176 >        } catch (NullPointerException success) {}
177      }
178  
179      /**
# Line 194 | Line 184 | public class LinkedTransferQueueTest ext
184              LinkedTransferQueue q = populatedQueue(SIZE);
185              q.addAll(q);
186              shouldThrow();
187 <        } catch (IllegalArgumentException success) {
198 <        }
187 >        } catch (IllegalArgumentException success) {}
188      }
189  
190      /**
# Line 207 | Line 196 | public class LinkedTransferQueueTest ext
196              Integer[] ints = new Integer[SIZE];
197              q.addAll(Arrays.asList(ints));
198              shouldThrow();
199 <        } catch (NullPointerException success) {
211 <        }
199 >        } catch (NullPointerException success) {}
200      }
201  
202      /**
# Line 224 | Line 212 | public class LinkedTransferQueueTest ext
212              }
213              q.addAll(Arrays.asList(ints));
214              shouldThrow();
215 <        } catch (NullPointerException success) {
228 <        }
215 >        } catch (NullPointerException success) {}
216      }
217  
218      /**
# Line 355 | Line 342 | public class LinkedTransferQueueTest ext
342       */
343      public void testInterruptedTimedPoll() throws InterruptedException {
344          final LinkedTransferQueue<Integer> q = populatedQueue(SIZE);
345 <        Thread t = newStartedThread(new CheckedInterruptedRunnable() {
345 >        Thread t = newStartedThread(new CheckedRunnable() {
346              void realRun() throws InterruptedException {
347                  for (int i = 0; i < SIZE; ++i) {
348                      long t0 = System.nanoTime();
# Line 364 | Line 351 | public class LinkedTransferQueueTest ext
351                      long millisElapsed = (System.nanoTime() - t0)/(1024 * 1024);
352                      assertTrue(millisElapsed < SMALL_DELAY_MS);
353                  }
354 <                q.poll(LONG_DELAY_MS, MILLISECONDS);
354 >                try {
355 >                    q.poll(LONG_DELAY_MS, MILLISECONDS);
356 >                    shouldThrow();
357 >                } catch (InterruptedException success) {}
358              }});
359 +
360          Thread.sleep(SMALL_DELAY_MS);
361          t.interrupt();
362          t.join();
# Line 417 | Line 408 | public class LinkedTransferQueueTest ext
408          try {
409              q.element();
410              shouldThrow();
411 <        } catch (NoSuchElementException success) {
421 <        }
411 >        } catch (NoSuchElementException success) {}
412          checkEmpty(q);
413      }
414  
# Line 433 | Line 423 | public class LinkedTransferQueueTest ext
423          try {
424              q.remove();
425              shouldThrow();
426 <        } catch (NoSuchElementException success) {
437 <        }
426 >        } catch (NoSuchElementException success) {}
427          checkEmpty(q);
428      }
429  
# Line 545 | Line 534 | public class LinkedTransferQueueTest ext
534      }
535  
536      /**
537 <     * toArray contains all elements
537 >     * toArray() contains all elements
538       */
539      public void testToArray() throws InterruptedException {
540          LinkedTransferQueue q = populatedQueue(SIZE);
# Line 575 | Line 564 | public class LinkedTransferQueueTest ext
564              LinkedTransferQueue q = populatedQueue(SIZE);
565              Object o[] = q.toArray(null);
566              shouldThrow();
567 <        } catch (NullPointerException success) {
579 <        }
567 >        } catch (NullPointerException success) {}
568      }
569  
570      /**
571 <     * toArray with incompatible array type throws CCE
571 >     * toArray(incompatible array type) throws CCE
572       */
573      public void testToArray1_BadArg() {
574          try {
575              LinkedTransferQueue q = populatedQueue(SIZE);
576              Object o[] = q.toArray(new String[10]);
577              shouldThrow();
578 <        } catch (ArrayStoreException success) {
591 <        }
578 >        } catch (ArrayStoreException success) {}
579      }
580  
581      /**
# Line 692 | Line 679 | public class LinkedTransferQueueTest ext
679      }
680  
681      /**
682 <     * poll retrieves elements across Executor threads
682 >     * timed poll retrieves elements across Executor threads
683       */
684      public void testPollInExecutor() {
685          final LinkedTransferQueue q = new LinkedTransferQueue();
# Line 747 | Line 734 | public class LinkedTransferQueueTest ext
734          try {
735              q.drainTo(null);
736              shouldThrow();
737 <        } catch (NullPointerException success) {
751 <        }
737 >        } catch (NullPointerException success) {}
738      }
739  
740      /**
# Line 759 | Line 745 | public class LinkedTransferQueueTest ext
745          try {
746              q.drainTo(q);
747              shouldThrow();
748 <        } catch (IllegalArgumentException success) {
763 <        }
748 >        } catch (IllegalArgumentException success) {}
749      }
750  
751      /**
# Line 790 | Line 775 | public class LinkedTransferQueueTest ext
775      }
776  
777      /**
778 <     * drainTo empties full queue, unblocking a waiting put.
778 >     * drainTo(c) empties full queue, unblocking a waiting put.
779       */
780      public void testDrainToWithActivePut() throws InterruptedException {
781          final LinkedTransferQueue q = populatedQueue(SIZE);
# Line 816 | Line 801 | public class LinkedTransferQueueTest ext
801          try {
802              q.drainTo(null, SIZE);
803              shouldThrow();
804 <        } catch (NullPointerException success) {
820 <        }
804 >        } catch (NullPointerException success) {}
805      }
806  
807      /**
# Line 828 | Line 812 | public class LinkedTransferQueueTest ext
812          try {
813              q.drainTo(q, SIZE);
814              shouldThrow();
815 <        } catch (IllegalArgumentException success) {
832 <        }
815 >        } catch (IllegalArgumentException success) {}
816      }
817  
818      /**
# Line 855 | Line 838 | public class LinkedTransferQueueTest ext
838      }
839  
840      /**
841 <     * poll and take decrement the waiting consumer count
841 >     * timed poll() or take() increments the waiting consumer count;
842 >     * offer(e) decrements the waiting consumer count
843       */
844      public void testWaitingConsumer() throws InterruptedException {
845          final LinkedTransferQueue q = new LinkedTransferQueue();
846 <        final ConsumerObserver waiting = new ConsumerObserver();
846 >        assertEquals(q.getWaitingConsumerCount(), 0);
847 >        assertFalse(q.hasWaitingConsumer());
848  
849          Thread t = newStartedThread(new CheckedRunnable() {
850              void realRun() throws InterruptedException {
851                  Thread.sleep(SMALL_DELAY_MS);
852                  threadAssertTrue(q.hasWaitingConsumer());
853 <                waiting.setWaitingConsumer(q.getWaitingConsumerCount());
853 >                threadAssertEquals(q.getWaitingConsumerCount(), 1);
854                  threadAssertTrue(q.offer(new Object()));
855 +                threadAssertFalse(q.hasWaitingConsumer());
856 +                threadAssertEquals(q.getWaitingConsumerCount(), 0);
857              }});
858  
859          assertTrue(q.poll(LONG_DELAY_MS, MILLISECONDS) != null);
860 <        assertTrue(q.getWaitingConsumerCount()
861 <                   < waiting.getWaitingConsumers());
860 >        assertEquals(q.getWaitingConsumerCount(), 0);
861 >        assertFalse(q.hasWaitingConsumer());
862          t.join();
863      }
864  
# Line 883 | Line 870 | public class LinkedTransferQueueTest ext
870              LinkedTransferQueue q = new LinkedTransferQueue();
871              q.transfer(null);
872              shouldThrow();
873 <        } catch (NullPointerException ex) {
887 <        }
873 >        } catch (NullPointerException success) {}
874      }
875  
876      /**
# Line 991 | Line 977 | public class LinkedTransferQueueTest ext
977              final LinkedTransferQueue q = new LinkedTransferQueue();
978              q.tryTransfer(null);
979              shouldThrow();
980 <        } catch (NullPointerException ex) {
995 <        }
980 >        } catch (NullPointerException success) {}
981      }
982  
983      /**
# Line 1121 | Line 1106 | public class LinkedTransferQueueTest ext
1106          assertFalse(q.tryTransfer(five, SHORT_DELAY_MS, MILLISECONDS));
1107          assertEquals(1, q.size());
1108          assertEquals(four, q.poll());
1124        checkEmpty(q);
1109          assertNull(q.poll());
1110 +        checkEmpty(q);
1111      }
1112  
1113      private LinkedTransferQueue<Integer> populatedQueue(int n) {
# Line 1136 | Line 1121 | public class LinkedTransferQueueTest ext
1121          assertFalse(q.isEmpty());
1122          return q;
1123      }
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    }
1124   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines