Java Code Examples for java.util.concurrent.LinkedBlockingQueue.iterator()

The following are Jave code examples for showing how to use iterator() of the java.util.concurrent.LinkedBlockingQueue class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: openjdk-jdk10   File: LinkedBlockingQueueTest.java   View Source Code Vote up 6 votes
/**
 * iterator iterates through all elements
 */
public void testIterator() throws InterruptedException {
    LinkedBlockingQueue q = populatedQueue(SIZE);
    Iterator it = q.iterator();
    int i;
    for (i = 0; it.hasNext(); i++)
        assertTrue(q.contains(it.next()));
    assertEquals(i, SIZE);
    assertIteratorExhausted(it);

    it = q.iterator();
    for (i = 0; it.hasNext(); i++)
        assertEquals(it.next(), q.take());
    assertEquals(i, SIZE);
    assertIteratorExhausted(it);
}
 
Example 2
Project: openjdk-jdk10   File: LinkedBlockingQueueTest.java   View Source Code Vote up 6 votes
/**
 * iterator.remove removes current element
 */
public void testIteratorRemove() {
    final LinkedBlockingQueue q = new LinkedBlockingQueue(3);
    q.add(two);
    q.add(one);
    q.add(three);

    Iterator it = q.iterator();
    it.next();
    it.remove();

    it = q.iterator();
    assertSame(it.next(), one);
    assertSame(it.next(), three);
    assertFalse(it.hasNext());
}
 
Example 3
Project: openjdk-jdk10   File: LinkedBlockingQueueTest.java   View Source Code Vote up 5 votes
/**
 * iterator ordering is FIFO
 */
public void testIteratorOrdering() {
    final LinkedBlockingQueue q = new LinkedBlockingQueue(3);
    q.add(one);
    q.add(two);
    q.add(three);
    assertEquals(0, q.remainingCapacity());
    int k = 0;
    for (Iterator it = q.iterator(); it.hasNext();) {
        assertEquals(++k, it.next());
    }
    assertEquals(3, k);
}
 
Example 4
Project: openjdk-jdk10   File: LinkedBlockingQueueTest.java   View Source Code Vote up 5 votes
/**
 * Modifications do not cause iterators to fail
 */
public void testWeaklyConsistentIteration() {
    final LinkedBlockingQueue q = new LinkedBlockingQueue(3);
    q.add(one);
    q.add(two);
    q.add(three);
    for (Iterator it = q.iterator(); it.hasNext();) {
        q.remove();
        it.next();
    }
    assertEquals(0, q.size());
}