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.6 by dl, Sun Oct 5 23:00:39 2003 UTC vs.
Revision 1.11 by dl, Sun Oct 31 14:55:14 2004 UTC

# Line 1 | Line 1
1   /*
2 < * Written by members of JCP JSR-166 Expert Group and released to the
3 < * public domain. Use, modify, and redistribute this code in any way
4 < * without acknowledgement. Other contributors include Andrew Wright,
5 < * Jeffrey Hayes, Pat Fischer, Mike Judd.
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
5 > * Other contributors include Andrew Wright, Jeffrey Hayes,
6 > * Pat Fisher, Mike Judd.
7   */
8  
9  
# Line 318 | Line 319 | public class ArrayBlockingQueueTest exte
319       * put blocks interruptibly if full
320       */
321      public void testBlockingPut() {
322 +        final ArrayBlockingQueue q = new ArrayBlockingQueue(SIZE);
323          Thread t = new Thread(new Runnable() {
324                  public void run() {
325                      int added = 0;
326                      try {
325                        ArrayBlockingQueue q = new ArrayBlockingQueue(SIZE);
327                          for (int i = 0; i < SIZE; ++i) {
328                              q.put(new Integer(i));
329                              ++added;
# Line 335 | Line 336 | public class ArrayBlockingQueueTest exte
336                  }});
337          try {
338              t.start();
339 <           Thread.sleep(SHORT_DELAY_MS);
339 >           Thread.sleep(MEDIUM_DELAY_MS);
340             t.interrupt();
341             t.join();
342          }
# Line 649 | Line 650 | public class ArrayBlockingQueueTest exte
650          assertEquals(SIZE, q.remainingCapacity());
651          q.add(one);
652          assertFalse(q.isEmpty());
653 +        assertTrue(q.contains(one));
654          q.clear();
655          assertTrue(q.isEmpty());
656      }
# Line 743 | Line 745 | public class ArrayBlockingQueueTest exte
745      }
746  
747      /**
748 <     * toArray with incompatable array type throws CCE
748 >     * toArray with incompatible array type throws CCE
749       */
750      public void testToArray1_BadArg() {
751          try {
# Line 969 | Line 971 | public class ArrayBlockingQueueTest exte
971          assertEquals(l.size(), SIZE);
972          for (int i = 0; i < SIZE; ++i)
973              assertEquals(l.get(i), new Integer(i));
974 +        q.add(zero);
975 +        q.add(one);
976 +        assertFalse(q.isEmpty());
977 +        assertTrue(q.contains(zero));
978 +        assertTrue(q.contains(one));
979 +        l.clear();
980 +        q.drainTo(l);
981 +        assertEquals(q.size(), 0);
982 +        assertEquals(l.size(), 2);
983 +        for (int i = 0; i < 2; ++i)
984 +            assertEquals(l.get(i), new Integer(i));
985      }
986  
987      /**
# Line 993 | Line 1006 | public class ArrayBlockingQueueTest exte
1006              for (int i = 0; i < SIZE; ++i)
1007                  assertEquals(l.get(i), new Integer(i));
1008              t.join();
1009 <            assertTrue(q.size() + l.size() == SIZE+1);
1009 >            assertTrue(q.size() + l.size() >= SIZE);
1010          } catch(Exception e){
1011              unexpectedException();
1012          }
# Line 1027 | Line 1040 | public class ArrayBlockingQueueTest exte
1040       * drainTo(c, n) empties first max {n, size} elements of queue into c
1041       */
1042      public void testDrainToN() {
1043 +        ArrayBlockingQueue q = new ArrayBlockingQueue(SIZE*2);
1044          for (int i = 0; i < SIZE + 2; ++i) {
1045 <            ArrayBlockingQueue q = populatedQueue(SIZE);
1045 >            for(int j = 0; j < SIZE; j++)
1046 >                assertTrue(q.offer(new Integer(j)));
1047              ArrayList l = new ArrayList();
1048              q.drainTo(l, i);
1049              int k = (i < SIZE)? i : SIZE;
1035            assertEquals(q.size(), SIZE-k);
1050              assertEquals(l.size(), k);
1051 +            assertEquals(q.size(), SIZE-k);
1052              for (int j = 0; j < k; ++j)
1053                  assertEquals(l.get(j), new Integer(j));
1054 +            while (q.poll() != null) ;
1055          }
1056      }
1057  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines