Search in sources :

Example 6 with CachePeekMode

use of org.apache.ignite.cache.CachePeekMode in project ignite by apache.

the class GridCacheAbstractQueueFailoverDataConsistencySelfTest method primaryQueueNode.

/**
 * @param queue Queue.
 * @return Primary node for queue's header.
 * @throws Exception If failed.
 */
private int primaryQueueNode(IgniteQueue queue) throws Exception {
    GridCacheContext cctx = GridTestUtils.getFieldValue(queue, "cctx");
    GridCacheAffinityManager aff = cctx.affinity();
    CachePeekMode[] modes = new CachePeekMode[] { CachePeekMode.ALL };
    for (int i = 0; i < gridCount(); i++) {
        for (Cache.Entry e : grid(i).context().cache().internalCache(cctx.name()).localEntries(modes)) {
            Object key = e.getKey();
            if (aff.primaryByKey(grid(i).localNode(), key, AffinityTopologyVersion.NONE) && key instanceof GridCacheQueueHeaderKey)
                return i;
        }
    }
    fail("Failed to find primary node for queue header.");
    return -1;
}
Also used : GridCacheContext(org.apache.ignite.internal.processors.cache.GridCacheContext) GridCacheAffinityManager(org.apache.ignite.internal.processors.cache.GridCacheAffinityManager) CachePeekMode(org.apache.ignite.cache.CachePeekMode) GridCacheQueueHeaderKey(org.apache.ignite.internal.processors.datastructures.GridCacheQueueHeaderKey) Cache(javax.cache.Cache)

Example 7 with CachePeekMode

use of org.apache.ignite.cache.CachePeekMode in project ignite by apache.

the class IgnitePdsCacheRebalancingAbstractTest method testRebalancingWithMixedDataRegionConfigurations.

/**
 * Test rebalancing of in-memory cache on the node with mixed data region configurations.
 *
 * @throws Exception If failed.
 */
@Test
public void testRebalancingWithMixedDataRegionConfigurations() throws Exception {
    int entriesCount = 10_000;
    Ignite ignite0 = startGrids(2);
    ignite0.cluster().active(true);
    IgniteCache<Integer, TestValue> cachePds = ignite0.cache(INDEXED_CACHE);
    IgniteCache<Integer, TestValue> cacheInMem = ignite0.cache(INDEXED_CACHE_IN_MEMORY);
    for (int i = 0; i < entriesCount / 2; i++) {
        TestValue value = new TestValue(i, i * 2, i * 3);
        cachePds.put(i, value);
        cacheInMem.put(i, value);
    }
    forceCheckpoint();
    stopGrid(1);
    for (int i = entriesCount / 2; i < entriesCount; i++) {
        TestValue value = new TestValue(i, i * 2, i * 3);
        cachePds.put(i, value);
        cacheInMem.put(i, value);
    }
    IgniteEx ignite1 = startGrid(1);
    awaitPartitionMapExchange();
    IgniteInternalCache<Integer, TestValue> cachePds1 = ignite1.cachex(INDEXED_CACHE);
    IgniteInternalCache<Integer, TestValue> cacheInMem1 = ignite1.cachex(INDEXED_CACHE_IN_MEMORY);
    CachePeekMode[] peekAll = new CachePeekMode[] { CachePeekMode.ALL };
    assertEquals(entriesCount, cachePds1.localSize(peekAll));
    assertEquals(entriesCount, cacheInMem1.localSize(peekAll));
    for (int i = 0; i < entriesCount; i++) {
        TestValue value = new TestValue(i, i * 2, i * 3);
        assertEquals(value, cachePds1.localPeek(i, peekAll));
        assertEquals(value, cacheInMem1.localPeek(i, peekAll));
    }
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) CachePeekMode(org.apache.ignite.cache.CachePeekMode) IgniteEx(org.apache.ignite.internal.IgniteEx) Ignite(org.apache.ignite.Ignite) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Aggregations

CachePeekMode (org.apache.ignite.cache.CachePeekMode)7 Cache (javax.cache.Cache)2 IgniteCache (org.apache.ignite.IgniteCache)2 IgniteEx (org.apache.ignite.internal.IgniteEx)2 GridCommonAbstractTest (org.apache.ignite.testframework.junits.common.GridCommonAbstractTest)2 Test (org.junit.Test)2 Serializable (java.io.Serializable)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 Factory (javax.cache.configuration.Factory)1 Ignite (org.apache.ignite.Ignite)1 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)1 IgniteException (org.apache.ignite.IgniteException)1 IgniteTransactions (org.apache.ignite.IgniteTransactions)1 BinaryObject (org.apache.ignite.binary.BinaryObject)1 CacheAtomicityMode (org.apache.ignite.cache.CacheAtomicityMode)1 Affinity (org.apache.ignite.cache.affinity.Affinity)1 EvictableEntry (org.apache.ignite.cache.eviction.EvictableEntry)1 EvictionPolicy (org.apache.ignite.cache.eviction.EvictionPolicy)1