use of java.util.concurrent.ConcurrentLinkedDeque in project mapdb by jankotek.
the class ConcurrentLinkedDequeTest method testPeekLast.
/**
* peekLast() returns next element, or null if empty
*/
public void testPeekLast() {
ConcurrentLinkedDeque q = populatedDeque(SIZE);
for (int i = SIZE - 1; i >= 0; --i) {
assertEquals(i, q.peekLast());
assertEquals(i, q.pollLast());
assertTrue(q.peekLast() == null || !q.peekLast().equals(i));
}
assertNull(q.peekLast());
}
use of java.util.concurrent.ConcurrentLinkedDeque in project mapdb by jankotek.
the class ConcurrentLinkedDequeTest method testDescendingIteratorRemove.
/**
* descendingIterator.remove() removes current element
*/
public void testDescendingIteratorRemove() {
final ConcurrentLinkedDeque q = new ConcurrentLinkedDeque();
final Random rng = new Random();
for (int iters = 0; iters < 100; ++iters) {
int max = rng.nextInt(5) + 2;
int split = rng.nextInt(max - 1) + 1;
for (int j = max; j >= 1; --j) q.add(new Integer(j));
Iterator it = q.descendingIterator();
for (int j = 1; j <= split; ++j) assertEquals(it.next(), new Integer(j));
it.remove();
assertEquals(it.next(), new Integer(split + 1));
for (int j = 1; j <= split; ++j) q.remove(new Integer(j));
it = q.descendingIterator();
for (int j = split + 1; j <= max; ++j) {
assertEquals(it.next(), new Integer(j));
it.remove();
}
assertFalse(it.hasNext());
assertTrue(q.isEmpty());
}
}
use of java.util.concurrent.ConcurrentLinkedDeque in project mapdb by jankotek.
the class ConcurrentLinkedDequeTest method testPeek.
/**
* peek() returns next element, or null if empty
*/
public void testPeek() {
ConcurrentLinkedDeque q = populatedDeque(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.ConcurrentLinkedDeque in project mapdb by jankotek.
the class ConcurrentLinkedDequeTest method testAddFirst.
/**
* addFirst(x) succeeds
*/
public void testAddFirst() {
ConcurrentLinkedDeque q = new ConcurrentLinkedDeque();
q.addFirst(zero);
q.addFirst(one);
assertSame(one, q.peekFirst());
assertSame(zero, q.peekLast());
}
use of java.util.concurrent.ConcurrentLinkedDeque in project mapdb by jankotek.
the class ConcurrentLinkedDequeTest method testAddLast.
/**
* addLast(x) succeeds
*/
public void testAddLast() {
ConcurrentLinkedDeque q = new ConcurrentLinkedDeque();
q.addLast(zero);
q.addLast(one);
assertSame(zero, q.peekFirst());
assertSame(one, q.peekLast());
}
Aggregations