Search in sources :

Example 1 with AddAllJob

use of org.apache.ignite.internal.processors.cache.datastructures.GridCacheQueueMultiNodeAbstractSelfTest.AddAllJob 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();
}
Also used : IgniteKernal(org.apache.ignite.internal.IgniteKernal) GridCacheContext(org.apache.ignite.internal.processors.cache.GridCacheContext) AddAllJob(org.apache.ignite.internal.processors.cache.datastructures.GridCacheQueueMultiNodeAbstractSelfTest.AddAllJob) Random(java.util.Random) IgniteInstanceResource(org.apache.ignite.resources.IgniteInstanceResource) IgniteQueue(org.apache.ignite.IgniteQueue) Collection(java.util.Collection) Ignite(org.apache.ignite.Ignite)

Aggregations

Collection (java.util.Collection)1 Random (java.util.Random)1 Ignite (org.apache.ignite.Ignite)1 IgniteQueue (org.apache.ignite.IgniteQueue)1 IgniteKernal (org.apache.ignite.internal.IgniteKernal)1 GridCacheContext (org.apache.ignite.internal.processors.cache.GridCacheContext)1 AddAllJob (org.apache.ignite.internal.processors.cache.datastructures.GridCacheQueueMultiNodeAbstractSelfTest.AddAllJob)1 IgniteInstanceResource (org.apache.ignite.resources.IgniteInstanceResource)1