java.util.concurrent.PriorityBlockingQueue#addAll ( )源码实例Demo

下面列出了java.util.concurrent.PriorityBlockingQueue#addAll ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

@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));
}
 
源代码2 项目: openjdk-jdk9   文件: PriorityBlockingQueueTest.java
/**
 * 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());
}
 
源代码3 项目: openjdk-jdk9   文件: PriorityBlockingQueueTest.java
/**
 * addAll(this) throws IAE
 */
public void testAddAllSelf() {
    PriorityBlockingQueue q = populatedQueue(SIZE);
    try {
        q.addAll(q);
        shouldThrow();
    } catch (IllegalArgumentException success) {}
}
 
源代码4 项目: openjdk-jdk9   文件: PriorityBlockingQueueTest.java
/**
 * 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) {}
}
 
源代码5 项目: j2objc   文件: PriorityBlockingQueueTest.java
/**
 * 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());
}
 
源代码6 项目: j2objc   文件: PriorityBlockingQueueTest.java
/**
 * addAll(this) throws IAE
 */
public void testAddAllSelf() {
    PriorityBlockingQueue q = populatedQueue(SIZE);
    try {
        q.addAll(q);
        shouldThrow();
    } catch (IllegalArgumentException success) {}
}
 
源代码7 项目: j2objc   文件: PriorityBlockingQueueTest.java
/**
 * 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) {}
}