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

Comparing jsr166/src/test/tck/ArrayBlockingQueueTest.java (file contents):
Revision 1.17 by jsr166, Sat Nov 21 07:10:56 2009 UTC vs.
Revision 1.24 by jsr166, Sat Nov 21 22:00:46 2009 UTC

# Line 44 | Line 44 | public class ArrayBlockingQueueTest exte
44      }
45  
46      /**
47 <     * Constructor throws IAE if  capacity argument nonpositive
47 >     * Constructor throws IAE if capacity argument nonpositive
48       */
49      public void testConstructor2() {
50          try {
# Line 104 | Line 104 | public class ArrayBlockingQueueTest exte
104       * Queue contains all elements of collection used to initialize
105       */
106      public void testConstructor7() {
107 <        try {
108 <            Integer[] ints = new Integer[SIZE];
109 <            for (int i = 0; i < SIZE; ++i)
110 <                ints[i] = new Integer(i);
111 <            ArrayBlockingQueue q = new ArrayBlockingQueue(SIZE, true, Arrays.asList(ints));
112 <            for (int i = 0; i < SIZE; ++i)
113 <                assertEquals(ints[i], q.poll());
114 <        }
115 <        finally {}
107 >        Integer[] ints = new Integer[SIZE];
108 >        for (int i = 0; i < SIZE; ++i)
109 >            ints[i] = new Integer(i);
110 >        ArrayBlockingQueue q = new ArrayBlockingQueue(SIZE, true, Arrays.asList(ints));
111 >        for (int i = 0; i < SIZE; ++i)
112 >            assertEquals(ints[i], q.poll());
113      }
114  
115      /**
# Line 308 | Line 305 | public class ArrayBlockingQueueTest exte
305                      }
306                      q.put(new Integer(SIZE));
307                      threadShouldThrow();
308 <                } catch (InterruptedException ie) {
308 >                } catch (InterruptedException success) {
309                      threadAssertEquals(added, SIZE);
310                  }}});
311  
# Line 336 | Line 333 | public class ArrayBlockingQueueTest exte
333                      q.put(new Object());
334                      ++added;
335                      threadShouldThrow();
336 <                } catch (InterruptedException e) {
336 >                } catch (InterruptedException success) {
337                      threadAssertTrue(added >= 2);
338                  }
339              }});
# Line 353 | Line 350 | public class ArrayBlockingQueueTest exte
350       */
351      public void testTimedOffer() throws InterruptedException {
352          final ArrayBlockingQueue q = new ArrayBlockingQueue(2);
353 <        Thread t = new ThreadShouldThrow(InterruptedException.class) {
353 >        Thread t = new Thread(new CheckedRunnable() {
354              public void realRun() throws InterruptedException {
355                  q.put(new Object());
356                  q.put(new Object());
357 <                threadAssertFalse(q.offer(new Object(), SHORT_DELAY_MS/2, MILLISECONDS));
358 <                q.offer(new Object(), LONG_DELAY_MS, MILLISECONDS);
359 <            }};
357 >                assertFalse(q.offer(new Object(), SHORT_DELAY_MS/2, MILLISECONDS));
358 >                try {
359 >                    q.offer(new Object(), LONG_DELAY_MS, MILLISECONDS);
360 >                    shouldThrow();
361 >                } catch (InterruptedException success) {}
362 >            }});
363  
364          t.start();
365          Thread.sleep(SHORT_DELAY_MS);
# Line 451 | Line 451 | public class ArrayBlockingQueueTest exte
451       * returning timeout status
452       */
453      public void testInterruptedTimedPoll() throws InterruptedException {
454 <        Thread t = new ThreadShouldThrow(InterruptedException.class) {
454 >        Thread t = new Thread(new CheckedRunnable() {
455              public void realRun() throws InterruptedException {
456                  ArrayBlockingQueue q = populatedQueue(SIZE);
457                  for (int i = 0; i < SIZE; ++i) {
458 <                    threadAssertEquals(i, ((Integer)q.poll(SHORT_DELAY_MS, MILLISECONDS)).intValue());
458 >                    assertEquals(i, ((Integer)q.poll(SHORT_DELAY_MS, MILLISECONDS)).intValue());
459                  }
460 <                q.poll(MEDIUM_DELAY_MS, MILLISECONDS);
461 <            }};
460 >                try {
461 >                    q.poll(SMALL_DELAY_MS, MILLISECONDS);
462 >                    shouldThrow();
463 >                } catch (InterruptedException success) {}
464 >            }});
465  
466          t.start();
467 <        Thread.sleep(SMALL_DELAY_MS);
467 >        Thread.sleep(SHORT_DELAY_MS);
468          t.interrupt();
469          t.join();
470      }
# Line 472 | Line 475 | public class ArrayBlockingQueueTest exte
475       */
476      public void testTimedPollWithOffer() throws InterruptedException {
477          final ArrayBlockingQueue q = new ArrayBlockingQueue(2);
478 <        Thread t = new ThreadShouldThrow(InterruptedException.class) {
478 >        Thread t = new Thread(new CheckedRunnable() {
479              public void realRun() throws InterruptedException {
480 <                threadAssertNull(q.poll(SHORT_DELAY_MS, MILLISECONDS));
481 <                q.poll(LONG_DELAY_MS, MILLISECONDS);
482 <                q.poll(LONG_DELAY_MS, MILLISECONDS);
483 <            }};
480 >                assertNull(q.poll(SHORT_DELAY_MS, MILLISECONDS));
481 >                assertSame(zero, q.poll(LONG_DELAY_MS, MILLISECONDS));
482 >                try {
483 >                    q.poll(LONG_DELAY_MS, MILLISECONDS);
484 >                    shouldThrow();
485 >                } catch (InterruptedException success) {}
486 >            }});
487  
488          t.start();
489          Thread.sleep(SMALL_DELAY_MS);
# Line 662 | Line 668 | public class ArrayBlockingQueueTest exte
668              ArrayBlockingQueue q = populatedQueue(SIZE);
669              Object o[] = q.toArray(new String[10] );
670              shouldThrow();
671 <        } catch (ArrayStoreException  success) {}
671 >        } catch (ArrayStoreException success) {}
672      }
673  
674  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines