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.15 by jsr166, Sat Nov 21 17:38:05 2009 UTC vs.
Revision 1.22 by jsr166, Tue Dec 1 06:03:49 2009 UTC

# Line 44 | Line 44 | public class LinkedTransferQueueTest ext
44          try {
45              q.element();
46              shouldThrow();
47 <        } catch (NoSuchElementException success) {
48 <        }
47 >        } catch (NoSuchElementException success) {}
48          try {
49              q.iterator().next();
50              shouldThrow();
51 <        } catch (NoSuchElementException success) {
53 <        }
51 >        } catch (NoSuchElementException success) {}
52          try {
53              q.remove();
54              shouldThrow();
55 <        } catch (NoSuchElementException success) {
58 <        }
55 >        } catch (NoSuchElementException success) {}
56      }
57  
58      /**
# Line 75 | Line 72 | public class LinkedTransferQueueTest ext
72          try {
73              new LinkedTransferQueue(null);
74              shouldThrow();
75 <        } catch (NullPointerException success) {
79 <        }
75 >        } catch (NullPointerException success) {}
76      }
77  
78      /**
# Line 88 | Line 84 | public class LinkedTransferQueueTest ext
84              Integer[] ints = new Integer[SIZE];
85              new LinkedTransferQueue(Arrays.asList(ints));
86              shouldThrow();
87 <        } catch (NullPointerException success) {
92 <        }
87 >        } catch (NullPointerException success) {}
88      }
89  
90      /**
# Line 104 | Line 99 | public class LinkedTransferQueueTest ext
99              }
100              new LinkedTransferQueue(Arrays.asList(ints));
101              shouldThrow();
102 <        } catch (NullPointerException success) {
108 <        }
102 >        } catch (NullPointerException success) {}
103      }
104  
105      /**
# Line 157 | Line 151 | public class LinkedTransferQueueTest ext
151              LinkedTransferQueue q = new LinkedTransferQueue();
152              q.offer(null);
153              shouldThrow();
154 <        } catch (NullPointerException success) {
161 <        }
154 >        } catch (NullPointerException success) {}
155      }
156  
157      /**
# Line 169 | Line 162 | public class LinkedTransferQueueTest ext
162              LinkedTransferQueue q = new LinkedTransferQueue();
163              q.add(null);
164              shouldThrow();
165 <        } catch (NullPointerException success) {
173 <        }
165 >        } catch (NullPointerException success) {}
166      }
167  
168      /**
# Line 181 | Line 173 | public class LinkedTransferQueueTest ext
173              LinkedTransferQueue q = new LinkedTransferQueue();
174              q.addAll(null);
175              shouldThrow();
176 <        } catch (NullPointerException success) {
185 <        }
176 >        } catch (NullPointerException success) {}
177      }
178  
179      /**
# Line 193 | Line 184 | public class LinkedTransferQueueTest ext
184              LinkedTransferQueue q = populatedQueue(SIZE);
185              q.addAll(q);
186              shouldThrow();
187 <        } catch (IllegalArgumentException success) {
197 <        }
187 >        } catch (IllegalArgumentException success) {}
188      }
189  
190      /**
# Line 206 | Line 196 | public class LinkedTransferQueueTest ext
196              Integer[] ints = new Integer[SIZE];
197              q.addAll(Arrays.asList(ints));
198              shouldThrow();
199 <        } catch (NullPointerException success) {
210 <        }
199 >        } catch (NullPointerException success) {}
200      }
201  
202      /**
# Line 223 | Line 212 | public class LinkedTransferQueueTest ext
212              }
213              q.addAll(Arrays.asList(ints));
214              shouldThrow();
215 <        } catch (NullPointerException success) {
227 <        }
215 >        } catch (NullPointerException success) {}
216      }
217  
218      /**
# Line 283 | Line 271 | public class LinkedTransferQueueTest ext
271      public void testTakeFromEmpty() throws InterruptedException {
272          final LinkedTransferQueue q = new LinkedTransferQueue();
273          Thread t = newStartedThread(new CheckedInterruptedRunnable() {
274 <            void realRun() throws InterruptedException {
274 >            public void realRun() throws InterruptedException {
275                  q.take();
276              }});
277          Thread.sleep(SHORT_DELAY_MS);
# Line 296 | Line 284 | public class LinkedTransferQueueTest ext
284       */
285      public void testBlockingTake() throws InterruptedException {
286          final LinkedTransferQueue<Integer> q = populatedQueue(SIZE);
287 <        Thread t = newStartedThread(new CheckedInterruptedRunnable() {
288 <            void realRun() throws InterruptedException {
287 >        Thread t = new Thread(new CheckedRunnable() {
288 >            public void realRun() throws InterruptedException {
289                  for (int i = 0; i < SIZE; ++i) {
290 <                    threadAssertEquals(i, (int) q.take());
290 >                    assertEquals(i, (int) q.take());
291                  }
292 <                q.take();
292 >                try {
293 >                    q.take();
294 >                    shouldThrow();
295 >                } catch (InterruptedException success) {}
296              }});
297 <        Thread.sleep(SMALL_DELAY_MS);
297 >
298 >        t.start();
299 >        Thread.sleep(SHORT_DELAY_MS);
300          t.interrupt();
301          t.join();
302          checkEmpty(q);
# Line 354 | Line 347 | public class LinkedTransferQueueTest ext
347       */
348      public void testInterruptedTimedPoll() throws InterruptedException {
349          final LinkedTransferQueue<Integer> q = populatedQueue(SIZE);
350 <        Thread t = newStartedThread(new CheckedInterruptedRunnable() {
351 <            void realRun() throws InterruptedException {
350 >        Thread t = newStartedThread(new CheckedRunnable() {
351 >            public void realRun() throws InterruptedException {
352                  for (int i = 0; i < SIZE; ++i) {
353                      long t0 = System.nanoTime();
354                      threadAssertEquals(i, (int) q.poll(LONG_DELAY_MS,
# Line 363 | Line 356 | public class LinkedTransferQueueTest ext
356                      long millisElapsed = (System.nanoTime() - t0)/(1024 * 1024);
357                      assertTrue(millisElapsed < SMALL_DELAY_MS);
358                  }
359 <                q.poll(LONG_DELAY_MS, MILLISECONDS);
359 >                try {
360 >                    q.poll(LONG_DELAY_MS, MILLISECONDS);
361 >                    shouldThrow();
362 >                } catch (InterruptedException success) {}
363              }});
364 +
365          Thread.sleep(SMALL_DELAY_MS);
366          t.interrupt();
367          t.join();
# Line 377 | Line 374 | public class LinkedTransferQueueTest ext
374       */
375      public void testTimedPollWithOffer() throws InterruptedException {
376          final LinkedTransferQueue q = new LinkedTransferQueue();
377 <        Thread t = newStartedThread(new CheckedInterruptedRunnable() {
378 <            void realRun() throws InterruptedException {
379 <                threadAssertNull(q.poll(SHORT_DELAY_MS, MILLISECONDS));
380 <                q.poll(LONG_DELAY_MS, MILLISECONDS);
381 <                q.poll(LONG_DELAY_MS, MILLISECONDS);
377 >        Thread t = new Thread(new CheckedRunnable() {
378 >            public void realRun() throws InterruptedException {
379 >                assertNull(q.poll(SHORT_DELAY_MS, MILLISECONDS));
380 >                assertSame(zero, q.poll(LONG_DELAY_MS, MILLISECONDS));
381 >                try {
382 >                    q.poll(LONG_DELAY_MS, MILLISECONDS);
383 >                    shouldThrow();
384 >                } catch (InterruptedException success) {}
385              }});
386 +
387 +        t.start();
388          Thread.sleep(SMALL_DELAY_MS);
389          assertTrue(q.offer(zero, SHORT_DELAY_MS, MILLISECONDS));
390          t.interrupt();
# Line 416 | Line 418 | public class LinkedTransferQueueTest ext
418          try {
419              q.element();
420              shouldThrow();
421 <        } catch (NoSuchElementException success) {
420 <        }
421 >        } catch (NoSuchElementException success) {}
422          checkEmpty(q);
423      }
424  
# Line 432 | Line 433 | public class LinkedTransferQueueTest ext
433          try {
434              q.remove();
435              shouldThrow();
436 <        } catch (NoSuchElementException success) {
436 <        }
436 >        } catch (NoSuchElementException success) {}
437          checkEmpty(q);
438      }
439  
# Line 570 | Line 570 | public class LinkedTransferQueueTest ext
570       * toArray(null) throws NullPointerException
571       */
572      public void testToArray_BadArg() {
573 +        LinkedTransferQueue q = populatedQueue(SIZE);
574          try {
574            LinkedTransferQueue q = populatedQueue(SIZE);
575              Object o[] = q.toArray(null);
576              shouldThrow();
577 <        } catch (NullPointerException success) {
578 <        }
577 >        } catch (NullPointerException success) {}
578      }
579  
580      /**
581       * toArray(incompatible array type) throws CCE
582       */
583      public void testToArray1_BadArg() {
584 +        LinkedTransferQueue q = populatedQueue(SIZE);
585          try {
586            LinkedTransferQueue q = populatedQueue(SIZE);
586              Object o[] = q.toArray(new String[10]);
587              shouldThrow();
588 <        } catch (ArrayStoreException success) {
590 <        }
588 >        } catch (ArrayStoreException success) {}
589      }
590  
591      /**
# Line 676 | Line 674 | public class LinkedTransferQueueTest ext
674          ExecutorService executor = Executors.newFixedThreadPool(2);
675  
676          executor.execute(new CheckedRunnable() {
677 <            void realRun() {
677 >            public void realRun() {
678                  threadAssertTrue(q.offer(three, MEDIUM_DELAY_MS,
679                                           MILLISECONDS));
680              }});
681  
682          executor.execute(new CheckedRunnable() {
683 <            void realRun() throws InterruptedException {
683 >            public void realRun() throws InterruptedException {
684                  Thread.sleep(SMALL_DELAY_MS);
685                  threadAssertEquals(one, q.take());
686              }});
# Line 698 | Line 696 | public class LinkedTransferQueueTest ext
696          ExecutorService executor = Executors.newFixedThreadPool(2);
697  
698          executor.execute(new CheckedRunnable() {
699 <            void realRun() throws InterruptedException {
700 <                threadAssertNull(q.poll());
701 <                threadAssertTrue(null != q.poll(MEDIUM_DELAY_MS,
702 <                                                MILLISECONDS));
705 <                threadAssertTrue(q.isEmpty());
699 >            public void realRun() throws InterruptedException {
700 >                assertNull(q.poll());
701 >                assertSame(one, q.poll(MEDIUM_DELAY_MS, MILLISECONDS));
702 >                assertTrue(q.isEmpty());
703              }});
704  
705          executor.execute(new CheckedRunnable() {
706 <            void realRun() throws InterruptedException {
706 >            public void realRun() throws InterruptedException {
707                  Thread.sleep(SMALL_DELAY_MS);
708                  q.put(one);
709              }});
# Line 746 | Line 743 | public class LinkedTransferQueueTest ext
743          try {
744              q.drainTo(null);
745              shouldThrow();
746 <        } catch (NullPointerException success) {
750 <        }
746 >        } catch (NullPointerException success) {}
747      }
748  
749      /**
# Line 758 | Line 754 | public class LinkedTransferQueueTest ext
754          try {
755              q.drainTo(q);
756              shouldThrow();
757 <        } catch (IllegalArgumentException success) {
762 <        }
757 >        } catch (IllegalArgumentException success) {}
758      }
759  
760      /**
# Line 794 | Line 789 | public class LinkedTransferQueueTest ext
789      public void testDrainToWithActivePut() throws InterruptedException {
790          final LinkedTransferQueue q = populatedQueue(SIZE);
791          Thread t = newStartedThread(new CheckedRunnable() {
792 <            void realRun() {
792 >            public void realRun() {
793                  q.put(SIZE + 1);
794              }});
795          ArrayList l = new ArrayList();
# Line 815 | Line 810 | public class LinkedTransferQueueTest ext
810          try {
811              q.drainTo(null, SIZE);
812              shouldThrow();
813 <        } catch (NullPointerException success) {
819 <        }
813 >        } catch (NullPointerException success) {}
814      }
815  
816      /**
# Line 827 | Line 821 | public class LinkedTransferQueueTest ext
821          try {
822              q.drainTo(q, SIZE);
823              shouldThrow();
824 <        } catch (IllegalArgumentException success) {
831 <        }
824 >        } catch (IllegalArgumentException success) {}
825      }
826  
827      /**
# Line 863 | Line 856 | public class LinkedTransferQueueTest ext
856          assertFalse(q.hasWaitingConsumer());
857  
858          Thread t = newStartedThread(new CheckedRunnable() {
859 <            void realRun() throws InterruptedException {
859 >            public void realRun() throws InterruptedException {
860                  Thread.sleep(SMALL_DELAY_MS);
861 <                threadAssertTrue(q.hasWaitingConsumer());
862 <                threadAssertEquals(q.getWaitingConsumerCount(), 1);
863 <                threadAssertTrue(q.offer(new Object()));
864 <                threadAssertFalse(q.hasWaitingConsumer());
865 <                threadAssertEquals(q.getWaitingConsumerCount(), 0);
861 >                assertTrue(q.hasWaitingConsumer());
862 >                assertEquals(q.getWaitingConsumerCount(), 1);
863 >                assertTrue(q.offer(one));
864 >                assertFalse(q.hasWaitingConsumer());
865 >                assertEquals(q.getWaitingConsumerCount(), 0);
866              }});
867  
868 <        assertTrue(q.poll(LONG_DELAY_MS, MILLISECONDS) != null);
868 >        assertSame(one, q.poll(LONG_DELAY_MS, MILLISECONDS));
869          assertEquals(q.getWaitingConsumerCount(), 0);
870          assertFalse(q.hasWaitingConsumer());
871          t.join();
# Line 898 | Line 891 | public class LinkedTransferQueueTest ext
891              = new LinkedTransferQueue<Integer>();
892  
893          Thread t = newStartedThread(new CheckedRunnable() {
894 <            void realRun() throws InterruptedException {
894 >            public void realRun() throws InterruptedException {
895                  q.transfer(SIZE);
896                  threadAssertTrue(q.isEmpty());
897              }});
# Line 918 | Line 911 | public class LinkedTransferQueueTest ext
911              = new LinkedTransferQueue<Integer>();
912  
913          Thread first = newStartedThread(new CheckedRunnable() {
914 <            void realRun() throws InterruptedException {
914 >            public void realRun() throws InterruptedException {
915                  Integer i = SIZE + 1;
916                  q.transfer(i);
917                  threadAssertTrue(!q.contains(i));
# Line 927 | Line 920 | public class LinkedTransferQueueTest ext
920  
921          Thread interruptedThread = newStartedThread(
922              new CheckedInterruptedRunnable() {
923 <                void realRun() throws InterruptedException {
923 >                public void realRun() throws InterruptedException {
924                      while (q.size() == 0)
925                          Thread.yield();
926                      q.transfer(SIZE);
# Line 953 | Line 946 | public class LinkedTransferQueueTest ext
946          final LinkedTransferQueue q = new LinkedTransferQueue();
947  
948          Thread t = newStartedThread(new CheckedRunnable() {
949 <            void realRun() throws InterruptedException {
949 >            public void realRun() throws InterruptedException {
950                  q.transfer(four);
951                  threadAssertFalse(q.contains(four));
952                  threadAssertEquals(three, q.poll());
# Line 974 | Line 967 | public class LinkedTransferQueueTest ext
967              = new LinkedTransferQueue<Integer>();
968  
969          Thread t = newStartedThread(new CheckedRunnable() {
970 <            void realRun() throws InterruptedException {
970 >            public void realRun() throws InterruptedException {
971                  q.transfer(SIZE);
972                  checkEmpty(q);
973              }});
# Line 1016 | Line 1009 | public class LinkedTransferQueueTest ext
1009          final LinkedTransferQueue q = new LinkedTransferQueue();
1010  
1011          Thread t = newStartedThread(new CheckedRunnable() {
1012 <            void realRun() {
1012 >            public void realRun() {
1013                  while (! q.hasWaitingConsumer())
1014                      Thread.yield();
1015                  threadAssertTrue(q.hasWaitingConsumer());
# Line 1039 | Line 1032 | public class LinkedTransferQueueTest ext
1032          final LinkedTransferQueue q = new LinkedTransferQueue();
1033  
1034          Thread t = newStartedThread(new CheckedRunnable() {
1035 <            void realRun() {
1035 >            public void realRun() {
1036                  while (! q.hasWaitingConsumer())
1037                      Thread.yield();
1038                  threadAssertTrue(q.hasWaitingConsumer());
# Line 1061 | Line 1054 | public class LinkedTransferQueueTest ext
1054          final LinkedTransferQueue q = new LinkedTransferQueue();
1055  
1056          Thread toInterrupt = newStartedThread(new CheckedInterruptedRunnable() {
1057 <            void realRun() throws InterruptedException {
1057 >            public void realRun() throws InterruptedException {
1058                  q.tryTransfer(new Object(), LONG_DELAY_MS, MILLISECONDS);
1059              }});
1060  
# Line 1077 | Line 1070 | public class LinkedTransferQueueTest ext
1070          final LinkedTransferQueue q = new LinkedTransferQueue();
1071  
1072          Thread t = newStartedThread(new CheckedRunnable() {
1073 <            void realRun() throws InterruptedException {
1073 >            public void realRun() throws InterruptedException {
1074                  threadAssertFalse
1075                      (q.tryTransfer(new Object(),
1076                                     SHORT_DELAY_MS, MILLISECONDS));
# Line 1097 | Line 1090 | public class LinkedTransferQueueTest ext
1090          assertTrue(q.offer(four));
1091  
1092          Thread t = newStartedThread(new CheckedRunnable() {
1093 <            void realRun() throws InterruptedException {
1093 >            public void realRun() throws InterruptedException {
1094                  threadAssertTrue(q.tryTransfer(five,
1095                                                 MEDIUM_DELAY_MS, MILLISECONDS));
1096                  threadAssertTrue(q.isEmpty());

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines