use of java.util.concurrent.BlockingQueue 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 java.util.concurrent.BlockingQueue in project HugeCollections-OLD by peter-lawrey.
the class LocalJSR166TestCase method testDrainTo.
/**
* drainTo(c) empties queue into another collection c
*/
@Test
@Ignore
public void testDrainTo() {
BlockingQueue 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));
}
use of java.util.concurrent.BlockingQueue in project HugeCollections-OLD by peter-lawrey.
the class LocalJSR166TestCase method testToArray1_BadArg.
/**
* toArray(incompatible array type) throws ArrayStoreException
*/
@Test
public void testToArray1_BadArg() {
BlockingQueue q = populatedQueue(SIZE);
try {
q.toArray(new String[10]);
shouldThrow();
} catch (ArrayStoreException success) {
}
}
use of java.util.concurrent.BlockingQueue 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 java.util.concurrent.BlockingQueue 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());
}
}
Aggregations