use of java.util.concurrent.SynchronousQueue in project j2objc by google.
the class SynchronousQueueTest method testDrainToWithActivePut.
public void testDrainToWithActivePut(boolean fair) {
final SynchronousQueue q = new SynchronousQueue(fair);
Thread t = newStartedThread(new CheckedRunnable() {
public void realRun() throws InterruptedException {
q.put(one);
}
});
ArrayList l = new ArrayList();
long startTime = System.nanoTime();
while (l.isEmpty()) {
q.drainTo(l);
if (millisElapsedSince(startTime) > LONG_DELAY_MS)
fail("timed out");
Thread.yield();
}
assertTrue(l.size() == 1);
assertSame(one, l.get(0));
awaitTermination(t);
}
use of java.util.concurrent.SynchronousQueue in project j2objc by google.
the class SynchronousQueueTest method testContains.
public void testContains(boolean fair) {
final SynchronousQueue q = new SynchronousQueue(fair);
assertFalse(q.contains(zero));
}
use of java.util.concurrent.SynchronousQueue in project j2objc by google.
the class SynchronousQueueTest method testContainsAll.
public void testContainsAll(boolean fair) {
final SynchronousQueue q = new SynchronousQueue(fair);
Integer[] empty = new Integer[0];
assertTrue(q.containsAll(Arrays.asList(empty)));
Integer[] ints = new Integer[1];
ints[0] = zero;
assertFalse(q.containsAll(Arrays.asList(ints)));
}
use of java.util.concurrent.SynchronousQueue in project j2objc by google.
the class SynchronousQueueTest method testPutWithTake.
public void testPutWithTake(boolean fair) {
final SynchronousQueue q = new SynchronousQueue(fair);
final CountDownLatch pleaseTake = new CountDownLatch(1);
final CountDownLatch pleaseInterrupt = new CountDownLatch(1);
Thread t = newStartedThread(new CheckedRunnable() {
public void realRun() throws InterruptedException {
pleaseTake.countDown();
q.put(one);
pleaseInterrupt.countDown();
try {
q.put(99);
shouldThrow();
} catch (InterruptedException success) {
}
assertFalse(Thread.interrupted());
}
});
await(pleaseTake);
assertEquals(0, q.remainingCapacity());
try {
assertSame(one, q.take());
} catch (InterruptedException e) {
threadUnexpectedException(e);
}
await(pleaseInterrupt);
assertThreadStaysAlive(t);
t.interrupt();
awaitTermination(t);
assertEquals(0, q.remainingCapacity());
}
use of java.util.concurrent.SynchronousQueue in project j2objc by google.
the class SynchronousQueueTest method testOffer.
public void testOffer(boolean fair) {
SynchronousQueue q = new SynchronousQueue(fair);
assertFalse(q.offer(one));
}
Aggregations