use of java.util.concurrent.LinkedBlockingDeque in project mapdb by jankotek.
the class LinkedBlockingDequeTest method testPop.
/**
* pop removes next element, or throws NSEE if empty
*/
public void testPop() {
LinkedBlockingDeque q = populatedDeque(SIZE);
for (int i = 0; i < SIZE; ++i) {
assertEquals(i, q.pop());
}
try {
q.pop();
shouldThrow();
} catch (NoSuchElementException success) {
}
}
use of java.util.concurrent.LinkedBlockingDeque in project mapdb by jankotek.
the class LinkedBlockingDequeTest method testInterruptedTimedPollLast.
/**
* Interrupted timed pollLast throws InterruptedException instead of
* returning timeout status
*/
public void testInterruptedTimedPollLast() throws InterruptedException {
final LinkedBlockingDeque q = populatedDeque(SIZE);
final CountDownLatch pleaseInterrupt = new CountDownLatch(1);
Thread t = newStartedThread(new CheckedRunnable() {
public void realRun() throws InterruptedException {
long startTime = System.nanoTime();
for (int i = 0; i < SIZE; ++i) {
assertEquals(SIZE - i - 1, q.pollLast(LONG_DELAY_MS, MILLISECONDS));
}
Thread.currentThread().interrupt();
try {
q.pollLast(LONG_DELAY_MS, MILLISECONDS);
shouldThrow();
} catch (InterruptedException success) {
}
assertFalse(Thread.interrupted());
pleaseInterrupt.countDown();
try {
q.pollLast(LONG_DELAY_MS, MILLISECONDS);
shouldThrow();
} catch (InterruptedException success) {
}
assertFalse(Thread.interrupted());
assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS);
}
});
await(pleaseInterrupt);
assertThreadStaysAlive(t);
t.interrupt();
awaitTermination(t);
checkEmpty(q);
}
use of java.util.concurrent.LinkedBlockingDeque in project mapdb by jankotek.
the class LinkedBlockingDequeTest method testTimedPollFirst.
/**
* timed pollFirst with nonzero timeout succeeds when non-empty, else times out
*/
public void testTimedPollFirst() throws InterruptedException {
LinkedBlockingDeque q = populatedDeque(SIZE);
for (int i = 0; i < SIZE; ++i) {
long startTime = System.nanoTime();
assertEquals(i, q.pollFirst(LONG_DELAY_MS, MILLISECONDS));
assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS);
}
long startTime = System.nanoTime();
assertNull(q.pollFirst(timeoutMillis(), MILLISECONDS));
assertTrue(millisElapsedSince(startTime) >= timeoutMillis());
checkEmpty(q);
}
use of java.util.concurrent.LinkedBlockingDeque in project mapdb by jankotek.
the class LinkedBlockingDequeTest method testIteratorRemove.
/**
* iterator.remove removes current element
*/
public void testIteratorRemove() {
final LinkedBlockingDeque q = new LinkedBlockingDeque(3);
q.add(two);
q.add(one);
q.add(three);
Iterator it = q.iterator();
it.next();
it.remove();
it = q.iterator();
assertSame(it.next(), one);
assertSame(it.next(), three);
assertFalse(it.hasNext());
}
use of java.util.concurrent.LinkedBlockingDeque in project mapdb by jankotek.
the class LinkedBlockingDequeTest method testDescendingIteratorRemove.
/**
* descendingIterator.remove removes current element
*/
public void testDescendingIteratorRemove() {
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));
Iterator it = q.descendingIterator();
assertEquals(it.next(), new Integer(1));
it.remove();
assertEquals(it.next(), new Integer(2));
it = q.descendingIterator();
assertEquals(it.next(), new Integer(2));
assertEquals(it.next(), new Integer(3));
it.remove();
assertFalse(it.hasNext());
q.remove();
}
}
Aggregations