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.25 by jsr166, Sun Nov 22 00:17:37 2009 UTC vs.
Revision 1.27 by jsr166, Tue Dec 1 06:03:49 2009 UTC

# Line 319 | Line 319 | public class ArrayBlockingQueueTest exte
319       * put blocks waiting for take when full
320       */
321      public void testPutWithTake() throws InterruptedException {
322 <        final ArrayBlockingQueue q = new ArrayBlockingQueue(2);
322 >        final int capacity = 2;
323 >        final ArrayBlockingQueue q = new ArrayBlockingQueue(capacity);
324          Thread t = new Thread(new CheckedRunnable() {
325 <            public void realRun() {
326 <                int added = 0;
325 >            public void realRun() throws InterruptedException {
326 >                for (int i = 0; i < capacity + 1; i++)
327 >                    q.put(i);
328                  try {
329 <                    q.put(new Object());
330 <                    ++added;
331 <                    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 <                }
329 >                    q.put(99);
330 >                    shouldThrow();
331 >                } catch (InterruptedException success) {}
332              }});
333  
334          t.start();
335          Thread.sleep(SHORT_DELAY_MS);
336 <        q.take();
336 >        assertEquals(q.remainingCapacity(), 0);
337 >        assertEquals(0, q.take());
338 >        Thread.sleep(SHORT_DELAY_MS);
339          t.interrupt();
340          t.join();
341 +        assertEquals(q.remainingCapacity(), 0);
342      }
343  
344      /**
# Line 502 | Line 498 | public class ArrayBlockingQueueTest exte
498      public void testPeek() {
499          ArrayBlockingQueue q = populatedQueue(SIZE);
500          for (int i = 0; i < SIZE; ++i) {
501 <            assertEquals(i, ((Integer)q.peek()).intValue());
502 <            q.poll();
501 >            assertEquals(i, q.peek());
502 >            assertEquals(i, q.poll());
503              assertTrue(q.peek() == null ||
504 <                       i != ((Integer)q.peek()).intValue());
504 >                       !q.peek().equals(i));
505          }
506          assertNull(q.peek());
507      }
# Line 516 | Line 512 | public class ArrayBlockingQueueTest exte
512      public void testElement() {
513          ArrayBlockingQueue q = populatedQueue(SIZE);
514          for (int i = 0; i < SIZE; ++i) {
515 <            assertEquals(i, ((Integer)q.element()).intValue());
516 <            q.poll();
515 >            assertEquals(i, q.element());
516 >            assertEquals(i, q.poll());
517          }
518          try {
519              q.element();
# Line 531 | Line 527 | public class ArrayBlockingQueueTest exte
527      public void testRemove() {
528          ArrayBlockingQueue q = populatedQueue(SIZE);
529          for (int i = 0; i < SIZE; ++i) {
530 <            assertEquals(i, ((Integer)q.remove()).intValue());
530 >            assertEquals(i, q.remove());
531          }
532          try {
533              q.remove();
# Line 561 | Line 557 | public class ArrayBlockingQueueTest exte
557          ArrayBlockingQueue q = populatedQueue(SIZE);
558          for (int i = 0; i < SIZE; ++i) {
559              assertTrue(q.contains(new Integer(i)));
560 <            q.poll();
560 >            assertEquals(i, q.poll());
561              assertFalse(q.contains(new Integer(i)));
562          }
563      }
# Line 656 | Line 652 | public class ArrayBlockingQueueTest exte
652       * toArray(null) throws NPE
653       */
654      public void testToArray_BadArg() {
655 +        ArrayBlockingQueue q = populatedQueue(SIZE);
656          try {
660            ArrayBlockingQueue q = populatedQueue(SIZE);
657              Object o[] = q.toArray(null);
658              shouldThrow();
659          } catch (NullPointerException success) {}
# Line 667 | Line 663 | public class ArrayBlockingQueueTest exte
663       * toArray with incompatible array type throws CCE
664       */
665      public void testToArray1_BadArg() {
666 +        ArrayBlockingQueue q = populatedQueue(SIZE);
667          try {
668 <            ArrayBlockingQueue q = populatedQueue(SIZE);
672 <            Object o[] = q.toArray(new String[10] );
668 >            Object o[] = q.toArray(new String[10]);
669              shouldThrow();
670          } catch (ArrayStoreException success) {}
671      }
# Line 718 | Line 714 | public class ArrayBlockingQueueTest exte
714  
715          int k = 0;
716          for (Iterator it = q.iterator(); it.hasNext();) {
717 <            int i = ((Integer)(it.next())).intValue();
722 <            assertEquals(++k, i);
717 >            assertEquals(++k, it.next());
718          }
719          assertEquals(3, k);
720      }
# Line 762 | Line 757 | public class ArrayBlockingQueueTest exte
757          ExecutorService executor = Executors.newFixedThreadPool(2);
758          executor.execute(new CheckedRunnable() {
759              public void realRun() throws InterruptedException {
760 <                threadAssertFalse(q.offer(three));
761 <                threadAssertTrue(q.offer(three, MEDIUM_DELAY_MS, MILLISECONDS));
762 <                threadAssertEquals(0, q.remainingCapacity());
760 >                assertFalse(q.offer(three));
761 >                assertTrue(q.offer(three, MEDIUM_DELAY_MS, MILLISECONDS));
762 >                assertEquals(0, q.remainingCapacity());
763              }});
764  
765          executor.execute(new CheckedRunnable() {
766              public void realRun() throws InterruptedException {
767                  Thread.sleep(SMALL_DELAY_MS);
768 <                threadAssertEquals(one, q.take());
768 >                assertSame(one, q.take());
769              }});
770  
771          joinPool(executor);
# Line 785 | Line 780 | public class ArrayBlockingQueueTest exte
780          ExecutorService executor = Executors.newFixedThreadPool(2);
781          executor.execute(new CheckedRunnable() {
782              public void realRun() throws InterruptedException {
783 <                threadAssertNull(q.poll());
784 <                threadAssertTrue(null != q.poll(MEDIUM_DELAY_MS, MILLISECONDS));
785 <                threadAssertTrue(q.isEmpty());
783 >                assertNull(q.poll());
784 >                assertSame(one, q.poll(MEDIUM_DELAY_MS, MILLISECONDS));
785 >                assertTrue(q.isEmpty());
786              }});
787  
788          executor.execute(new CheckedRunnable() {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines