use of java.util.concurrent.LinkedTransferQueue in project j2objc by google.
the class LinkedTransferQueueTest method testTransfer4.
/**
* transfer waits until a poll occurs, at which point the polling
* thread returns the element
*/
public void testTransfer4() throws InterruptedException {
final LinkedTransferQueue q = new LinkedTransferQueue();
Thread t = newStartedThread(new CheckedRunnable() {
public void realRun() throws InterruptedException {
q.transfer(four);
assertFalse(q.contains(four));
assertSame(three, q.poll());
}
});
while (q.isEmpty()) Thread.yield();
assertFalse(q.isEmpty());
assertEquals(1, q.size());
assertTrue(q.offer(three));
assertSame(four, q.poll());
awaitTermination(t);
}
use of java.util.concurrent.LinkedTransferQueue in project j2objc by google.
the class LinkedTransferQueueTest method testAddAll3.
/**
* addAll of a collection with any null elements throws
* NullPointerException after possibly adding some elements
*/
public void testAddAll3() {
LinkedTransferQueue q = new LinkedTransferQueue();
Integer[] ints = new Integer[SIZE];
for (int i = 0; i < SIZE - 1; ++i) ints[i] = i;
try {
q.addAll(Arrays.asList(ints));
shouldThrow();
} catch (NullPointerException success) {
}
}
use of java.util.concurrent.LinkedTransferQueue in project j2objc by google.
the class LinkedTransferQueueTest method testDrainTo.
/**
* drainTo(c) empties queue into another collection c
*/
public void testDrainTo() {
LinkedTransferQueue q = populatedQueue(SIZE);
ArrayList l = new ArrayList();
q.drainTo(l);
assertEquals(0, q.size());
assertEquals(SIZE, l.size());
for (int i = 0; i < SIZE; ++i) {
assertEquals(i, l.get(i));
}
q.add(zero);
q.add(one);
assertFalse(q.isEmpty());
assertTrue(q.contains(zero));
assertTrue(q.contains(one));
l.clear();
q.drainTo(l);
assertEquals(0, q.size());
assertEquals(2, l.size());
for (int i = 0; i < 2; ++i) {
assertEquals(i, l.get(i));
}
}
use of java.util.concurrent.LinkedTransferQueue in project j2objc by google.
the class LinkedTransferQueueTest method testAddAll5.
/**
* Queue contains all elements, in traversal order, of successful addAll
*/
public void testAddAll5() {
Integer[] empty = new Integer[0];
Integer[] ints = new Integer[SIZE];
for (int i = 0; i < SIZE; ++i) {
ints[i] = i;
}
LinkedTransferQueue q = new LinkedTransferQueue();
assertFalse(q.addAll(Arrays.asList(empty)));
assertTrue(q.addAll(Arrays.asList(ints)));
for (int i = 0; i < SIZE; ++i) {
assertEquals(ints[i], q.poll());
}
}
use of java.util.concurrent.LinkedTransferQueue in project j2objc by google.
the class LinkedTransferQueueTest method testTryTransfer3.
/**
* If there is a consumer waiting in timed poll, tryTransfer
* returns true while successfully transfering object.
*/
public void testTryTransfer3() 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));
}
});
long startTime = System.nanoTime();
assertSame(hotPotato, q.poll(LONG_DELAY_MS, MILLISECONDS));
assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS);
checkEmpty(q);
awaitTermination(t);
}
Aggregations