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

Comparing jsr166/src/test/tck/LinkedBlockingDequeTest.java (file contents):
Revision 1.32 by jsr166, Fri Nov 5 00:17:22 2010 UTC vs.
Revision 1.36 by jsr166, Thu Apr 14 22:55:08 2011 UTC

# Line 1 | Line 1
1   /*
2   * Written by Doug Lea with assistance from members of JCP JSR-166
3   * Expert Group and released to the public domain, as explained at
4 < * http://creativecommons.org/licenses/publicdomain
4 > * http://creativecommons.org/publicdomain/zero/1.0/
5   */
6  
7   import junit.framework.*;
# Line 743 | Line 743 | public class LinkedBlockingDequeTest ext
743       * returning timeout status
744       */
745      public void testInterruptedTimedPoll() throws InterruptedException {
746 <        Thread t = new Thread(new CheckedRunnable() {
746 >        final BlockingQueue<Integer> q = populatedDeque(SIZE);
747 >        final CountDownLatch aboutToWait = new CountDownLatch(1);
748 >        Thread t = newStartedThread(new CheckedRunnable() {
749              public void realRun() throws InterruptedException {
748                LinkedBlockingDeque q = populatedDeque(SIZE);
750                  for (int i = 0; i < SIZE; ++i) {
751 <                    assertEquals(i, q.poll(SHORT_DELAY_MS, MILLISECONDS));
751 >                    long t0 = System.nanoTime();
752 >                    assertEquals(i, (int) q.poll(LONG_DELAY_MS, MILLISECONDS));
753 >                    assertTrue(millisElapsedSince(t0) < SMALL_DELAY_MS);
754                  }
755 +                long t0 = System.nanoTime();
756 +                aboutToWait.countDown();
757                  try {
758 <                    q.poll(SMALL_DELAY_MS, MILLISECONDS);
758 >                    q.poll(MEDIUM_DELAY_MS, MILLISECONDS);
759                      shouldThrow();
760 <                } catch (InterruptedException success) {}
760 >                } catch (InterruptedException success) {
761 >                    assertTrue(millisElapsedSince(t0) < MEDIUM_DELAY_MS);
762 >                }
763              }});
764  
765 <        t.start();
766 <        Thread.sleep(SHORT_DELAY_MS);
765 >        aboutToWait.await();
766 >        waitForThreadToEnterWaitState(t, SMALL_DELAY_MS);
767          t.interrupt();
768 <        t.join();
768 >        awaitTermination(t, MEDIUM_DELAY_MS);
769 >        checkEmpty(q);
770      }
771  
772      /**
773       * putFirst(null) throws NPE
774       */
775 <     public void testPutFirstNull() throws InterruptedException {
775 >    public void testPutFirstNull() throws InterruptedException {
776          try {
777              LinkedBlockingDeque q = new LinkedBlockingDeque(SIZE);
778              q.putFirst(null);
779              shouldThrow();
780          } catch (NullPointerException success) {}
781 <     }
781 >    }
782  
783      /**
784       * all elements successfully putFirst are contained
785       */
786 <     public void testPutFirst() throws InterruptedException {
787 <         LinkedBlockingDeque q = new LinkedBlockingDeque(SIZE);
788 <         for (int i = 0; i < SIZE; ++i) {
789 <             Integer I = new Integer(i);
790 <             q.putFirst(I);
791 <             assertTrue(q.contains(I));
792 <         }
793 <         assertEquals(0, q.remainingCapacity());
786 >    public void testPutFirst() throws InterruptedException {
787 >        LinkedBlockingDeque q = new LinkedBlockingDeque(SIZE);
788 >        for (int i = 0; i < SIZE; ++i) {
789 >            Integer I = new Integer(i);
790 >            q.putFirst(I);
791 >            assertTrue(q.contains(I));
792 >        }
793 >        assertEquals(0, q.remainingCapacity());
794      }
795  
796      /**
# Line 977 | Line 985 | public class LinkedBlockingDequeTest ext
985      /**
986       * putLast(null) throws NPE
987       */
988 <     public void testPutLastNull() throws InterruptedException {
988 >    public void testPutLastNull() throws InterruptedException {
989          try {
990              LinkedBlockingDeque q = new LinkedBlockingDeque(SIZE);
991              q.putLast(null);
992              shouldThrow();
993          } catch (NullPointerException success) {}
994 <     }
994 >    }
995  
996      /**
997       * all elements successfully putLast are contained
998       */
999 <     public void testPutLast() throws InterruptedException {
1000 <         LinkedBlockingDeque q = new LinkedBlockingDeque(SIZE);
1001 <         for (int i = 0; i < SIZE; ++i) {
1002 <             Integer I = new Integer(i);
1003 <             q.putLast(I);
1004 <             assertTrue(q.contains(I));
1005 <         }
1006 <         assertEquals(0, q.remainingCapacity());
999 >    public void testPutLast() throws InterruptedException {
1000 >        LinkedBlockingDeque q = new LinkedBlockingDeque(SIZE);
1001 >        for (int i = 0; i < SIZE; ++i) {
1002 >            Integer I = new Integer(i);
1003 >            q.putLast(I);
1004 >            assertTrue(q.contains(I));
1005 >        }
1006 >        assertEquals(0, q.remainingCapacity());
1007      }
1008  
1009      /**
# Line 1208 | Line 1216 | public class LinkedBlockingDequeTest ext
1216      public void testRemoveElement() {
1217          LinkedBlockingDeque q = populatedDeque(SIZE);
1218          for (int i = 1; i < SIZE; i+=2) {
1219 <            assertTrue(q.remove(new Integer(i)));
1219 >            assertTrue(q.contains(i));
1220 >            assertTrue(q.remove(i));
1221 >            assertFalse(q.contains(i));
1222 >            assertTrue(q.contains(i-1));
1223          }
1224          for (int i = 0; i < SIZE; i+=2) {
1225 <            assertTrue(q.remove(new Integer(i)));
1226 <            assertFalse(q.remove(new Integer(i+1)));
1225 >            assertTrue(q.contains(i));
1226 >            assertTrue(q.remove(i));
1227 >            assertFalse(q.contains(i));
1228 >            assertFalse(q.remove(i+1));
1229 >            assertFalse(q.contains(i+1));
1230          }
1231          assertTrue(q.isEmpty());
1232      }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines