use of java.util.concurrent.LinkedTransferQueue in project mapdb by jankotek.
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 mapdb by jankotek.
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 mapdb by jankotek.
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);
}
use of java.util.concurrent.LinkedTransferQueue in project mapdb by jankotek.
the class LinkedTransferQueueTest method testTryTransfer8.
/**
* tryTransfer attempts to enqueue into the queue and fails
* returning false not enqueueing and the successive poll is null
*/
public void testTryTransfer8() throws InterruptedException {
final LinkedTransferQueue q = new LinkedTransferQueue();
assertTrue(q.offer(four));
assertEquals(1, q.size());
long startTime = System.nanoTime();
assertFalse(q.tryTransfer(five, timeoutMillis(), MILLISECONDS));
assertTrue(millisElapsedSince(startTime) >= timeoutMillis());
assertEquals(1, q.size());
assertSame(four, q.poll());
assertNull(q.poll());
checkEmpty(q);
}
use of java.util.concurrent.LinkedTransferQueue in project mapdb by jankotek.
the class LinkedTransferQueueTest method testTryTransfer2.
/**
* tryTransfer returns false and does not enqueue if there are no
* consumers waiting to poll or take.
*/
public void testTryTransfer2() throws InterruptedException {
final LinkedTransferQueue q = new LinkedTransferQueue();
assertFalse(q.tryTransfer(new Object()));
assertFalse(q.hasWaitingConsumer());
checkEmpty(q);
}
Aggregations