src/test/java/org/mapdb/jsr166Tests/Collection8Test.java
public void testElementRemovalDuringTraversal() {
        Collection c = impl.emptyCollection();
        ThreadLocalRandom rnd = ThreadLocalRandom.current();
        int n = rnd.nextInt(6);
        ArrayList copy = new ArrayList();
        for (int i = 0; i < n; i++) {
            Object x = impl.makeElement(i);
            copy.add(x);
            c.add(x);
        }
        ArrayList iterated = new ArrayList();
        ArrayList spliterated = new ArrayList();
        Spliterator s = c.spliterator();
        Iterator it = c.iterator();
        for (int i = rnd.nextInt(n + 1); --i >= 0; ) {
            assertTrue(s.tryAdvance(spliterated::add));
            if (rnd.nextBoolean()) assertTrue(it.hasNext());
            iterated.add(it.next());
        }
        Consumer alwaysThrows = e -> { throw new AssertionError(); };
        if (s.hasCharacteristics(Spliterator.CONCURRENT)) {
            c.clear();
            if (testImplementationDetails
                && !(c instanceof java.util.concurrent.ArrayBlockingQueue)) {
                if (rnd.nextBoolean())
                    assertFalse(s.tryAdvance(alwaysThrows));
                else
                    s.forEachRemaining(alwaysThrows);
            }
            if (it.hasNext()) iterated.add(it.next());
            if (rnd.nextBoolean()) assertIteratorExhausted(it);
        }
        assertTrue(copy.containsAll(iterated));
        assertTrue(copy.containsAll(spliterated));
    }
/**
     * All elements removed in the middle of CONCURRENT traversal.
     */
All elements removed in the middle of CONCURRENT traversal.
All elements removed in the middle of CONCURRENT traversal .
public void testElementRemovalDuringTraversal() {
        Collection c = impl.emptyCollection();
        ThreadLocalRandom rnd = ThreadLocalRandom.current();
        int n = rnd.nextInt(6);
        ArrayList copy = new ArrayList();
        for (int i = 0; i < n; i++) {
            Object x = impl.makeElement(i);
            copy.add(x);
            c.add(x);
        }
        ArrayList iterated = new ArrayList();
        ArrayList spliterated = new ArrayList();
        Spliterator s = c.spliterator();
        Iterator it = c.iterator();
        for (int i = rnd.nextInt(n + 1); --i >= 0; ) {
            assertTrue(s.tryAdvance(spliterated::add));
            if (rnd.nextBoolean()) assertTrue(it.hasNext());
            iterated.add(it.next());
        }
        Consumer alwaysThrows = e -> { throw new AssertionError(); };
        if (s.hasCharacteristics(Spliterator.CONCURRENT)) {
            c.clear();
            if (testImplementationDetails
                && !(c instanceof java.util.concurrent.ArrayBlockingQueue)) {
                if (rnd.nextBoolean())
                    assertFalse(s.tryAdvance(alwaysThrows));
                else
                    s.forEachRemaining(alwaysThrows);
            }
            if (it.hasNext()) iterated.add(it.next());
            if (rnd.nextBoolean()) assertIteratorExhausted(it);
        }
        assertTrue(copy.containsAll(iterated));
        assertTrue(copy.containsAll(spliterated));
    }
public void testElementRemovalDuringTraversal ( ) { Collection c = impl . emptyCollection ( ) ; ThreadLocalRandom rnd = ThreadLocalRandom . current ( ) ; int n = rnd . nextInt ( 6 ) ; ArrayList copy = new ArrayList ( ) ; for ( int i = 0 ; i < n ; i ++ ) { Object x = impl . makeElement ( i ) ; copy . add ( x ) ; c . add ( x ) ; } ArrayList iterated = new ArrayList ( ) ; ArrayList spliterated = new ArrayList ( ) ; Spliterator s = c . spliterator ( ) ; Iterator it = c . iterator ( ) ; for ( int i = rnd . nextInt ( n + 1 ) ; -- i >= 0 ; ) { assertTrue ( s . tryAdvance ( spliterated :: add ) ) ; if ( rnd . nextBoolean ( ) ) assertTrue ( it . hasNext ( ) ) ; iterated . add ( it . next ( ) ) ; } Consumer alwaysThrows = e -> { throw new AssertionError ( ) ; } ; if ( s . hasCharacteristics ( Spliterator . CONCURRENT ) ) { c . clear ( ) ; if ( testImplementationDetails && ! ( c instanceof java . util . concurrent . ArrayBlockingQueue ) ) { if ( rnd . nextBoolean ( ) ) assertFalse ( s . tryAdvance ( alwaysThrows ) ) ; else s . forEachRemaining ( alwaysThrows ) ; } if ( it . hasNext ( ) ) iterated . add ( it . next ( ) ) ; if ( rnd . nextBoolean ( ) ) assertIteratorExhausted ( it ) ; } assertTrue ( copy . containsAll ( iterated ) ) ; assertTrue ( copy . containsAll ( spliterated ) ) ; }
All elements removed in the middle of CONCURRENT traversal.
All elements removed in the middle of CONCURRENT traversal .