use of java.util.concurrent.LinkedBlockingDeque in project mapdb by jankotek.
the class LinkedBlockingDequeTest method testPutFirstNull.
/**
* putFirst(null) throws NPE
*/
public void testPutFirstNull() throws InterruptedException {
LinkedBlockingDeque q = new LinkedBlockingDeque(SIZE);
try {
q.putFirst(null);
shouldThrow();
} catch (NullPointerException success) {
}
}
use of java.util.concurrent.LinkedBlockingDeque in project mapdb by jankotek.
the class LinkedBlockingDequeTest method testPutWithTake.
/**
* put blocks interruptibly waiting for take when full
*/
public void testPutWithTake() throws InterruptedException {
final int capacity = 2;
final LinkedBlockingDeque q = new LinkedBlockingDeque(capacity);
final CountDownLatch pleaseTake = new CountDownLatch(1);
final CountDownLatch pleaseInterrupt = new CountDownLatch(1);
Thread t = newStartedThread(new CheckedRunnable() {
public void realRun() throws InterruptedException {
for (int i = 0; i < capacity; i++) q.put(i);
pleaseTake.countDown();
q.put(86);
pleaseInterrupt.countDown();
try {
q.put(99);
shouldThrow();
} catch (InterruptedException success) {
}
assertFalse(Thread.interrupted());
}
});
await(pleaseTake);
assertEquals(0, q.remainingCapacity());
assertEquals(0, q.take());
await(pleaseInterrupt);
assertThreadStaysAlive(t);
t.interrupt();
awaitTermination(t);
assertEquals(0, q.remainingCapacity());
}
use of java.util.concurrent.LinkedBlockingDeque in project mapdb by jankotek.
the class LinkedBlockingDequeTest method testEmptyFull.
/**
* Deque transitions from empty to full when elements added
*/
public void testEmptyFull() {
LinkedBlockingDeque q = new LinkedBlockingDeque(2);
assertTrue(q.isEmpty());
assertEquals("should have room for 2", 2, q.remainingCapacity());
q.add(one);
assertFalse(q.isEmpty());
q.add(two);
assertFalse(q.isEmpty());
assertEquals(0, q.remainingCapacity());
assertFalse(q.offer(three));
}
use of java.util.concurrent.LinkedBlockingDeque in project mapdb by jankotek.
the class LinkedBlockingDequeTest method testTakeFirstFromEmptyAfterInterrupt.
/**
* takeFirst() throws InterruptedException immediately if interrupted
* before waiting
*/
public void testTakeFirstFromEmptyAfterInterrupt() {
final BlockingDeque q = new LinkedBlockingDeque();
Thread t = newStartedThread(new CheckedRunnable() {
public void realRun() {
Thread.currentThread().interrupt();
try {
q.takeFirst();
shouldThrow();
} catch (InterruptedException success) {
}
assertFalse(Thread.interrupted());
}
});
awaitTermination(t);
}
use of java.util.concurrent.LinkedBlockingDeque in project mapdb by jankotek.
the class LinkedBlockingDequeTest method testTimedPollLast0.
/**
* timed pollLast with zero timeout succeeds when non-empty, else times out
*/
public void testTimedPollLast0() throws InterruptedException {
LinkedBlockingDeque q = populatedDeque(SIZE);
for (int i = 0; i < SIZE; ++i) {
assertEquals(SIZE - i - 1, q.pollLast(0, MILLISECONDS));
}
assertNull(q.pollLast(0, MILLISECONDS));
}
Aggregations