ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/test/tck/PriorityBlockingQueueTest.java
(Generate patch)

Comparing jsr166/src/test/tck/PriorityBlockingQueueTest.java (file contents):
Revision 1.16 by jsr166, Sat Nov 21 02:07:27 2009 UTC vs.
Revision 1.23 by jsr166, Sun Nov 22 00:17:37 2009 UTC

# Line 9 | Line 9
9   import junit.framework.*;
10   import java.util.*;
11   import java.util.concurrent.*;
12 + import static java.util.concurrent.TimeUnit.MILLISECONDS;
13   import java.io.*;
14  
15   public class PriorityBlockingQueueTest extends JSR166TestCase {
# Line 57 | Line 58 | public class PriorityBlockingQueueTest e
58      }
59  
60      /**
61 <     * Constructor throws IAE if  capacity argument nonpositive
61 >     * Constructor throws IAE if capacity argument nonpositive
62       */
63      public void testConstructor2() {
64          try {
# Line 327 | Line 328 | public class PriorityBlockingQueueTest e
328       */
329      public void testTimedOffer() throws InterruptedException {
330          final PriorityBlockingQueue q = new PriorityBlockingQueue(2);
331 <        Thread t = new Thread(new Runnable() {
332 <                public void run() {
333 <                    try {
334 <                        q.put(new Integer(0));
335 <                        q.put(new Integer(0));
336 <                        threadAssertTrue(q.offer(new Integer(0), SHORT_DELAY_MS, TimeUnit.MILLISECONDS));
337 <                        threadAssertTrue(q.offer(new Integer(0), LONG_DELAY_MS, TimeUnit.MILLISECONDS));
337 <                    } finally { }
338 <                }
339 <            });
331 >        Thread t = new Thread(new CheckedRunnable() {
332 >            public void realRun() {
333 >                q.put(new Integer(0));
334 >                q.put(new Integer(0));
335 >                assertTrue(q.offer(new Integer(0), SHORT_DELAY_MS, MILLISECONDS));
336 >                assertTrue(q.offer(new Integer(0), LONG_DELAY_MS, MILLISECONDS));
337 >            }});
338  
339          t.start();
340          Thread.sleep(SMALL_DELAY_MS);
# Line 374 | Line 372 | public class PriorityBlockingQueueTest e
372       * Take removes existing elements until empty, then blocks interruptibly
373       */
374      public void testBlockingTake() throws InterruptedException {
375 <        Thread t = new Thread(new CheckedInterruptedRunnable() {
375 >        final PriorityBlockingQueue q = populatedQueue(SIZE);
376 >        Thread t = new Thread(new CheckedRunnable() {
377              public void realRun() throws InterruptedException {
379                PriorityBlockingQueue q = populatedQueue(SIZE);
378                  for (int i = 0; i < SIZE; ++i) {
379 <                    threadAssertEquals(i, ((Integer)q.take()).intValue());
379 >                    assertEquals(i, q.take());
380                  }
381 <                q.take();
381 >                try {
382 >                    q.take();
383 >                    shouldThrow();
384 >                } catch (InterruptedException success) {}
385              }});
386  
387          t.start();
# Line 407 | Line 408 | public class PriorityBlockingQueueTest e
408      public void testTimedPoll0() throws InterruptedException {
409          PriorityBlockingQueue q = populatedQueue(SIZE);
410          for (int i = 0; i < SIZE; ++i) {
411 <            assertEquals(i, ((Integer)q.poll(0, TimeUnit.MILLISECONDS)).intValue());
411 >            assertEquals(i, ((Integer)q.poll(0, MILLISECONDS)).intValue());
412          }
413 <        assertNull(q.poll(0, TimeUnit.MILLISECONDS));
413 >        assertNull(q.poll(0, MILLISECONDS));
414      }
415  
416      /**
# Line 418 | Line 419 | public class PriorityBlockingQueueTest e
419      public void testTimedPoll() throws InterruptedException {
420          PriorityBlockingQueue q = populatedQueue(SIZE);
421          for (int i = 0; i < SIZE; ++i) {
422 <            assertEquals(i, ((Integer)q.poll(SHORT_DELAY_MS, TimeUnit.MILLISECONDS)).intValue());
422 >            assertEquals(i, ((Integer)q.poll(SHORT_DELAY_MS, MILLISECONDS)).intValue());
423          }
424 <        assertNull(q.poll(SHORT_DELAY_MS, TimeUnit.MILLISECONDS));
424 >        assertNull(q.poll(SHORT_DELAY_MS, MILLISECONDS));
425      }
426  
427      /**
# Line 432 | Line 433 | public class PriorityBlockingQueueTest e
433              public void realRun() throws InterruptedException {
434                  PriorityBlockingQueue q = populatedQueue(SIZE);
435                  for (int i = 0; i < SIZE; ++i) {
436 <                    threadAssertEquals(i, ((Integer)q.poll(SHORT_DELAY_MS, TimeUnit.MILLISECONDS)).intValue());
436 >                    assertEquals(i, ((Integer)q.poll(SHORT_DELAY_MS, MILLISECONDS)).intValue());
437                  }
438                  try {
439 <                    q.poll(SMALL_DELAY_MS, TimeUnit.MILLISECONDS);
440 <                    threadShouldThrow();
439 >                    q.poll(SMALL_DELAY_MS, MILLISECONDS);
440 >                    shouldThrow();
441                  } catch (InterruptedException success) {}
442              }});
443  
# Line 454 | Line 455 | public class PriorityBlockingQueueTest e
455          final PriorityBlockingQueue q = new PriorityBlockingQueue(2);
456          Thread t = new Thread(new CheckedRunnable() {
457              public void realRun() throws InterruptedException {
458 <                threadAssertNull(q.poll(SHORT_DELAY_MS, TimeUnit.MILLISECONDS));
459 <                threadAssertEquals(0, q.poll(MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS));
458 >                assertNull(q.poll(SHORT_DELAY_MS, MILLISECONDS));
459 >                assertSame(zero, q.poll(MEDIUM_DELAY_MS, MILLISECONDS));
460                  try {
461 <                    q.poll(LONG_DELAY_MS, TimeUnit.MILLISECONDS);
462 <                    threadShouldThrow();
461 >                    q.poll(LONG_DELAY_MS, MILLISECONDS);
462 >                    shouldThrow();
463                  } catch (InterruptedException success) {}
464              }});
465  
466          t.start();
467          Thread.sleep(SMALL_DELAY_MS);
468 <        assertTrue(q.offer(new Integer(0), SHORT_DELAY_MS, TimeUnit.MILLISECONDS));
468 >        assertTrue(q.offer(zero, SHORT_DELAY_MS, MILLISECONDS));
469          t.interrupt();
470          t.join();
471      }
# Line 646 | Line 647 | public class PriorityBlockingQueueTest e
647              PriorityBlockingQueue q = populatedQueue(SIZE);
648              Object o[] = q.toArray(new String[10] );
649              shouldThrow();
650 <        } catch (ArrayStoreException  success) {}
650 >        } catch (ArrayStoreException success) {}
651      }
652  
653      /**
# Line 703 | Line 704 | public class PriorityBlockingQueueTest e
704          executor.execute(new CheckedRunnable() {
705              public void realRun() throws InterruptedException {
706                  threadAssertNull(q.poll());
707 <                threadAssertTrue(null != q.poll(MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS));
707 >                threadAssertTrue(null != q.poll(MEDIUM_DELAY_MS, MILLISECONDS));
708                  threadAssertTrue(q.isEmpty());
709              }});
710  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines