Search in sources :

Example 1 with GridAtomicInteger

use of org.apache.ignite.internal.util.GridAtomicInteger in project ignite by apache.

the class CacheDiscoveryDataConcurrentJoinTest method testConcurrentJoin.

/**
     * @throws Exception If failed.
     */
public void testConcurrentJoin() throws Exception {
    for (int iter = 0; iter < ITERATIONS; iter++) {
        log.info("Iteration: " + iter);
        final int NODES = 6;
        final int MAX_CACHES = 10;
        final GridAtomicInteger caches = new GridAtomicInteger();
        startGrid(0);
        final AtomicInteger idx = new AtomicInteger(1);
        GridTestUtils.runMultiThreaded(new Callable<Void>() {

            @Override
            public Void call() throws Exception {
                int c = ThreadLocalRandom.current().nextInt(MAX_CACHES) + 1;
                staticCaches.set(c);
                startGrid(idx.getAndIncrement());
                caches.setIfGreater(c);
                return null;
            }
        }, NODES - 1, "start-node");
        assertTrue(caches.get() > 0);
        for (int i = 0; i < NODES; i++) {
            Ignite node = ignite(i);
            for (int c = 0; c < caches.get(); c++) {
                Collection<ClusterNode> nodes = node.cluster().forCacheNodes("cache-" + c).nodes();
                assertEquals(NODES, nodes.size());
                checkCache(node, "cache-" + c);
            }
        }
        stopAllGrids();
    }
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) GridAtomicInteger(org.apache.ignite.internal.util.GridAtomicInteger) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) GridAtomicInteger(org.apache.ignite.internal.util.GridAtomicInteger) Ignite(org.apache.ignite.Ignite)

Example 2 with GridAtomicInteger

use of org.apache.ignite.internal.util.GridAtomicInteger in project ignite by apache.

the class GridCacheAsyncOperationsLimitSelfTest method testAsyncOps.

/**
     * @throws Exception If failed.
     */
public void testAsyncOps() throws Exception {
    final AtomicInteger cnt = new AtomicInteger();
    final GridAtomicInteger max = new GridAtomicInteger();
    for (int i = 0; i < 5000; i++) {
        final int i0 = i;
        cnt.incrementAndGet();
        jcache().putAsync("key" + i, i).listen(new CI1<IgniteFuture<?>>() {

            @Override
            public void apply(IgniteFuture<?> t) {
                cnt.decrementAndGet();
                max.setIfGreater(cnt.get());
                if (i0 > 0 && i0 % 100 == 0)
                    info("cnt: " + cnt.get());
            }
        });
        assertTrue("Maximum number of permits exceeded: " + max.get(), max.get() <= 51);
    }
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) GridAtomicInteger(org.apache.ignite.internal.util.GridAtomicInteger) GridAtomicInteger(org.apache.ignite.internal.util.GridAtomicInteger) IgniteFuture(org.apache.ignite.lang.IgniteFuture)

Aggregations

AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 GridAtomicInteger (org.apache.ignite.internal.util.GridAtomicInteger)2 Ignite (org.apache.ignite.Ignite)1 ClusterNode (org.apache.ignite.cluster.ClusterNode)1 IgniteFuture (org.apache.ignite.lang.IgniteFuture)1