59 |
|
|
60 |
|
Object bomb() { |
61 |
|
return new Object() { |
62 |
< |
public boolean equals(Object x) { throw new AssertionError(); } |
63 |
< |
public int hashCode() { throw new AssertionError(); } |
64 |
< |
}; |
62 |
> |
public boolean equals(Object x) { throw new AssertionError(); } |
63 |
> |
public int hashCode() { throw new AssertionError(); } |
64 |
> |
}; |
65 |
|
} |
66 |
|
|
67 |
|
/** Checks properties of empty collections. */ |
140 |
|
} |
141 |
|
if (c instanceof BlockingQueue) { |
142 |
|
BlockingQueue q = (BlockingQueue) c; |
143 |
< |
assertNull(q.poll(0L, MILLISECONDS)); |
143 |
> |
assertNull(q.poll(randomExpiredTimeout(), randomTimeUnit())); |
144 |
|
} |
145 |
|
if (c instanceof BlockingDeque) { |
146 |
|
BlockingDeque q = (BlockingDeque) c; |
147 |
< |
assertNull(q.pollFirst(0L, MILLISECONDS)); |
148 |
< |
assertNull(q.pollLast(0L, MILLISECONDS)); |
147 |
> |
assertNull(q.pollFirst(randomExpiredTimeout(), randomTimeUnit())); |
148 |
> |
assertNull(q.pollLast(randomExpiredTimeout(), randomTimeUnit())); |
149 |
|
} |
150 |
|
} |
151 |
|
|
541 |
|
} catch (ConcurrentModificationException ex) { |
542 |
|
r1 = ConcurrentModificationException.class; |
543 |
|
assertFalse(impl.isConcurrent()); |
544 |
– |
} catch (UnsupportedOperationException ex) { |
545 |
– |
r1 = UnsupportedOperationException.class; |
544 |
|
} |
545 |
|
try { |
546 |
|
it2.forEachRemaining(iteratedForEachRemaining::add); |
547 |
|
r2 = iteratedForEachRemaining; |
548 |
|
} catch (ConcurrentModificationException ex) { |
549 |
|
r2 = ConcurrentModificationException.class; |
550 |
< |
} catch (UnsupportedOperationException ex) { |
553 |
< |
r2 = UnsupportedOperationException.class; |
550 |
> |
assertFalse(impl.isConcurrent()); |
551 |
|
} |
552 |
|
assertEquals(r1, r2); |
553 |
|
} |
727 |
|
} |
728 |
|
|
729 |
|
/** |
730 |
+ |
* Concurrent Spliterators, once exhausted, stay exhausted. |
731 |
+ |
*/ |
732 |
+ |
public void testStickySpliteratorExhaustion() throws Throwable { |
733 |
+ |
if (!impl.isConcurrent()) return; |
734 |
+ |
if (!testImplementationDetails) return; |
735 |
+ |
final ThreadLocalRandom rnd = ThreadLocalRandom.current(); |
736 |
+ |
final Consumer alwaysThrows = e -> { throw new AssertionError(); }; |
737 |
+ |
final Collection c = impl.emptyCollection(); |
738 |
+ |
final Spliterator s = c.spliterator(); |
739 |
+ |
if (rnd.nextBoolean()) { |
740 |
+ |
assertFalse(s.tryAdvance(alwaysThrows)); |
741 |
+ |
} else { |
742 |
+ |
s.forEachRemaining(alwaysThrows); |
743 |
+ |
} |
744 |
+ |
final Object one = impl.makeElement(1); |
745 |
+ |
// Spliterator should not notice added element |
746 |
+ |
c.add(one); |
747 |
+ |
if (rnd.nextBoolean()) { |
748 |
+ |
assertFalse(s.tryAdvance(alwaysThrows)); |
749 |
+ |
} else { |
750 |
+ |
s.forEachRemaining(alwaysThrows); |
751 |
+ |
} |
752 |
+ |
} |
753 |
+ |
|
754 |
+ |
/** |
755 |
|
* Motley crew of threads concurrently randomly hammer the collection. |
756 |
|
*/ |
757 |
|
public void testDetectRaces() throws Throwable { |