use of org.apache.ignite.IgniteQueue in project ignite by apache.
the class GridCachePartitionedQueueEntryMoveSelfTest method testQueue.
/**
* @throws Exception If failed.
*/
public void testQueue() throws Exception {
final String queueName = "qq";
System.out.println(U.filler(20, '\n'));
final CountDownLatch latch1 = new CountDownLatch(1);
final CountDownLatch latch2 = new CountDownLatch(1);
IgniteInternalFuture<?> fut1 = GridTestUtils.runAsync(new Callable<Void>() {
@Override
public Void call() throws IgniteInterruptedCheckedException {
Ignite ignite = grid(0);
IgniteQueue<Integer> queue = ignite.queue(queueName, QUEUE_CAP, config(true));
for (int i = 0; i < QUEUE_CAP * 2; i++) {
if (i == QUEUE_CAP) {
latch1.countDown();
U.await(latch2);
}
try {
info(">>> Putting value: " + i);
queue.put(i);
info(">>> Value is in queue: " + i);
} catch (Error | RuntimeException e) {
error("Failed to put value: " + i, e);
throw e;
}
}
return null;
}
});
latch1.await();
startAdditionalNodes(BACKUP_CNT + 2, queueName);
System.out.println(U.filler(20, '\n'));
latch2.countDown();
IgniteInternalFuture<?> fut2 = GridTestUtils.runAsync(new Callable<Void>() {
@Override
public Void call() throws IgniteCheckedException {
Ignite ignite = grid(GRID_CNT);
IgniteQueue<Integer> queue = ignite.queue(queueName, QUEUE_CAP, config(true));
int cnt = 0;
do {
try {
Integer i = queue.poll();
if (i != null) {
info(">>> Polled value: " + cnt);
cnt++;
} else {
info(">>> Waiting for value...");
U.sleep(2000);
}
} catch (Error | RuntimeException e) {
error("Failed to poll value.", e);
throw e;
}
} while (cnt < QUEUE_CAP * 2);
return null;
}
});
fut1.get();
fut2.get();
}
Aggregations