use of java.util.concurrent.LinkedBlockingDeque in project mapdb by jankotek.
the class LinkedBlockingDequeTest method testPutLastNull.
/**
* putLast(null) throws NPE
*/
public void testPutLastNull() throws InterruptedException {
LinkedBlockingDeque q = new LinkedBlockingDeque(SIZE);
try {
q.putLast(null);
shouldThrow();
} catch (NullPointerException success) {
}
}
use of java.util.concurrent.LinkedBlockingDeque in project mapdb by jankotek.
the class LinkedBlockingDequeTest method testBlockingPutLast.
/**
* putLast blocks interruptibly if full
*/
public void testBlockingPutLast() throws InterruptedException {
final LinkedBlockingDeque q = new LinkedBlockingDeque(SIZE);
final CountDownLatch pleaseInterrupt = new CountDownLatch(1);
Thread t = newStartedThread(new CheckedRunnable() {
public void realRun() throws InterruptedException {
for (int i = 0; i < SIZE; ++i) q.putLast(i);
assertEquals(SIZE, q.size());
assertEquals(0, q.remainingCapacity());
Thread.currentThread().interrupt();
try {
q.putLast(99);
shouldThrow();
} catch (InterruptedException success) {
}
assertFalse(Thread.interrupted());
pleaseInterrupt.countDown();
try {
q.putLast(99);
shouldThrow();
} catch (InterruptedException success) {
}
assertFalse(Thread.interrupted());
}
});
await(pleaseInterrupt);
assertThreadStaysAlive(t);
t.interrupt();
awaitTermination(t);
assertEquals(SIZE, q.size());
assertEquals(0, q.remainingCapacity());
}
use of java.util.concurrent.LinkedBlockingDeque in project mapdb by jankotek.
the class LinkedBlockingDequeTest method testInterruptedTimedPollFirst.
/**
* Interrupted timed pollFirst throws InterruptedException instead of
* returning timeout status
*/
public void testInterruptedTimedPollFirst() 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(i, q.pollFirst(LONG_DELAY_MS, MILLISECONDS));
}
Thread.currentThread().interrupt();
try {
q.pollFirst(LONG_DELAY_MS, MILLISECONDS);
shouldThrow();
} catch (InterruptedException success) {
}
assertFalse(Thread.interrupted());
pleaseInterrupt.countDown();
try {
q.pollFirst(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);
}
use of java.util.concurrent.LinkedBlockingDeque in project mapdb by jankotek.
the class LinkedBlockingDequeTest method testOffer.
/**
* Offer succeeds if not full; fails if full
*/
public void testOffer() {
LinkedBlockingDeque q = new LinkedBlockingDeque(1);
assertTrue(q.offer(zero));
assertFalse(q.offer(one));
}
use of java.util.concurrent.LinkedBlockingDeque in project mapdb by jankotek.
the class LinkedBlockingDequeTest method testWeaklyConsistentIteration.
/**
* Modifications do not cause iterators to fail
*/
public void testWeaklyConsistentIteration() {
final LinkedBlockingDeque q = new LinkedBlockingDeque(3);
q.add(one);
q.add(two);
q.add(three);
for (Iterator it = q.iterator(); it.hasNext(); ) {
q.remove();
it.next();
}
assertEquals(0, q.size());
}
Aggregations