use of java.util.concurrent.LinkedBlockingDeque in project mapdb by jankotek.
the class LinkedBlockingDequeTest method testTakeFirstFromEmptyBlocksInterruptibly.
/**
* takeFirst() blocks interruptibly when empty
*/
public void testTakeFirstFromEmptyBlocksInterruptibly() {
final BlockingDeque q = new LinkedBlockingDeque();
final CountDownLatch threadStarted = new CountDownLatch(1);
Thread t = newStartedThread(new CheckedRunnable() {
public void realRun() {
threadStarted.countDown();
try {
q.takeFirst();
shouldThrow();
} catch (InterruptedException success) {
}
assertFalse(Thread.interrupted());
}
});
await(threadStarted);
assertThreadStaysAlive(t);
t.interrupt();
awaitTermination(t);
}
use of java.util.concurrent.LinkedBlockingDeque in project mapdb by jankotek.
the class LinkedBlockingDequeTest method testDescendingIteratorOrdering.
/**
* Descending iterator ordering is reverse FIFO
*/
public void testDescendingIteratorOrdering() {
final LinkedBlockingDeque q = new LinkedBlockingDeque();
for (int iters = 0; iters < 100; ++iters) {
q.add(new Integer(3));
q.add(new Integer(2));
q.add(new Integer(1));
int k = 0;
for (Iterator it = q.descendingIterator(); it.hasNext(); ) {
assertEquals(++k, it.next());
}
assertEquals(3, k);
q.remove();
q.remove();
q.remove();
}
}
use of java.util.concurrent.LinkedBlockingDeque in project mapdb by jankotek.
the class LinkedBlockingDequeTest method testPushNull.
/**
* push(null) throws NPE
*/
public void testPushNull() {
LinkedBlockingDeque q = new LinkedBlockingDeque(1);
try {
q.push(null);
shouldThrow();
} catch (NullPointerException success) {
}
}
use of java.util.concurrent.LinkedBlockingDeque in project mapdb by jankotek.
the class LinkedBlockingDequeTest method testAddLast.
/**
* peekLast returns element inserted with addLast
*/
public void testAddLast() {
LinkedBlockingDeque q = populatedDeque(3);
q.pollLast();
q.addLast(four);
assertSame(four, q.peekLast());
}
use of java.util.concurrent.LinkedBlockingDeque in project mapdb by jankotek.
the class LinkedBlockingDequeTest method testRemoveFirst.
/**
* removeFirst() removes first element, or throws NSEE if empty
*/
public void testRemoveFirst() {
LinkedBlockingDeque q = populatedDeque(SIZE);
for (int i = 0; i < SIZE; ++i) {
assertEquals(i, q.removeFirst());
}
try {
q.removeFirst();
shouldThrow();
} catch (NoSuchElementException success) {
}
assertNull(q.peekFirst());
}
Aggregations