use of org.apache.ignite.IgniteQueue in project ignite by apache.
the class GridCachePartitionedQueueEntryMoveSelfTest method startAdditionalNodes.
/**
* Start additional nodes above {@link #GRID_CNT}.
*
* @param cnt Number of additional nodes.
* @param queueName Queue name.
* @throws Exception If failed.
*/
private void startAdditionalNodes(int cnt, String queueName) throws Exception {
IgniteQueue queue = ignite(0).queue(queueName, 0, null);
CacheConfiguration cCfg = getQueueCache(queue);
Collection<ClusterNode> aff1 = ignite(0).affinity(cCfg.getName()).mapKeyToPrimaryAndBackups(queueName);
for (int i = 0, id = GRID_CNT; i < cnt; i++) {
startGrid(id++);
awaitPartitionMapExchange();
Collection<ClusterNode> aff2 = ignite(0).affinity(cCfg.getName()).mapKeyToPrimaryAndBackups(queueName);
if (!aff1.iterator().next().equals(aff2.iterator().next())) {
info("Moved queue to new primary node [oldAff=" + aff1 + ", newAff=" + aff2 + ']');
return;
}
}
throw new IgniteCheckedException("Unable to move the queue to a new primary node");
}
use of org.apache.ignite.IgniteQueue in project ignite by apache.
the class GridCachePartitionedQueueCreateMultiNodeSelfTest method testQueueCreation.
/**
* @throws Exception If failed.
*/
public void testQueueCreation() throws Exception {
final AtomicInteger idx = new AtomicInteger();
IgniteInternalFuture<?> fut = multithreadedAsync(new Callable<Object>() {
@Override
public Object call() throws Exception {
int idx0 = idx.getAndIncrement();
Thread.currentThread().setName("createQueue-" + idx0);
final Ignite ignite = startGrid(idx0);
UUID locNodeId = ignite.cluster().localNode().id();
info("Started grid: " + locNodeId);
info("Creating queue: " + locNodeId);
GridTestUtils.runMultiThreaded(new Callable<Void>() {
@Override
public Void call() throws Exception {
ignite.queue("queue", 1, config(true));
return null;
}
}, 10, "create-queue-" + ignite.name());
IgniteQueue<String> q = ignite.queue("queue", 1, config(true));
assert q != null;
info("Putting first value: " + locNodeId);
q.offer("val", 1000, MILLISECONDS);
info("Putting second value: " + locNodeId);
boolean res2 = q.offer("val1", 1000, MILLISECONDS);
assert !res2;
info("Thread finished: " + locNodeId);
return null;
}
}, 10);
fut.get();
}
use of org.apache.ignite.IgniteQueue in project ignite by apache.
the class GridCacheQueueMultiNodeAbstractSelfTest method testIterator.
/**
* @throws Exception If failed.
*/
public void testIterator() throws Exception {
final String queueName = UUID.randomUUID().toString();
info("Queue name: " + queueName);
try (IgniteQueue<Integer> queue = grid(0).queue(queueName, QUEUE_CAPACITY, config(false))) {
assertTrue(queue.isEmpty());
grid(0).compute().broadcast(new AddAllJob(queueName, RETRIES));
assertEquals(GRID_CNT * RETRIES, queue.size());
Collection<ClusterNode> nodes = grid(0).cluster().nodes();
for (ClusterNode node : nodes) {
Collection<Integer> queueElements = compute(grid(0).cluster().forNode(node)).call(new IgniteCallable<Collection<Integer>>() {
@IgniteInstanceResource
private Ignite grid;
/** {@inheritDoc} */
@Override
public Collection<Integer> call() throws Exception {
Collection<Integer> values = new ArrayList<>();
grid.log().info("Running job [node=" + grid.cluster().localNode().id() + "]");
IgniteQueue<Integer> locQueue = grid.queue(queueName, 0, null);
grid.log().info("Queue size " + locQueue.size());
for (Integer element : locQueue) values.add(element);
grid.log().info("Returning: " + values);
return values;
}
});
assertTrue(F.eqOrdered(queue, queueElements));
}
}
}
use of org.apache.ignite.IgniteQueue in project ignite by apache.
the class GridCacheQueueMultiNodeConsistencySelfTest method checkCacheQueue.
/**
* Starts {@code GRID_CNT} nodes, broadcasts {@code AddAllJob} to them then starts new grid and
* reads cache queue content and finally asserts queue content is the same.
*
* @throws Exception If failed.
*/
private void checkCacheQueue() throws Exception {
startGrids(GRID_CNT);
final String queueName = UUID.randomUUID().toString();
IgniteQueue<Integer> queue0 = grid(0).queue(queueName, QUEUE_CAPACITY, config(false));
assertTrue(queue0.isEmpty());
grid(0).compute().broadcast(new AddAllJob(queueName, RETRIES));
assertEquals(GRID_CNT * RETRIES, queue0.size());
if (stopRandomGrid)
stopGrid(1 + new Random().nextInt(GRID_CNT));
if (forceRepartition) {
for (int i = 0; i < GRID_CNT; i++) {
IgniteKernal ignite = (IgniteKernal) grid(i);
boolean found = false;
for (GridCacheContext ctx : ignite.context().cache().context().cacheContexts()) {
if (ctx.name() != null && ctx.name().startsWith("datastructures")) {
ctx.cache().rebalance().get();
found = true;
}
}
assertTrue(found);
}
}
Ignite newIgnite = startGrid(GRID_CNT + 1);
// Intentionally commented code cause in this way inconsistent queue problem doesn't appear.
// IgniteQueue<Integer> newQueue = newGrid.cache().queue(queueName);
// assertTrue(CollectionUtils.isEqualCollection(queue0, newQueue));
Collection<Integer> locQueueContent = compute(newIgnite.cluster().forLocal()).call(new IgniteCallable<Collection<Integer>>() {
@IgniteInstanceResource
private Ignite grid;
/** {@inheritDoc} */
@Override
public Collection<Integer> call() throws Exception {
Collection<Integer> values = new ArrayList<>();
grid.log().info("Running job [node=" + grid.cluster().localNode().id() + ", job=" + this + "]");
IgniteQueue<Integer> locQueue = grid.queue(queueName, QUEUE_CAPACITY, config(false));
grid.log().info("Queue size " + locQueue.size());
for (Integer element : locQueue) values.add(element);
return values;
}
});
assertTrue(CollectionUtils.isEqualCollection(queue0, locQueueContent));
queue0.close();
}
use of org.apache.ignite.IgniteQueue in project ignite by apache.
the class GridCacheQueueApiSelfAbstractTest method testNotReuseCache.
/**
* @throws Exception If failed.
*/
public void testNotReuseCache() throws Exception {
CollectionConfiguration colCfg1 = collectionConfiguration();
CollectionConfiguration colCfg2 = collectionConfiguration();
if (colCfg2.getAtomicityMode() == ATOMIC)
colCfg2.setAtomicityMode(TRANSACTIONAL);
else
colCfg2.setAtomicityMode(ATOMIC);
IgniteQueue queue1 = grid(0).queue("Queue1", 0, colCfg1);
IgniteQueue queue2 = grid(0).queue("Queue2", 0, colCfg2);
assertNotSame(getQueueCache(queue1), getQueueCache(queue2));
}
Aggregations