Java Code Examples for java.util.concurrent.LinkedBlockingDeque#getFirst()

The following examples show how to use java.util.concurrent.LinkedBlockingDeque#getFirst() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: rapid   File: PaxosTests.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Wait and then verify all consensus decisions
 *
 * @param expectedSize expected size of each cluster
 * @param maxTries number of tries to checkSubject if the cluster has stabilized.
 * @param intervalInMs the time duration between checks.
 * @param decisions the reported consensus decisions
 */
private void waitAndVerifyAgreement(final int expectedSize, final int maxTries, final int intervalInMs,
                                    final LinkedBlockingDeque<List<Endpoint>> decisions)
                                    throws InterruptedException {
    int tries = maxTries;
    while (--tries > 0) {
        if (decisions.size() != expectedSize) {
            Thread.sleep(intervalInMs);
        }
        else {
            break;
        }
    }

    assertEquals(expectedSize, decisions.size());
    if (expectedSize > 0) {
        final List<Endpoint> first = decisions.getFirst();
        assertAll(first, decisions);
    }
}
 
Example 2
/**
 * getFirst() returns first element, or throws NSEE if empty
 */
public void testFirstElement() {
    LinkedBlockingDeque q = populatedDeque(SIZE);
    for (int i = 0; i < SIZE; ++i) {
        assertEquals(i, q.getFirst());
        assertEquals(i, q.pollFirst());
    }
    try {
        q.getFirst();
        shouldThrow();
    } catch (NoSuchElementException success) {}
    assertNull(q.peekFirst());
}
 
Example 3
Source Project: j2objc   File: LinkedBlockingDequeTest.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * getFirst() returns first element, or throws NSEE if empty
 */
public void testFirstElement() {
    LinkedBlockingDeque q = populatedDeque(SIZE);
    for (int i = 0; i < SIZE; ++i) {
        assertEquals(i, q.getFirst());
        assertEquals(i, q.pollFirst());
    }
    try {
        q.getFirst();
        shouldThrow();
    } catch (NoSuchElementException success) {}
    assertNull(q.peekFirst());
}