use of java.util.concurrent.SynchronousQueue in project j2objc by google.
the class SynchronousQueueTest method testRetainAll.
public void testRetainAll(boolean fair) {
final SynchronousQueue q = new SynchronousQueue(fair);
Integer[] empty = new Integer[0];
assertFalse(q.retainAll(Arrays.asList(empty)));
Integer[] ints = new Integer[1];
ints[0] = zero;
assertFalse(q.retainAll(Arrays.asList(ints)));
}
use of java.util.concurrent.SynchronousQueue in project j2objc by google.
the class SynchronousQueueTest method testOfferInExecutor.
public void testOfferInExecutor(boolean fair) {
final SynchronousQueue q = new SynchronousQueue(fair);
final CheckedBarrier threadsStarted = new CheckedBarrier(2);
final ExecutorService executor = Executors.newFixedThreadPool(2);
try (PoolCleaner cleaner = cleaner(executor)) {
executor.execute(new CheckedRunnable() {
public void realRun() throws InterruptedException {
assertFalse(q.offer(one));
threadsStarted.await();
assertTrue(q.offer(one, LONG_DELAY_MS, MILLISECONDS));
assertEquals(0, q.remainingCapacity());
}
});
executor.execute(new CheckedRunnable() {
public void realRun() throws InterruptedException {
threadsStarted.await();
assertSame(one, q.take());
}
});
}
}
use of java.util.concurrent.SynchronousQueue in project j2objc by google.
the class SynchronousQueueTest method testTimedOffer.
public void testTimedOffer(boolean fair) {
final SynchronousQueue q = new SynchronousQueue(fair);
final CountDownLatch pleaseInterrupt = new CountDownLatch(1);
Thread t = newStartedThread(new CheckedRunnable() {
public void realRun() throws InterruptedException {
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.SynchronousQueue in project j2objc by google.
the class SynchronousQueueTest method testPeek.
public void testPeek(boolean fair) {
final SynchronousQueue q = new SynchronousQueue(fair);
assertNull(q.peek());
}
use of java.util.concurrent.SynchronousQueue in project j2objc by google.
the class SynchronousQueueTest method testElement.
public void testElement(boolean fair) {
final SynchronousQueue q = new SynchronousQueue(fair);
try {
q.element();
shouldThrow();
} catch (NoSuchElementException success) {
}
}
Aggregations