Search in sources :

Example 21 with PartitionUpdateCounter

use of org.apache.ignite.internal.processors.cache.PartitionUpdateCounter 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 22 with PartitionUpdateCounter

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

the class PartitionUpdateCounterTest method testOutOfOrderUpdatesIterator.

/**
 */
@Test
public void testOutOfOrderUpdatesIterator() {
    PartitionUpdateCounter pc = new PartitionUpdateCounterTrackingImpl(null);
    pc.update(67, 3);
    pc.update(1, 58);
    pc.update(60, 5);
    Iterator<long[]> iter = pc.iterator();
    long[] upd = iter.next();
    assertEquals(1, upd[0]);
    assertEquals(58, upd[1]);
    upd = iter.next();
    assertEquals(60, upd[0]);
    assertEquals(5, upd[1]);
    upd = iter.next();
    assertEquals(67, upd[0]);
    assertEquals(3, upd[1]);
    assertFalse(iter.hasNext());
}
Also used : PartitionUpdateCounterTrackingImpl(org.apache.ignite.internal.processors.cache.PartitionUpdateCounterTrackingImpl) PartitionUpdateCounter(org.apache.ignite.internal.processors.cache.PartitionUpdateCounter) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 23 with PartitionUpdateCounter

use of org.apache.ignite.internal.processors.cache.PartitionUpdateCounter 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)

Example 24 with PartitionUpdateCounter

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

the class PartitionUpdateCounterTest method testRandomUpdates.

/**
 * Test applying update multiple times in random order.
 */
@Test
public void testRandomUpdates() {
    List<int[]> tmp = generateUpdates(1000, 5);
    long expTotal = tmp.stream().mapToInt(pair -> pair[1]).sum();
    PartitionUpdateCounter pc = null;
    for (int i = 0; i < 100; i++) {
        Collections.shuffle(tmp);
        PartitionUpdateCounter pc0 = new PartitionUpdateCounterTrackingImpl(null);
        for (int[] pair : tmp) pc0.update(pair[0], pair[1]);
        if (pc == null)
            pc = pc0;
        else {
            assertEquals(pc, pc0);
            assertEquals(expTotal, pc0.get());
            assertTrue(pc0.sequential());
            pc = pc0;
        }
    }
}
Also used : CacheAtomicityMode(org.apache.ignite.cache.CacheAtomicityMode) IgniteInternalFuture(org.apache.ignite.internal.IgniteInternalFuture) LongAdder(java.util.concurrent.atomic.LongAdder) PartitionUpdateCounterVolatileImpl(org.apache.ignite.internal.processors.cache.PartitionUpdateCounterVolatileImpl) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) U(org.apache.ignite.internal.util.typedef.internal.U) Random(java.util.Random) IgniteEx(org.apache.ignite.internal.IgniteEx) RendezvousAffinityFunction(org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction) ArrayList(java.util.ArrayList) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) PartitionUpdateCounterTrackingImpl(org.apache.ignite.internal.processors.cache.PartitionUpdateCounterTrackingImpl) X(org.apache.ignite.internal.util.typedef.X) DataStorageConfiguration(org.apache.ignite.configuration.DataStorageConfiguration) WALMode(org.apache.ignite.configuration.WALMode) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Iterator(java.util.Iterator) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) PartitionUpdateCounter(org.apache.ignite.internal.processors.cache.PartitionUpdateCounter) Test(org.junit.Test) NavigableMap(java.util.NavigableMap) List(java.util.List) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) Queue(java.util.Queue) Collections(java.util.Collections) PartitionUpdateCounterErrorWrapper(org.apache.ignite.internal.processors.cache.PartitionUpdateCounterErrorWrapper) DataRegionConfiguration(org.apache.ignite.configuration.DataRegionConfiguration) ConcurrentLinkedQueue(java.util.concurrent.ConcurrentLinkedQueue) CacheMode(org.apache.ignite.cache.CacheMode) PartitionUpdateCounterTrackingImpl(org.apache.ignite.internal.processors.cache.PartitionUpdateCounterTrackingImpl) PartitionUpdateCounter(org.apache.ignite.internal.processors.cache.PartitionUpdateCounter) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 25 with PartitionUpdateCounter

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

the class PartitionUpdateCounterTest method testFoldIntermediateUpdates.

/**
 */
@Test
public void testFoldIntermediateUpdates() {
    PartitionUpdateCounter pc = new PartitionUpdateCounterTrackingImpl(null);
    pc.update(0, 59);
    pc.update(60, 5);
    pc.update(67, 3);
    pc.update(65, 2);
    Iterator<long[]> it = pc.iterator();
    it.next();
    assertFalse(it.hasNext());
    pc.update(59, 1);
    assertTrue(pc.sequential());
}
Also used : PartitionUpdateCounterTrackingImpl(org.apache.ignite.internal.processors.cache.PartitionUpdateCounterTrackingImpl) 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)29 Test (org.junit.Test)17 IgniteEx (org.apache.ignite.internal.IgniteEx)15 Ignite (org.apache.ignite.Ignite)12 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)12 GridCommonAbstractTest (org.apache.ignite.testframework.junits.common.GridCommonAbstractTest)12 PartitionUpdateCounterTrackingImpl (org.apache.ignite.internal.processors.cache.PartitionUpdateCounterTrackingImpl)10 List (java.util.List)9 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)8 T2 (org.apache.ignite.internal.util.typedef.T2)7 Map (java.util.Map)6 GridDhtLocalPartition (org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtLocalPartition)6 Nullable (org.jetbrains.annotations.Nullable)6 ArrayList (java.util.ArrayList)5 HashMap (java.util.HashMap)5 IgniteInternalFuture (org.apache.ignite.internal.IgniteInternalFuture)5 TestRecordingCommunicationSpi (org.apache.ignite.internal.TestRecordingCommunicationSpi)5 Collections (java.util.Collections)4 IgniteException (org.apache.ignite.IgniteException)4 Collection (java.util.Collection)3