use of java.util.concurrent.BlockingQueue in project mapdb by jankotek.
the class LinkedTransferQueueTest method testBlockingTake.
/**
* take removes existing elements until empty, then blocks interruptibly
*/
public void testBlockingTake() throws InterruptedException {
final BlockingQueue q = populatedQueue(SIZE);
final CountDownLatch pleaseInterrupt = new CountDownLatch(1);
Thread t = newStartedThread(new CheckedRunnable() {
public void realRun() throws InterruptedException {
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);
}
use of java.util.concurrent.BlockingQueue in project mapdb by jankotek.
the class LinkedTransferQueueTest method testRemainingCapacity.
/**
* remainingCapacity() always returns Integer.MAX_VALUE
*/
public void testRemainingCapacity() {
BlockingQueue q = populatedQueue(SIZE);
for (int i = 0; i < SIZE; ++i) {
assertEquals(Integer.MAX_VALUE, q.remainingCapacity());
assertEquals(SIZE - i, q.size());
assertEquals(i, q.remove());
}
for (int i = 0; i < SIZE; ++i) {
assertEquals(Integer.MAX_VALUE, q.remainingCapacity());
assertEquals(i, q.size());
assertTrue(q.add(i));
}
}
use of java.util.concurrent.BlockingQueue in project mapdb by jankotek.
the class LinkedBlockingQueueTest method testBlockingTake.
/**
* Take removes existing elements until empty, then blocks interruptibly
*/
public void testBlockingTake() throws InterruptedException {
final BlockingQueue q = populatedQueue(SIZE);
final CountDownLatch pleaseInterrupt = new CountDownLatch(1);
Thread t = newStartedThread(new CheckedRunnable() {
public void realRun() throws InterruptedException {
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);
}
use of java.util.concurrent.BlockingQueue in project HugeCollections-OLD by peter-lawrey.
the class LocalJSR166TestCase method testConstructor7.
/**
* Queue contains all elements of collection used to initialize
*/
@Ignore
@Test
public void testConstructor7() {
Integer[] ints = new Integer[SIZE];
for (int i = 0; i < SIZE; ++i) ints[i] = i;
Collection<Integer> elements = Arrays.asList(ints);
BlockingQueue q = new LocalConcurrentBlockingObjectQueue(SIZE, true, elements);
for (int i = 0; i < SIZE; ++i) assertEquals(ints[i], q.poll());
}
use of java.util.concurrent.BlockingQueue in project HugeCollections-OLD by peter-lawrey.
the class LocalJSR166TestCase method testBlockingTake.
/**
* Take removes existing elements until empty, then blocks interruptibly
*/
@Ignore
@Test
public void testBlockingTake() throws InterruptedException {
final BlockingQueue q = populatedQueue(SIZE);
final CountDownLatch pleaseInterrupt = new CountDownLatch(1);
Thread t = newStartedThread(new CheckedRunnable() {
public void realRun() throws InterruptedException {
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