12 |
|
import java.util.Collection; |
13 |
|
import java.util.Iterator; |
14 |
|
import java.util.NoSuchElementException; |
15 |
– |
import java.util.Queue; |
15 |
|
import java.util.concurrent.BlockingQueue; |
16 |
|
import java.util.concurrent.CountDownLatch; |
17 |
|
import java.util.concurrent.Executors; |
165 |
|
}}); |
166 |
|
|
167 |
|
await(pleaseTake); |
168 |
< |
assertEquals(q.remainingCapacity(), 0); |
168 |
> |
assertEquals(0, q.remainingCapacity()); |
169 |
|
try { assertSame(one, q.take()); } |
170 |
|
catch (InterruptedException e) { threadUnexpectedException(e); } |
171 |
|
|
173 |
|
assertThreadStaysAlive(t); |
174 |
|
t.interrupt(); |
175 |
|
awaitTermination(t); |
176 |
< |
assertEquals(q.remainingCapacity(), 0); |
176 |
> |
assertEquals(0, q.remainingCapacity()); |
177 |
|
} |
178 |
|
|
179 |
|
/** |
321 |
|
} |
322 |
|
|
323 |
|
/** |
325 |
– |
* remove(x) returns false |
326 |
– |
*/ |
327 |
– |
public void testRemoveElement() { testRemoveElement(false); } |
328 |
– |
public void testRemoveElement_fair() { testRemoveElement(true); } |
329 |
– |
public void testRemoveElement(boolean fair) { |
330 |
– |
final SynchronousQueue q = new SynchronousQueue(fair); |
331 |
– |
assertFalse(q.remove(zero)); |
332 |
– |
assertTrue(q.isEmpty()); |
333 |
– |
} |
334 |
– |
|
335 |
– |
/** |
324 |
|
* contains returns false |
325 |
|
*/ |
326 |
|
public void testContains() { testContains(false); } |
388 |
|
public void testToArray(boolean fair) { |
389 |
|
final SynchronousQueue q = new SynchronousQueue(fair); |
390 |
|
Object[] o = q.toArray(); |
391 |
< |
assertEquals(o.length, 0); |
391 |
> |
assertEquals(0, o.length); |
392 |
|
} |
393 |
|
|
394 |
|
/** |
395 |
< |
* toArray(a) is nulled at position 0 |
395 |
> |
* toArray(Integer array) returns its argument with the first |
396 |
> |
* element (if present) nulled out |
397 |
|
*/ |
398 |
|
public void testToArray2() { testToArray2(false); } |
399 |
|
public void testToArray2_fair() { testToArray2(true); } |
400 |
|
public void testToArray2(boolean fair) { |
401 |
< |
final SynchronousQueue q = new SynchronousQueue(fair); |
402 |
< |
Integer[] ints = new Integer[1]; |
403 |
< |
assertNull(ints[0]); |
401 |
> |
final SynchronousQueue<Integer> q |
402 |
> |
= new SynchronousQueue<Integer>(fair); |
403 |
> |
Integer[] a; |
404 |
> |
|
405 |
> |
a = new Integer[0]; |
406 |
> |
assertSame(a, q.toArray(a)); |
407 |
> |
|
408 |
> |
a = new Integer[3]; |
409 |
> |
Arrays.fill(a, 42); |
410 |
> |
assertSame(a, q.toArray(a)); |
411 |
> |
assertNull(a[0]); |
412 |
> |
for (int i = 1; i < a.length; i++) |
413 |
> |
assertEquals(42, (int) a[i]); |
414 |
|
} |
415 |
|
|
416 |
|
/** |
522 |
|
/** |
523 |
|
* a deserialized serialized queue is usable |
524 |
|
*/ |
525 |
< |
public void testSerialization() { testSerialization(false); } |
526 |
< |
public void testSerialization_fair() { testSerialization(true); } |
527 |
< |
public void testSerialization(boolean fair) { |
528 |
< |
final SynchronousQueue x = new SynchronousQueue(fair); |
529 |
< |
final SynchronousQueue y = serialClone(x); |
530 |
< |
assertTrue(x != y); |
531 |
< |
assertTrue(x.isEmpty()); |
532 |
< |
assertTrue(y.isEmpty()); |
525 |
> |
public void testSerialization() { |
526 |
> |
final SynchronousQueue x = new SynchronousQueue(); |
527 |
> |
final SynchronousQueue y = new SynchronousQueue(false); |
528 |
> |
final SynchronousQueue z = new SynchronousQueue(true); |
529 |
> |
assertSerialEquals(x, y); |
530 |
> |
assertNotSerialEquals(x, z); |
531 |
> |
SynchronousQueue[] qs = { x, y, z }; |
532 |
> |
for (SynchronousQueue q : qs) { |
533 |
> |
SynchronousQueue clone = serialClone(q); |
534 |
> |
assertNotSame(q, clone); |
535 |
> |
assertSerialEquals(q, clone); |
536 |
> |
assertTrue(clone.isEmpty()); |
537 |
> |
assertEquals(0, clone.size()); |
538 |
> |
assertEquals(0, clone.remainingCapacity()); |
539 |
> |
assertFalse(clone.offer(zero)); |
540 |
> |
} |
541 |
|
} |
542 |
|
|
543 |
|
/** |
549 |
|
final SynchronousQueue q = new SynchronousQueue(fair); |
550 |
|
ArrayList l = new ArrayList(); |
551 |
|
q.drainTo(l); |
552 |
< |
assertEquals(q.size(), 0); |
553 |
< |
assertEquals(l.size(), 0); |
552 |
> |
assertEquals(0, q.size()); |
553 |
> |
assertEquals(0, l.size()); |
554 |
|
} |
555 |
|
|
556 |
|
/** |
605 |
|
awaitTermination(t2); |
606 |
|
} |
607 |
|
|
608 |
+ |
/** |
609 |
+ |
* remove(null), contains(null) always return false |
610 |
+ |
*/ |
611 |
+ |
public void testNeverContainsNull() { |
612 |
+ |
Collection<?> q = new SynchronousQueue(); |
613 |
+ |
assertFalse(q.contains(null)); |
614 |
+ |
assertFalse(q.remove(null)); |
615 |
+ |
} |
616 |
+ |
|
617 |
|
} |