Search in sources :

Example 6 with PartitionUpdateCounterTrackingImpl

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

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

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

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

Example 10 with PartitionUpdateCounterTrackingImpl

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

the class PartitionUpdateCounterTest method testMaxGaps.

/**
 * Test logic for handling gaps limit.
 */
@Test
public void testMaxGaps() {
    PartitionUpdateCounter pc = new PartitionUpdateCounterTrackingImpl(null);
    int i;
    for (i = 1; i <= PartitionUpdateCounterTrackingImpl.MAX_MISSED_UPDATES; i++) pc.update(i * 3, i * 3 + 1);
    i++;
    try {
        pc.update(i * 3, i * 3 + 1);
        fail();
    } catch (Exception e) {
    // Expected.
    }
}
Also used : PartitionUpdateCounterTrackingImpl(org.apache.ignite.internal.processors.cache.PartitionUpdateCounterTrackingImpl) PartitionUpdateCounter(org.apache.ignite.internal.processors.cache.PartitionUpdateCounter) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Aggregations

PartitionUpdateCounter (org.apache.ignite.internal.processors.cache.PartitionUpdateCounter)10 PartitionUpdateCounterTrackingImpl (org.apache.ignite.internal.processors.cache.PartitionUpdateCounterTrackingImpl)10 GridCommonAbstractTest (org.apache.ignite.testframework.junits.common.GridCommonAbstractTest)9 Test (org.junit.Test)9 IgniteEx (org.apache.ignite.internal.IgniteEx)3 PartitionUpdateCounterErrorWrapper (org.apache.ignite.internal.processors.cache.PartitionUpdateCounterErrorWrapper)3 NavigableMap (java.util.NavigableMap)2 Random (java.util.Random)2 ConcurrentLinkedQueue (java.util.concurrent.ConcurrentLinkedQueue)2 ThreadLocalRandom (java.util.concurrent.ThreadLocalRandom)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2 LongAdder (java.util.concurrent.atomic.LongAdder)2 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)2 PartitionUpdateCounterVolatileImpl (org.apache.ignite.internal.processors.cache.PartitionUpdateCounterVolatileImpl)2 ArrayList (java.util.ArrayList)1 Collections (java.util.Collections)1 Iterator (java.util.Iterator)1 List (java.util.List)1 Queue (java.util.Queue)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1