use of java.util.concurrent.ArrayBlockingQueue in project mapdb by jankotek.
the class ArrayBlockingQueueTest method testAdd.
/**
* add succeeds if not full; throws ISE if full
*/
public void testAdd() {
ArrayBlockingQueue q = new ArrayBlockingQueue(SIZE);
for (int i = 0; i < SIZE; ++i) {
assertTrue(q.add(new Integer(i)));
}
assertEquals(0, q.remainingCapacity());
try {
q.add(new Integer(SIZE));
shouldThrow();
} catch (IllegalStateException success) {
}
}
use of java.util.concurrent.ArrayBlockingQueue in project mapdb by jankotek.
the class ArrayBlockingQueueTest method testEmptyFull.
/**
* Queue transitions from empty to full when elements added
*/
public void testEmptyFull() {
ArrayBlockingQueue q = new ArrayBlockingQueue(2);
assertTrue(q.isEmpty());
assertEquals(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.ArrayBlockingQueue in project mapdb by jankotek.
the class ArrayBlockingQueueTest method testContains.
/**
* contains(x) reports true when elements added but not yet removed
*/
public void testContains() {
ArrayBlockingQueue q = populatedQueue(SIZE);
for (int i = 0; i < SIZE; ++i) {
assertTrue(q.contains(new Integer(i)));
assertEquals(i, q.poll());
assertFalse(q.contains(new Integer(i)));
}
}
use of java.util.concurrent.ArrayBlockingQueue in project mapdb by jankotek.
the class ArrayBlockingQueueTest method testClear.
/**
* clear removes all elements
*/
public void testClear() {
ArrayBlockingQueue q = populatedQueue(SIZE);
q.clear();
assertTrue(q.isEmpty());
assertEquals(0, q.size());
assertEquals(SIZE, q.remainingCapacity());
q.add(one);
assertFalse(q.isEmpty());
assertTrue(q.contains(one));
q.clear();
assertTrue(q.isEmpty());
}
use of java.util.concurrent.ArrayBlockingQueue in project mapdb by jankotek.
the class ArrayBlockingQueueTest method testPut.
/**
* all elements successfully put are contained
*/
public void testPut() throws InterruptedException {
ArrayBlockingQueue q = new ArrayBlockingQueue(SIZE);
for (int i = 0; i < SIZE; ++i) {
Integer x = new Integer(i);
q.put(x);
assertTrue(q.contains(x));
}
assertEquals(0, q.remainingCapacity());
}
Aggregations