use of java.util.concurrent.BlockingQueue in project HugeCollections-OLD by peter-lawrey.
the class BlockingQueueTest method testDrainToNull.
/**
* drainTo(null) throws NullPointerException
*/
public void testDrainToNull() {
final BlockingQueue q = emptyCollection();
try {
q.drainTo(null);
shouldThrow();
} catch (NullPointerException success) {
}
}
use of java.util.concurrent.BlockingQueue in project HugeCollections-OLD by peter-lawrey.
the class BlockingQueueTest method testTimedPollWithOffer.
/**
* timed poll before a delayed offer times out; after offer succeeds;
* on interruption throws
*/
public void testTimedPollWithOffer() throws InterruptedException {
final BlockingQueue q = emptyCollection();
final CheckedBarrier barrier = new CheckedBarrier(2);
final Object zero = makeElement(0);
Thread t = newStartedThread(new CheckedRunnable() {
public void realRun() throws InterruptedException {
long startTime = System.nanoTime();
assertNull(q.poll(timeoutMillis(), MILLISECONDS));
assertTrue(millisElapsedSince(startTime) >= timeoutMillis());
barrier.await();
assertSame(zero, q.poll(LONG_DELAY_MS, MILLISECONDS));
Thread.currentThread().interrupt();
try {
q.poll(LONG_DELAY_MS, MILLISECONDS);
shouldThrow();
} catch (InterruptedException success) {
}
assertFalse(Thread.interrupted());
barrier.await();
try {
q.poll(LONG_DELAY_MS, MILLISECONDS);
shouldThrow();
} catch (InterruptedException success) {
}
assertFalse(Thread.interrupted());
}
});
barrier.await();
long startTime = System.nanoTime();
assertTrue(q.offer(zero, LONG_DELAY_MS, MILLISECONDS));
assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS);
barrier.await();
assertThreadStaysAlive(t);
t.interrupt();
awaitTermination(t);
}
use of java.util.concurrent.BlockingQueue in project HugeCollections-OLD by peter-lawrey.
the class LocalJSR166TestCase method testContains.
/**
* contains(x) reports true when elements added but not yet removed
*/
@Test
public void testContains() {
BlockingQueue q = populatedQueue(SIZE);
for (int i = 0; i < SIZE; ++i) {
assertTrue(q.contains(new Integer(i)));
assertEquals(i, q.poll());
assertFalse(q.contains(new Integer(i)));
}
}
use of java.util.concurrent.BlockingQueue 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 java.util.concurrent.BlockingQueue in project HugeCollections-OLD by peter-lawrey.
the class LocalJSR166TestCase method testRemoveAll.
/**
* removeAll(c) removes only those elements of c and reports true if changed
*/
@Test
public void testRemoveAll() {
for (int i = 1; i < SIZE; ++i) {
BlockingQueue q = populatedQueue(SIZE);
BlockingQueue p = populatedQueue(i);
assertTrue(q.removeAll(p));
assertEquals(SIZE - i, q.size());
for (int j = 0; j < i; ++j) {
Integer I = (Integer) (p.remove());
assertFalse(q.contains(I));
}
}
}
Aggregations