use of java.util.concurrent.LinkedBlockingQueue in project mapdb by jankotek.
the class LinkedBlockingQueueTest method testToString.
/**
* toString contains toStrings of elements
*/
public void testToString() {
LinkedBlockingQueue q = populatedQueue(SIZE);
String s = q.toString();
for (int i = 0; i < SIZE; ++i) {
assertTrue(s.contains(String.valueOf(i)));
}
}
use of java.util.concurrent.LinkedBlockingQueue in project mapdb by jankotek.
the class LinkedBlockingQueueTest method testPut.
/**
* all elements successfully put are contained
*/
public void testPut() throws InterruptedException {
LinkedBlockingQueue q = new LinkedBlockingQueue(SIZE);
for (int i = 0; i < SIZE; ++i) {
Integer x = new Integer(i);
q.put(x);
assertTrue(q.contains(x));
}
assertEquals(0, q.remainingCapacity());
}
use of java.util.concurrent.LinkedBlockingQueue in project mapdb by jankotek.
the class LinkedBlockingQueueTest method testIterator.
/**
* iterator iterates through all elements
*/
public void testIterator() throws InterruptedException {
LinkedBlockingQueue 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);
it = q.iterator();
for (i = 0; it.hasNext(); i++) assertEquals(it.next(), q.take());
assertEquals(i, SIZE);
assertIteratorExhausted(it);
}
use of java.util.concurrent.LinkedBlockingQueue in project mapdb by jankotek.
the class LinkedBlockingQueueTest method testDrainToWithActivePut.
/**
* drainTo empties full queue, unblocking a waiting put.
*/
public void testDrainToWithActivePut() throws InterruptedException {
final LinkedBlockingQueue q = populatedQueue(SIZE);
Thread t = new Thread(new CheckedRunnable() {
public void realRun() throws InterruptedException {
q.put(new Integer(SIZE + 1));
}
});
t.start();
ArrayList l = new ArrayList();
q.drainTo(l);
assertTrue(l.size() >= SIZE);
for (int i = 0; i < SIZE; ++i) assertEquals(l.get(i), new Integer(i));
t.join();
assertTrue(q.size() + l.size() >= SIZE);
}
use of java.util.concurrent.LinkedBlockingQueue in project mapdb by jankotek.
the class LinkedBlockingQueueTest method testDrainTo.
/**
* drainTo(c) empties queue into another collection c
*/
public void testDrainTo() {
LinkedBlockingQueue q = populatedQueue(SIZE);
ArrayList l = new ArrayList();
q.drainTo(l);
assertEquals(0, q.size());
assertEquals(SIZE, l.size());
for (int i = 0; i < SIZE; ++i) assertEquals(l.get(i), new Integer(i));
q.add(zero);
q.add(one);
assertFalse(q.isEmpty());
assertTrue(q.contains(zero));
assertTrue(q.contains(one));
l.clear();
q.drainTo(l);
assertEquals(0, q.size());
assertEquals(2, l.size());
for (int i = 0; i < 2; ++i) assertEquals(l.get(i), new Integer(i));
}
Aggregations