use of java.util.concurrent.LinkedBlockingQueue in project mapdb by jankotek.
the class LinkedBlockingQueueTest method testPollInExecutor.
/**
* timed poll retrieves elements across Executor threads
*/
public void testPollInExecutor() {
final LinkedBlockingQueue q = new LinkedBlockingQueue(2);
final CheckedBarrier threadsStarted = new CheckedBarrier(2);
final ExecutorService executor = Executors.newFixedThreadPool(2);
try (PoolCleaner cleaner = cleaner(executor)) {
executor.execute(new CheckedRunnable() {
public void realRun() throws InterruptedException {
assertNull(q.poll());
threadsStarted.await();
assertSame(one, q.poll(LONG_DELAY_MS, MILLISECONDS));
checkEmpty(q);
}
});
executor.execute(new CheckedRunnable() {
public void realRun() throws InterruptedException {
threadsStarted.await();
q.put(one);
}
});
}
}
use of java.util.concurrent.LinkedBlockingQueue in project mapdb by jankotek.
the class LinkedBlockingQueueTest method testToArray.
/**
* toArray contains all elements in FIFO order
*/
public void testToArray() {
LinkedBlockingQueue q = populatedQueue(SIZE);
Object[] o = q.toArray();
for (int i = 0; i < o.length; i++) assertSame(o[i], q.poll());
}
use of java.util.concurrent.LinkedBlockingQueue in project mapdb by jankotek.
the class LinkedBlockingQueueTest method testAddAllSelf.
/**
* addAll(this) throws IllegalArgumentException
*/
public void testAddAllSelf() {
LinkedBlockingQueue q = populatedQueue(SIZE);
try {
q.addAll(q);
shouldThrow();
} catch (IllegalArgumentException success) {
}
}
use of java.util.concurrent.LinkedBlockingQueue in project mapdb by jankotek.
the class LinkedBlockingQueueTest method testRemoveAll.
/**
* removeAll(c) removes only those elements of c and reports true if changed
*/
public void testRemoveAll() {
for (int i = 1; i < SIZE; ++i) {
LinkedBlockingQueue q = populatedQueue(SIZE);
LinkedBlockingQueue p = populatedQueue(i);
assertTrue(q.removeAll(p));
assertEquals(SIZE - i, q.size());
for (int j = 0; j < i; ++j) {
Integer x = (Integer) (p.remove());
assertFalse(q.contains(x));
}
}
}
use of java.util.concurrent.LinkedBlockingQueue in project mapdb by jankotek.
the class LinkedBlockingQueueTest method testAddAll5.
/**
* Queue contains all elements, in traversal order, of successful addAll
*/
public void testAddAll5() {
Integer[] empty = new Integer[0];
Integer[] ints = new Integer[SIZE];
for (int i = 0; i < SIZE; ++i) ints[i] = new Integer(i);
LinkedBlockingQueue q = new LinkedBlockingQueue(SIZE);
assertFalse(q.addAll(Arrays.asList(empty)));
assertTrue(q.addAll(Arrays.asList(ints)));
for (int i = 0; i < SIZE; ++i) assertEquals(ints[i], q.poll());
}
Aggregations