use of java.util.concurrent.ConcurrentLinkedQueue in project mapdb by jankotek.
the class ConcurrentLinkedQueueTest method testPeek.
/**
* peek returns next element, or null if empty
*/
public void testPeek() {
ConcurrentLinkedQueue q = populatedQueue(SIZE);
for (int i = 0; i < SIZE; ++i) {
assertEquals(i, q.peek());
assertEquals(i, q.poll());
assertTrue(q.peek() == null || !q.peek().equals(i));
}
assertNull(q.peek());
}
use of java.util.concurrent.ConcurrentLinkedQueue in project mapdb by jankotek.
the class ConcurrentLinkedQueueTest method testToArray.
/**
* toArray contains all elements in FIFO order
*/
public void testToArray() {
ConcurrentLinkedQueue q = populatedQueue(SIZE);
Object[] o = q.toArray();
for (int i = 0; i < o.length; i++) assertSame(o[i], q.poll());
}
use of java.util.concurrent.ConcurrentLinkedQueue in project mapdb by jankotek.
the class ConcurrentLinkedQueueTest method testRemoveElement.
/**
* remove(x) removes x and returns true if present
*/
public void testRemoveElement() {
ConcurrentLinkedQueue q = populatedQueue(SIZE);
for (int i = 1; i < SIZE; i += 2) {
assertTrue(q.contains(i));
assertTrue(q.remove(i));
assertFalse(q.contains(i));
assertTrue(q.contains(i - 1));
}
for (int i = 0; i < SIZE; i += 2) {
assertTrue(q.contains(i));
assertTrue(q.remove(i));
assertFalse(q.contains(i));
assertFalse(q.remove(i + 1));
assertFalse(q.contains(i + 1));
}
assertTrue(q.isEmpty());
}
use of java.util.concurrent.ConcurrentLinkedQueue in project mapdb by jankotek.
the class ConcurrentLinkedQueueTest method testRemove.
/**
* remove removes next element, or throws NSEE if empty
*/
public void testRemove() {
ConcurrentLinkedQueue q = populatedQueue(SIZE);
for (int i = 0; i < SIZE; ++i) {
assertEquals(i, q.remove());
}
try {
q.remove();
shouldThrow();
} catch (NoSuchElementException success) {
}
}
use of java.util.concurrent.ConcurrentLinkedQueue in project mapdb by jankotek.
the class ConcurrentLinkedQueueTest method testIterator.
/**
* iterator iterates through all elements
*/
public void testIterator() {
ConcurrentLinkedQueue q = populatedQueue(SIZE);
Iterator it = q.iterator();
int i;
for (i = 0; it.hasNext(); i++) assertTrue(q.contains(it.next()));
assertEquals(i, SIZE);
assertIteratorExhausted(it);
}
Aggregations