557 |
|
if (!impl.isConcurrent()) return; |
558 |
|
final ThreadLocalRandom rnd = ThreadLocalRandom.current(); |
559 |
|
final Collection c = impl.emptyCollection(); |
560 |
< |
final long testDurationMillis = timeoutMillis(); |
560 |
> |
final long testDurationMillis |
561 |
> |
= expensiveTests ? LONG_DELAY_MS : timeoutMillis(); |
562 |
|
final AtomicBoolean done = new AtomicBoolean(false); |
563 |
|
final Object one = impl.makeElement(1); |
564 |
|
final Object two = impl.makeElement(2); |
565 |
+ |
final Consumer checkSanity = x -> assertTrue(x == one || x == two); |
566 |
+ |
final Consumer<Object[]> checkArraySanity = array -> { |
567 |
+ |
// assertTrue(array.length <= 2); // duplicates are permitted |
568 |
+ |
for (Object x : array) assertTrue(x == one || x == two); |
569 |
+ |
}; |
570 |
|
final Object[] emptyArray = |
571 |
|
(Object[]) java.lang.reflect.Array.newInstance(one.getClass(), 0); |
572 |
|
final List<Future<?>> futures; |
573 |
|
final Phaser threadsStarted = new Phaser(1); // register this thread |
568 |
– |
final Consumer checkSanity = x -> assertTrue(x == one || x == two); |
574 |
|
final Runnable[] frobbers = { |
575 |
|
() -> c.forEach(checkSanity), |
576 |
|
() -> c.stream().forEach(checkSanity), |
586 |
|
do {} while (s.tryAdvance(checkSanity)); |
587 |
|
}, |
588 |
|
() -> { for (Object x : c) checkSanity.accept(x); }, |
589 |
< |
() -> { for (Object x : c.toArray()) checkSanity.accept(x); }, |
590 |
< |
() -> { for (Object x : c.toArray(emptyArray)) checkSanity.accept(x); }, |
589 |
> |
() -> checkArraySanity.accept(c.toArray()), |
590 |
> |
() -> checkArraySanity.accept(c.toArray(emptyArray)), |
591 |
|
() -> { |
592 |
|
assertTrue(c.add(one)); |
593 |
|
assertTrue(c.contains(one)); |