use of net.openhft.chronicle.sandbox.queue.LocalConcurrentBlockingObjectQueue in project HugeCollections-OLD by peter-lawrey.
the class LocalJSR166TestCase method populatedQueue.
/**
* Returns a new queue of given size containing consecutive
* Integers 0 ... n.
*/
private BlockingQueue populatedQueue(int n) {
BlockingQueue q = new LocalConcurrentBlockingObjectQueue(n);
assertTrue(q.isEmpty());
for (int i = 0; i < n; i++) assertTrue(q.offer(new Integer(i)));
assertFalse(q.isEmpty());
assertEquals(0, q.remainingCapacity());
assertEquals(n, q.size());
return q;
}
use of net.openhft.chronicle.sandbox.queue.LocalConcurrentBlockingObjectQueue in project HugeCollections-OLD by peter-lawrey.
the class LocalJSR166TestCase method testContainsAll.
/**
* containsAll(c) is true when c contains a subset of elements
*/
@Test
public void testContainsAll() {
BlockingQueue q = populatedQueue(SIZE);
LocalConcurrentBlockingObjectQueue p = new LocalConcurrentBlockingObjectQueue(SIZE);
for (int i = 0; i < SIZE; ++i) {
assertTrue(q.containsAll(p));
assertFalse(p.containsAll(q));
p.add(new Integer(i));
}
assertTrue(p.containsAll(q));
}
use of net.openhft.chronicle.sandbox.queue.LocalConcurrentBlockingObjectQueue in project HugeCollections-OLD by peter-lawrey.
the class LocalJSR166TestCase method testDrainToN.
/**
* drainTo(c, n) empties first min(n, size) elements of queue into c
*/
@Ignore
@Test
public void testDrainToN() {
BlockingQueue q = new LocalConcurrentBlockingObjectQueue(SIZE * 2);
for (int i = 0; i < SIZE + 2; ++i) {
for (int j = 0; j < SIZE; j++) assertTrue(q.offer(new Integer(j)));
ArrayList l = new ArrayList();
q.drainTo(l, i);
int k = (i < SIZE) ? i : SIZE;
assertEquals(k, l.size());
assertEquals(SIZE - k, q.size());
for (int j = 0; j < k; ++j) assertEquals(l.get(j), new Integer(j));
while (q.poll() != null) ;
}
}
use of net.openhft.chronicle.sandbox.queue.LocalConcurrentBlockingObjectQueue in project HugeCollections-OLD by peter-lawrey.
the class LocalJSR166TestCase method testToArray.
/**
* toArray() contains all elements in FIFO order
*/
@Test
public void testToArray() {
BlockingQueue q = new LocalConcurrentBlockingObjectQueue(SIZE);
for (int i = 0; i < SIZE; i++) {
checkToArray(q);
q.add(i);
}
// Provoke wraparound
for (int i = 0; i < SIZE; i++) {
checkToArray(q);
assertEquals(i, q.poll());
checkToArray(q);
q.add(SIZE + i);
}
for (int i = 0; i < SIZE; i++) {
checkToArray(q);
assertEquals(SIZE + i, q.poll());
}
}
use of net.openhft.chronicle.sandbox.queue.LocalConcurrentBlockingObjectQueue in project HugeCollections-OLD by peter-lawrey.
the class LocalJSR166TestCase method testEmptyFull.
/**
* Queue transitions from empty to full when elements added
*/
@Test
public void testEmptyFull() {
BlockingQueue q = new LocalConcurrentBlockingObjectQueue(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));
}
Aggregations