use of java.util.concurrent.BlockingQueue in project HugeCollections-OLD by peter-lawrey.
the class LocalJSR166TestCase method testClear.
/**
* clear removes all elements
*/
@Test
public void testClear() {
BlockingQueue q = populatedQueue(SIZE);
q.clear();
assertTrue(q.isEmpty());
assertEquals(0, q.size());
assertEquals(SIZE, q.remainingCapacity());
q.add(one);
assertFalse(q.isEmpty());
assertTrue(q.contains(one));
q.clear();
assertTrue(q.isEmpty());
}
use of java.util.concurrent.BlockingQueue in project HugeCollections-OLD by peter-lawrey.
the class LocalJSR166TestCase method testTimedOffer.
/**
* timed offer times out if full and elements not taken
*/
@Ignore
@Test
public void testTimedOffer() throws InterruptedException {
final BlockingQueue q = new LocalConcurrentBlockingObjectQueue(2);
final CountDownLatch pleaseInterrupt = new CountDownLatch(1);
Thread t = newStartedThread(new CheckedRunnable() {
public void realRun() throws InterruptedException {
q.put(new Object());
q.put(new Object());
long startTime = System.nanoTime();
assertFalse(q.offer(new Object(), timeoutMillis(), MILLISECONDS));
assertTrue(millisElapsedSince(startTime) >= timeoutMillis());
pleaseInterrupt.countDown();
try {
q.offer(new Object(), 2 * LONG_DELAY_MS, MILLISECONDS);
shouldThrow();
} catch (InterruptedException success) {
}
}
});
await(pleaseInterrupt);
assertThreadStaysAlive(t);
t.interrupt();
awaitTermination(t);
}
use of java.util.concurrent.BlockingQueue in project HugeCollections-OLD by peter-lawrey.
the class LocalJSR166TestCase method testRemove.
/**
* remove removes next element, or throws NSEE if empty
*/
@Test
public void testRemove() {
BlockingQueue q = populatedQueue(SIZE);
for (int i = 0; i < SIZE; ++i) {
assertEquals(i, q.remove());
}
try {
q.remove();
shouldThrow();
} catch (NoSuchElementException success) {
}
}
use of java.util.concurrent.BlockingQueue in project HugeCollections-OLD by peter-lawrey.
the class SharedJSR166TestCase method testTimedOffer.
/**
* timed offer times out if full and elements not taken
*/
@Ignore
@Test
public void testTimedOffer() throws Exception, IOException {
final BlockingQueue q = new SharedConcurrentBlockingObjectQueue(2, Integer.class);
final CountDownLatch pleaseInterrupt = new CountDownLatch(1);
Thread t = newStartedThread(new CheckedRunnable() {
public void realRun() throws Exception {
q.put(new Object());
q.put(new Object());
long startTime = System.nanoTime();
assertFalse(q.offer(new Object(), timeoutMillis(), MILLISECONDS));
assertTrue(millisElapsedSince(startTime) >= timeoutMillis());
pleaseInterrupt.countDown();
try {
q.offer(new Object(), 2 * LONG_DELAY_MS, MILLISECONDS);
shouldThrow();
} catch (InterruptedException success) {
}
}
});
await(pleaseInterrupt);
assertThreadStaysAlive(t);
t.interrupt();
awaitTermination(t);
}
use of java.util.concurrent.BlockingQueue in project HugeCollections-OLD by peter-lawrey.
the class SharedJSR166TestCase method testBlockingTake.
/**
* Take removes existing elements until empty, then blocks interruptibly
*/
@Ignore
@Test
public void testBlockingTake() throws Exception, IOException {
final BlockingQueue q = populatedQueue(SIZE);
final CountDownLatch pleaseInterrupt = new CountDownLatch(1);
Thread t = newStartedThread(new CheckedRunnable() {
public void realRun() throws Exception {
for (int i = 0; i < SIZE; ++i) {
assertEquals(i, q.take());
}
Thread.currentThread().interrupt();
try {
q.take();
shouldThrow();
} catch (InterruptedException success) {
}
assertFalse(Thread.interrupted());
pleaseInterrupt.countDown();
try {
q.take();
shouldThrow();
} catch (InterruptedException success) {
}
assertFalse(Thread.interrupted());
}
});
await(pleaseInterrupt);
assertThreadStaysAlive(t);
t.interrupt();
awaitTermination(t);
}
Aggregations