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 { |
326 |
– |
ArrayBlockingQueue q = new ArrayBlockingQueue(SIZE); |
327 |
|
for (int i = 0; i < SIZE; ++i) { |
328 |
|
q.put(new Integer(i)); |
329 |
|
++added; |
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 |
|
} |
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 |
|
} |
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 { |
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 |
|
/** |
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 |
|
} |
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; |
1036 |
– |
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 |
|
|