Java Code Examples for java.util.concurrent.PriorityBlockingQueue#addAll()

The following examples show how to use java.util.concurrent.PriorityBlockingQueue#addAll() . 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 File: PriorityBlockingQueueIntegrationTest.java    From tutorials with MIT License 6 votes vote down vote up
@Test
public void whenPollingEmptyQueue_thenShouldBlockThread() throws InterruptedException {
    PriorityBlockingQueue<Integer> queue = new PriorityBlockingQueue<>();

    final Thread thread = new Thread(() -> {
        LOG.debug("Polling...");
        while (true) {
            try {
                Integer poll = queue.take();
                LOG.debug("Polled: " + poll);
            } catch (InterruptedException ignored) {
            }
        }
    });
    thread.start();

    Thread.sleep(TimeUnit.SECONDS.toMillis(5));
    LOG.debug("Adding to queue");

    queue.addAll(newArrayList(1, 5, 6, 1, 2, 6, 7));
    Thread.sleep(TimeUnit.SECONDS.toMillis(1));
}
 
Example 2
Source File: PriorityBlockingQueueTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * The comparator used in constructor is used
 */
public void testConstructor7() {
    MyReverseComparator cmp = new MyReverseComparator();
    PriorityBlockingQueue q = new PriorityBlockingQueue(SIZE, cmp);
    assertEquals(cmp, q.comparator());
    Integer[] ints = new Integer[SIZE];
    for (int i = 0; i < SIZE; ++i)
        ints[i] = new Integer(i);
    q.addAll(Arrays.asList(ints));
    for (int i = SIZE - 1; i >= 0; --i)
        assertEquals(ints[i], q.poll());
}
 
Example 3
Source File: PriorityBlockingQueueTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * addAll(this) throws IAE
 */
public void testAddAllSelf() {
    PriorityBlockingQueue q = populatedQueue(SIZE);
    try {
        q.addAll(q);
        shouldThrow();
    } catch (IllegalArgumentException success) {}
}
 
Example 4
Source File: PriorityBlockingQueueTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * addAll of a collection with any null elements throws NPE after
 * possibly adding some elements
 */
public void testAddAll3() {
    PriorityBlockingQueue q = new PriorityBlockingQueue(SIZE);
    Integer[] ints = new Integer[SIZE];
    for (int i = 0; i < SIZE - 1; ++i)
        ints[i] = new Integer(i);
    try {
        q.addAll(Arrays.asList(ints));
        shouldThrow();
    } catch (NullPointerException success) {}
}
 
Example 5
Source File: PriorityBlockingQueueTest.java    From j2objc with Apache License 2.0 5 votes vote down vote up
/**
 * The comparator used in constructor is used
 */
public void testConstructor7() {
    MyReverseComparator cmp = new MyReverseComparator();
    PriorityBlockingQueue q = new PriorityBlockingQueue(SIZE, cmp);
    assertEquals(cmp, q.comparator());
    Integer[] ints = new Integer[SIZE];
    for (int i = 0; i < SIZE; ++i)
        ints[i] = new Integer(i);
    q.addAll(Arrays.asList(ints));
    for (int i = SIZE - 1; i >= 0; --i)
        assertEquals(ints[i], q.poll());
}
 
Example 6
Source File: PriorityBlockingQueueTest.java    From j2objc with Apache License 2.0 5 votes vote down vote up
/**
 * addAll(this) throws IAE
 */
public void testAddAllSelf() {
    PriorityBlockingQueue q = populatedQueue(SIZE);
    try {
        q.addAll(q);
        shouldThrow();
    } catch (IllegalArgumentException success) {}
}
 
Example 7
Source File: PriorityBlockingQueueTest.java    From j2objc with Apache License 2.0 5 votes vote down vote up
/**
 * addAll of a collection with any null elements throws NPE after
 * possibly adding some elements
 */
public void testAddAll3() {
    PriorityBlockingQueue q = new PriorityBlockingQueue(SIZE);
    Integer[] ints = new Integer[SIZE];
    for (int i = 0; i < SIZE - 1; ++i)
        ints[i] = new Integer(i);
    try {
        q.addAll(Arrays.asList(ints));
        shouldThrow();
    } catch (NullPointerException success) {}
}