use of java.util.concurrent.LinkedTransferQueue in project j2objc by google.
the class LinkedTransferQueueTest method testTryTransfer4.
/**
* If there is a consumer waiting in take, tryTransfer returns
* true while successfully transfering object.
*/
public void testTryTransfer4() throws InterruptedException {
final Object hotPotato = new Object();
final LinkedTransferQueue q = new LinkedTransferQueue();
Thread t = newStartedThread(new CheckedRunnable() {
public void realRun() {
while (!q.hasWaitingConsumer()) Thread.yield();
assertTrue(q.hasWaitingConsumer());
checkEmpty(q);
assertTrue(q.tryTransfer(hotPotato));
}
});
assertSame(q.take(), hotPotato);
checkEmpty(q);
awaitTermination(t);
}
use of java.util.concurrent.LinkedTransferQueue in project j2objc by google.
the class LinkedTransferQueueTest method testWeaklyConsistentIteration.
/**
* Modifications do not cause iterators to fail
*/
public void testWeaklyConsistentIteration() {
final LinkedTransferQueue q = new LinkedTransferQueue();
q.add(one);
q.add(two);
q.add(three);
for (Iterator it = q.iterator(); it.hasNext(); ) {
q.remove();
it.next();
}
assertEquals(0, q.size());
}
use of java.util.concurrent.LinkedTransferQueue in project j2objc by google.
the class LinkedTransferQueueTest method testTryTransfer1.
/**
* tryTransfer(null) throws NullPointerException
*/
public void testTryTransfer1() {
final LinkedTransferQueue q = new LinkedTransferQueue();
try {
q.tryTransfer(null);
shouldThrow();
} catch (NullPointerException success) {
}
}
use of java.util.concurrent.LinkedTransferQueue in project j2objc by google.
the class LinkedTransferQueueTest method testRetainAll.
/**
* retainAll(c) retains only those elements of c and reports true
* if changed
*/
public void testRetainAll() {
LinkedTransferQueue q = populatedQueue(SIZE);
LinkedTransferQueue 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();
}
}
use of java.util.concurrent.LinkedTransferQueue in project j2objc by google.
the class LinkedTransferQueueTest method testDrainToWithActivePut.
/**
* drainTo(c) empties full queue, unblocking a waiting put.
*/
public void testDrainToWithActivePut() throws InterruptedException {
final LinkedTransferQueue q = populatedQueue(SIZE);
Thread t = newStartedThread(new CheckedRunnable() {
public void realRun() {
q.put(SIZE + 1);
}
});
ArrayList l = new ArrayList();
q.drainTo(l);
assertTrue(l.size() >= SIZE);
for (int i = 0; i < SIZE; ++i) assertEquals(i, l.get(i));
awaitTermination(t);
assertTrue(q.size() + l.size() >= SIZE);
}
Aggregations