use of java.util.concurrent.ArrayBlockingQueue in project mapdb by jankotek.
the class ArrayBlockingQueueTest method testRemove.
/**
* remove removes next element, or throws NSEE if empty
*/
public void testRemove() {
ArrayBlockingQueue q = populatedQueue(SIZE);
for (int i = 0; i < SIZE; ++i) {
assertEquals(i, q.remove());
}
try {
q.remove();
shouldThrow();
} catch (NoSuchElementException success) {
}
}
use of java.util.concurrent.ArrayBlockingQueue in project mapdb by jankotek.
the class ArrayBlockingQueueTest method testTimedPoll.
/**
* timed poll with nonzero timeout succeeds when non-empty, else times out
*/
public void testTimedPoll() throws InterruptedException {
ArrayBlockingQueue q = populatedQueue(SIZE);
for (int i = 0; i < SIZE; ++i) {
long startTime = System.nanoTime();
assertEquals(i, q.poll(LONG_DELAY_MS, MILLISECONDS));
assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS);
}
long startTime = System.nanoTime();
assertNull(q.poll(timeoutMillis(), MILLISECONDS));
assertTrue(millisElapsedSince(startTime) >= timeoutMillis());
checkEmpty(q);
}
use of java.util.concurrent.ArrayBlockingQueue in project mapdb by jankotek.
the class ArrayBlockingQueueTest 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) {
ArrayBlockingQueue q = populatedQueue(SIZE);
ArrayBlockingQueue 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.ArrayBlockingQueue in project mapdb by jankotek.
the class ArrayBlockingQueueTest method testAddAll3.
/**
* addAll of a collection with any null elements throws NPE after
* possibly adding some elements
*/
public void testAddAll3() {
ArrayBlockingQueue q = new ArrayBlockingQueue(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) {
}
}
use of java.util.concurrent.ArrayBlockingQueue in project mapdb by jankotek.
the class ArrayBlockingQueueTest 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);
ArrayBlockingQueue q = new ArrayBlockingQueue(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