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.26 by jsr166, Sun Nov 22 18:57:16 2009 UTC vs.
Revision 1.31 by dl, Wed Sep 29 12:33:48 2010 UTC

# Line 15 | Line 15 | import java.io.*;
15  
16   public class ArrayBlockingQueueTest extends JSR166TestCase {
17      public static void main(String[] args) {
18 <        junit.textui.TestRunner.run (suite());
18 >        junit.textui.TestRunner.run(suite());
19      }
20      public static Test suite() {
21          return new TestSuite(ArrayBlockingQueueTest.class);
# Line 224 | Line 224 | public class ArrayBlockingQueueTest exte
224              shouldThrow();
225          } catch (NullPointerException success) {}
226      }
227 +
228      /**
229       * addAll of a collection with any null elements throws NPE after
230       * possibly adding some elements
# Line 238 | Line 239 | public class ArrayBlockingQueueTest exte
239              shouldThrow();
240          } catch (NullPointerException success) {}
241      }
242 +
243      /**
244       * addAll throws ISE if not enough room
245       */
# Line 251 | Line 253 | public class ArrayBlockingQueueTest exte
253              shouldThrow();
254          } catch (IllegalStateException success) {}
255      }
256 +
257      /**
258       * Queue contains all elements, in traversal order, of successful addAll
259       */
# Line 319 | Line 322 | public class ArrayBlockingQueueTest exte
322       * put blocks waiting for take when full
323       */
324      public void testPutWithTake() throws InterruptedException {
325 <        final ArrayBlockingQueue q = new ArrayBlockingQueue(2);
325 >        final int capacity = 2;
326 >        final ArrayBlockingQueue q = new ArrayBlockingQueue(capacity);
327          Thread t = new Thread(new CheckedRunnable() {
328 <            public void realRun() {
329 <                int added = 0;
328 >            public void realRun() throws InterruptedException {
329 >                for (int i = 0; i < capacity + 1; i++)
330 >                    q.put(i);
331                  try {
332 <                    q.put(new Object());
333 <                    ++added;
334 <                    q.put(new Object());
330 <                    ++added;
331 <                    q.put(new Object());
332 <                    ++added;
333 <                    q.put(new Object());
334 <                    ++added;
335 <                    threadShouldThrow();
336 <                } catch (InterruptedException success) {
337 <                    threadAssertTrue(added >= 2);
338 <                }
332 >                    q.put(99);
333 >                    shouldThrow();
334 >                } catch (InterruptedException success) {}
335              }});
336  
337          t.start();
338          Thread.sleep(SHORT_DELAY_MS);
339 <        q.take();
339 >        assertEquals(q.remainingCapacity(), 0);
340 >        assertEquals(0, q.take());
341 >        Thread.sleep(SHORT_DELAY_MS);
342          t.interrupt();
343          t.join();
344 +        assertEquals(q.remainingCapacity(), 0);
345      }
346  
347      /**
# Line 480 | Line 479 | public class ArrayBlockingQueueTest exte
479          final ArrayBlockingQueue q = new ArrayBlockingQueue(2);
480          Thread t = new Thread(new CheckedRunnable() {
481              public void realRun() throws InterruptedException {
483                assertNull(q.poll(SHORT_DELAY_MS, MILLISECONDS));
484                assertSame(zero, q.poll(LONG_DELAY_MS, MILLISECONDS));
482                  try {
483 +                    assertNull(q.poll(SHORT_DELAY_MS, MILLISECONDS));
484 +                    assertSame(zero, q.poll(LONG_DELAY_MS, MILLISECONDS));
485                      q.poll(LONG_DELAY_MS, MILLISECONDS);
486                      shouldThrow();
487                  } catch (InterruptedException success) {}
# Line 689 | Line 688 | public class ArrayBlockingQueueTest exte
688      /**
689       * iterator.remove removes current element
690       */
691 <    public void testIteratorRemove () {
691 >    public void testIteratorRemove() {
692          final ArrayBlockingQueue q = new ArrayBlockingQueue(3);
693          q.add(two);
694          q.add(one);
# Line 700 | Line 699 | public class ArrayBlockingQueueTest exte
699          it.remove();
700  
701          it = q.iterator();
702 <        assertEquals(it.next(), one);
703 <        assertEquals(it.next(), three);
702 >        assertSame(it.next(), one);
703 >        assertSame(it.next(), three);
704          assertFalse(it.hasNext());
705      }
706  
# Line 726 | Line 725 | public class ArrayBlockingQueueTest exte
725      /**
726       * Modifications do not cause iterators to fail
727       */
728 <    public void testWeaklyConsistentIteration () {
728 >    public void testWeaklyConsistentIteration() {
729          final ArrayBlockingQueue q = new ArrayBlockingQueue(3);
730          q.add(one);
731          q.add(two);
# Line 761 | Line 760 | public class ArrayBlockingQueueTest exte
760          ExecutorService executor = Executors.newFixedThreadPool(2);
761          executor.execute(new CheckedRunnable() {
762              public void realRun() throws InterruptedException {
763 <                threadAssertFalse(q.offer(three));
764 <                threadAssertTrue(q.offer(three, MEDIUM_DELAY_MS, MILLISECONDS));
765 <                threadAssertEquals(0, q.remainingCapacity());
763 >                assertFalse(q.offer(three));
764 >                assertTrue(q.offer(three, MEDIUM_DELAY_MS, MILLISECONDS));
765 >                assertEquals(0, q.remainingCapacity());
766              }});
767  
768          executor.execute(new CheckedRunnable() {
769              public void realRun() throws InterruptedException {
770                  Thread.sleep(SMALL_DELAY_MS);
771 <                threadAssertEquals(one, q.take());
771 >                assertSame(one, q.take());
772              }});
773  
774          joinPool(executor);
776
775      }
776  
777      /**
# Line 784 | Line 782 | public class ArrayBlockingQueueTest exte
782          ExecutorService executor = Executors.newFixedThreadPool(2);
783          executor.execute(new CheckedRunnable() {
784              public void realRun() throws InterruptedException {
785 <                threadAssertNull(q.poll());
786 <                threadAssertTrue(null != q.poll(MEDIUM_DELAY_MS, MILLISECONDS));
787 <                threadAssertTrue(q.isEmpty());
785 >                assertNull(q.poll());
786 >                assertSame(one, q.poll(MEDIUM_DELAY_MS, MILLISECONDS));
787 >                assertTrue(q.isEmpty());
788              }});
789  
790          executor.execute(new CheckedRunnable() {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines