use of java.util.concurrent.LinkedBlockingDeque in project mapdb by jankotek.
the class LinkedBlockingDequeTest method testSize.
/**
* size changes when elements added and removed
*/
public void testSize() {
LinkedBlockingDeque q = populatedDeque(SIZE);
for (int i = 0; i < SIZE; ++i) {
assertEquals(SIZE - i, q.size());
q.removeFirst();
}
for (int i = 0; i < SIZE; ++i) {
assertEquals(i, q.size());
q.add(new Integer(i));
}
}
use of java.util.concurrent.LinkedBlockingDeque in project mapdb by jankotek.
the class LinkedBlockingDequeTest method testDescendingIterator.
/**
* Descending iterator iterates through all elements
*/
public void testDescendingIterator() {
LinkedBlockingDeque q = populatedDeque(SIZE);
int i = 0;
Iterator it = q.descendingIterator();
while (it.hasNext()) {
assertTrue(q.contains(it.next()));
++i;
}
assertEquals(i, SIZE);
assertFalse(it.hasNext());
try {
it.next();
shouldThrow();
} catch (NoSuchElementException success) {
}
}
use of java.util.concurrent.LinkedBlockingDeque in project mapdb by jankotek.
the class LinkedBlockingDequeTest method testToArray1_BadArg.
/**
* toArray(incompatible array type) throws ArrayStoreException
*/
public void testToArray1_BadArg() {
LinkedBlockingDeque q = populatedDeque(SIZE);
try {
q.toArray(new String[10]);
shouldThrow();
} catch (ArrayStoreException success) {
}
}
use of java.util.concurrent.LinkedBlockingDeque in project mapdb by jankotek.
the class LinkedBlockingDequeTest method testOfferFirst.
/**
* OfferFirst succeeds
*/
public void testOfferFirst() {
LinkedBlockingDeque q = new LinkedBlockingDeque();
assertTrue(q.offerFirst(new Integer(0)));
assertTrue(q.offerFirst(new Integer(1)));
}
use of java.util.concurrent.LinkedBlockingDeque in project mapdb by jankotek.
the class LinkedBlockingDequeTest method testPutLastWithTake.
/**
* putLast blocks interruptibly waiting for take when full
*/
public void testPutLastWithTake() 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.putLast(i);
pleaseTake.countDown();
q.putLast(86);
pleaseInterrupt.countDown();
try {
q.putLast(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());
}
Aggregations