use of java.util.concurrent.LinkedBlockingDeque in project mapdb by jankotek.
the class LinkedBlockingDequeTest method testRetainAll.
/**
* retainAll(c) retains only those elements of c and reports true if changed
*/
public void testRetainAll() {
LinkedBlockingDeque q = populatedDeque(SIZE);
LinkedBlockingDeque p = populatedDeque(SIZE);
for (int i = 0; i < SIZE; ++i) {
boolean changed = q.retainAll(p);
if (i == 0)
assertFalse(changed);
else
assertTrue(changed);
assertTrue(q.containsAll(p));
assertEquals(SIZE - i, q.size());
p.remove();
}
}
use of java.util.concurrent.LinkedBlockingDeque in project mapdb by jankotek.
the class LinkedBlockingDequeTest method testContainsAll.
/**
* containsAll(c) is true when c contains a subset of elements
*/
public void testContainsAll() {
LinkedBlockingDeque q = populatedDeque(SIZE);
LinkedBlockingDeque p = new LinkedBlockingDeque(SIZE);
for (int i = 0; i < SIZE; ++i) {
assertTrue(q.containsAll(p));
assertFalse(p.containsAll(q));
p.add(new Integer(i));
}
assertTrue(p.containsAll(q));
}
use of java.util.concurrent.LinkedBlockingDeque in project mapdb by jankotek.
the class LinkedBlockingDequeTest method testBlockingTakeFirst.
/**
* takeFirst removes existing elements until empty, then blocks interruptibly
*/
public void testBlockingTakeFirst() throws InterruptedException {
final LinkedBlockingDeque q = populatedDeque(SIZE);
final CountDownLatch pleaseInterrupt = new CountDownLatch(1);
Thread t = newStartedThread(new CheckedRunnable() {
public void realRun() throws InterruptedException {
for (int i = 0; i < SIZE; ++i) {
assertEquals(i, q.takeFirst());
}
Thread.currentThread().interrupt();
try {
q.takeFirst();
shouldThrow();
} catch (InterruptedException success) {
}
assertFalse(Thread.interrupted());
pleaseInterrupt.countDown();
try {
q.takeFirst();
shouldThrow();
} catch (InterruptedException success) {
}
assertFalse(Thread.interrupted());
}
});
await(pleaseInterrupt);
assertThreadStaysAlive(t);
t.interrupt();
awaitTermination(t);
}
use of java.util.concurrent.LinkedBlockingDeque in project mapdb by jankotek.
the class LinkedBlockingDequeTest method testPollLast.
/**
* pollLast succeeds unless empty
*/
public void testPollLast() {
LinkedBlockingDeque q = populatedDeque(SIZE);
for (int i = SIZE - 1; i >= 0; --i) {
assertEquals(i, q.pollLast());
}
assertNull(q.pollLast());
}
use of java.util.concurrent.LinkedBlockingDeque in project mapdb by jankotek.
the class LinkedBlockingDequeTest method testTimedPollFirst0.
/**
* timed pollFirst with zero timeout succeeds when non-empty, else times out
*/
public void testTimedPollFirst0() throws InterruptedException {
LinkedBlockingDeque q = populatedDeque(SIZE);
for (int i = 0; i < SIZE; ++i) {
assertEquals(i, q.pollFirst(0, MILLISECONDS));
}
assertNull(q.pollFirst(0, MILLISECONDS));
}
Aggregations