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 { |