use of java.util.concurrent.BlockingQueue in project HugeCollections-OLD by peter-lawrey.
the class SharedJSR166TestCase method testContainsAll.
/**
* containsAll(c) is true when c contains a subset of elements
*/
@Test
public void testContainsAll() throws IOException {
BlockingQueue<Integer> q = populatedQueue(SIZE);
BlockingQueue p = new SharedConcurrentBlockingObjectQueue<Integer>(SIZE, Integer.class);
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 SharedJSR166TestCase method testPutWithTake.
/**
* put blocks interruptibly waiting for take when full
*/
@Test
public void testPutWithTake() throws Exception {
final int capacity = 2;
final BlockingQueue q = new SharedConcurrentBlockingObjectQueue<Integer>(capacity, Integer.class);
final CountDownLatch pleaseTake = new CountDownLatch(1);
final CountDownLatch pleaseInterrupt = new CountDownLatch(1);
Thread t = newStartedThread(new CheckedRunnable() {
public void realRun() throws Exception {
for (int i = 0; i < capacity; i++) q.put(i);
pleaseTake.countDown();
q.put(86);
pleaseInterrupt.countDown();
try {
q.put(99);
shouldThrow();
} catch (InterruptedException success) {
}
assertFalse(Thread.interrupted());
}
});
await(pleaseTake);
assertEquals(0, q.remainingCapacity());
assertEquals(0, q.take());
await(pleaseInterrupt);
assertThreadStaysAlive(t);
t.interrupt();
awaitTermination(t);
assertEquals(0, q.remainingCapacity());
}
use of java.util.concurrent.BlockingQueue in project HugeCollections-OLD by peter-lawrey.
the class SharedJSR166TestCase method testPoll.
/**
* poll succeeds unless empty
*/
@Test
public void testPoll() throws IOException {
BlockingQueue q = populatedQueue(SIZE);
for (int i = 0; i < SIZE; ++i) {
assertEquals(i, q.poll());
}
assertNull(q.poll());
}
use of java.util.concurrent.BlockingQueue in project HugeCollections-OLD by peter-lawrey.
the class LocalJSR166TestCase method testBlockingPut.
/**
* put blocks interruptibly if full
*/
@Test
public void testBlockingPut() throws InterruptedException {
final BlockingQueue q = new LocalConcurrentBlockingObjectQueue(SIZE);
final CountDownLatch pleaseInterrupt = new CountDownLatch(1);
Thread t = newStartedThread(new CheckedRunnable() {
public void realRun() throws InterruptedException {
for (int i = 0; i < SIZE; ++i) q.put(i);
assertEquals(SIZE, q.size());
assertEquals(0, q.remainingCapacity());
Thread.currentThread().interrupt();
try {
q.put(99);
shouldThrow();
} catch (InterruptedException success) {
}
assertFalse(Thread.interrupted());
pleaseInterrupt.countDown();
try {
q.put(99);
shouldThrow();
} catch (InterruptedException success) {
}
assertFalse(Thread.interrupted());
}
});
await(pleaseInterrupt);
assertThreadStaysAlive(t);
t.interrupt();
awaitTermination(t);
assertEquals(SIZE, q.size());
assertEquals(0, q.remainingCapacity());
}
use of java.util.concurrent.BlockingQueue in project HugeCollections-OLD by peter-lawrey.
the class LocalJSR166TestCase method testRetainAll.
/**
* retainAll(c) retains only those elements of c and reports true if changed
*/
@Test
public void testRetainAll() {
BlockingQueue q = populatedQueue(SIZE);
BlockingQueue p = populatedQueue(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();
}
}
Aggregations