use of java.util.concurrent.ConcurrentLinkedDeque in project mapdb by jankotek.
the class ConcurrentLinkedDequeTest method testIteratorRemove.
/**
* iterator.remove() removes current element
*/
public void testIteratorRemove() {
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 = 1; j <= max; ++j) q.add(new Integer(j));
Iterator it = q.iterator();
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.iterator();
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 testRemoveElement.
/**
* remove(x) removes x and returns true if present
*/
public void testRemoveElement() {
ConcurrentLinkedDeque q = populatedDeque(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.ConcurrentLinkedDeque in project mapdb by jankotek.
the class ConcurrentLinkedDequeTest method testRetainAll.
/**
* retainAll(c) retains only those elements of c and reports true if change
*/
public void testRetainAll() {
ConcurrentLinkedDeque q = populatedDeque(SIZE);
ConcurrentLinkedDeque p = populatedDeque(SIZE);
for (int i = 0; i < SIZE; ++i) {
boolean changed = q.retainAll(p);
if (i == 0)
assertFalse(changed);
else
assertTrue(changed);
assertTrue(q.containsAll(p));
assertEquals(SIZE - i, q.size());
p.remove();
}
}
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());
}
use of java.util.concurrent.ConcurrentLinkedDeque in project mapdb by jankotek.
the class ConcurrentLinkedDequeTest method testToArray.
/**
* toArray() contains all elements in FIFO order
*/
public void testToArray() {
ConcurrentLinkedDeque q = populatedDeque(SIZE);
Object[] o = q.toArray();
for (int i = 0; i < o.length; i++) assertSame(o[i], q.poll());
}
Aggregations