Search in sources :

Example 1 with PartitionUpdateCounterVolatileImpl

use of org.apache.ignite.internal.processors.cache.PartitionUpdateCounterVolatileImpl in project ignite by apache.

the class PartitionUpdateCounterTest method testWithPersistentNode.

/**
 * @param mode Mode.
 */
private void testWithPersistentNode(CacheAtomicityMode mode) throws Exception {
    this.mode = mode;
    try {
        IgniteEx grid0 = startGrid(0);
        grid0.cluster().baselineAutoAdjustEnabled(false);
        grid0.cluster().active(true);
        grid0.cluster().baselineAutoAdjustEnabled(false);
        grid0.cache(DEFAULT_CACHE_NAME).put(0, 0);
        startGrid(1);
        grid0.cluster().setBaselineTopology(2);
        awaitPartitionMapExchange();
        grid0.cache(DEFAULT_CACHE_NAME).put(1, 1);
        assertPartitionsSame(idleVerify(grid0, DEFAULT_CACHE_NAME));
        printPartitionState(DEFAULT_CACHE_NAME, 0);
        stopGrid(grid0.name(), false);
        grid0 = startGrid(grid0.name());
        awaitPartitionMapExchange();
        PartitionUpdateCounter cntr = counter(0, grid0.name());
        assertTrue(cntr instanceof PartitionUpdateCounterErrorWrapper);
        PartitionUpdateCounter delegate = U.field(cntr, "delegate");
        if (mode == CacheAtomicityMode.TRANSACTIONAL)
            assertTrue(delegate instanceof PartitionUpdateCounterTrackingImpl);
        else if (mode == CacheAtomicityMode.ATOMIC)
            assertTrue(delegate instanceof PartitionUpdateCounterVolatileImpl);
        assertEquals(cntr.initial(), cntr.get());
    } finally {
        stopAllGrids();
    }
}
Also used : PartitionUpdateCounterTrackingImpl(org.apache.ignite.internal.processors.cache.PartitionUpdateCounterTrackingImpl) IgniteEx(org.apache.ignite.internal.IgniteEx) PartitionUpdateCounterVolatileImpl(org.apache.ignite.internal.processors.cache.PartitionUpdateCounterVolatileImpl) PartitionUpdateCounter(org.apache.ignite.internal.processors.cache.PartitionUpdateCounter) PartitionUpdateCounterErrorWrapper(org.apache.ignite.internal.processors.cache.PartitionUpdateCounterErrorWrapper)

Example 2 with PartitionUpdateCounterVolatileImpl

use of org.apache.ignite.internal.processors.cache.PartitionUpdateCounterVolatileImpl in project ignite by apache.

the class PartitionUpdateCounterTest method testAtomicUpdateCounterMultithreaded.

/**
 */
@Test
public void testAtomicUpdateCounterMultithreaded() throws Exception {
    PartitionUpdateCounter cntr = new PartitionUpdateCounterVolatileImpl(null);
    AtomicInteger id = new AtomicInteger();
    final int max = 1000;
    IgniteInternalFuture<?> fut = multithreadedAsync(new Runnable() {

        @Override
        public void run() {
            int val;
            while ((val = id.incrementAndGet()) <= max) {
                try {
                    cntr.update(val);
                } catch (IgniteCheckedException e) {
                    fail(X.getFullStackTrace(e));
                }
            }
        }
    }, Runtime.getRuntime().availableProcessors() * 2, "updater");
    fut.get();
    assertEquals(max, cntr.get());
}
Also used : IgniteCheckedException(org.apache.ignite.IgniteCheckedException) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) PartitionUpdateCounterVolatileImpl(org.apache.ignite.internal.processors.cache.PartitionUpdateCounterVolatileImpl) PartitionUpdateCounter(org.apache.ignite.internal.processors.cache.PartitionUpdateCounter) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Aggregations

PartitionUpdateCounter (org.apache.ignite.internal.processors.cache.PartitionUpdateCounter)2 PartitionUpdateCounterVolatileImpl (org.apache.ignite.internal.processors.cache.PartitionUpdateCounterVolatileImpl)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)1 IgniteEx (org.apache.ignite.internal.IgniteEx)1 PartitionUpdateCounterErrorWrapper (org.apache.ignite.internal.processors.cache.PartitionUpdateCounterErrorWrapper)1 PartitionUpdateCounterTrackingImpl (org.apache.ignite.internal.processors.cache.PartitionUpdateCounterTrackingImpl)1 GridCommonAbstractTest (org.apache.ignite.testframework.junits.common.GridCommonAbstractTest)1 Test (org.junit.Test)1