Search in sources :

Example 21 with GridCacheAdapter

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

the class JoinActiveNodeToActiveCluster method joinClientStaticCacheConfigurationDifferentOnBothTemplate.

/**
 * {@inheritDoc}
 */
@Override
public JoinNodeTestPlanBuilder joinClientStaticCacheConfigurationDifferentOnBothTemplate() throws Exception {
    return staticCacheConfigurationDifferentOnBothTemplate().nodeConfiguration(setClient).afterActivate(new Runnable() {

        @Override
        public void run() {
            for (int i = 0; i < 3; i++) {
                IgniteEx ig = grid(name(i));
                Map<String, DynamicCacheDescriptor> desc = cacheDescriptors(ig);
                Assert.assertEquals(4, desc.size());
                if (!ig.context().discovery().localNode().isClient()) {
                    Assert.assertNotNull(ig.context().cache().cache(cache1));
                    Assert.assertNotNull(ig.context().cache().cache(cache2));
                } else {
                    Assert.assertNull(ig.context().cache().cache(cache1));
                    Assert.assertNotNull(ig.context().cache().cache(cache2));
                }
                Map<String, GridCacheAdapter> caches = caches(ig);
                Assert.assertEquals(4, caches.size());
            }
        }
    }).afterNodeJoin(new Runnable() {

        @Override
        public void run() {
            for (int i = 0; i < 4; i++) {
                IgniteEx ig = grid(name(i));
                Map<String, DynamicCacheDescriptor> desc = cacheDescriptors(ig);
                Assert.assertEquals(4, desc.size());
                if (!ig.context().discovery().localNode().isClient())
                    Assert.assertNotNull(ig.context().cache().cache(cache1));
                Assert.assertNotNull(ig.context().cache().cache(cache2));
                Map<String, GridCacheAdapter> caches = caches(ig);
                if (!ig.context().discovery().localNode().isClient())
                    Assert.assertEquals(4, caches.size());
                else
                    Assert.assertEquals(3, caches.size());
            }
        }
    }).setEnd(new Runnable() {

        @Override
        public void run() {
            for (int i = 0; i < 4; i++) {
                IgniteEx ig = grid(name(i));
                Map<String, DynamicCacheDescriptor> desc = cacheDescriptors(ig);
                Assert.assertEquals(4, desc.size());
                if (!ig.context().discovery().localNode().isClient())
                    Assert.assertNotNull(ig.context().cache().cache(cache1));
                Assert.assertNotNull(ig.context().cache().cache(cache2));
                Map<String, GridCacheAdapter> caches = caches(ig);
                if (!ig.context().discovery().localNode().isClient())
                    Assert.assertEquals(4, caches.size());
                else
                    Assert.assertEquals(3, caches.size());
            }
        }
    });
}
Also used : GridCacheAdapter(org.apache.ignite.internal.processors.cache.GridCacheAdapter) IgniteEx(org.apache.ignite.internal.IgniteEx) DynamicCacheDescriptor(org.apache.ignite.internal.processors.cache.DynamicCacheDescriptor) Map(java.util.Map)

Example 22 with GridCacheAdapter

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

the class JoinActiveNodeToActiveCluster method joinClientStaticCacheConfigurationInClusterTemplate.

/**
 * {@inheritDoc}
 */
@Override
public JoinNodeTestPlanBuilder joinClientStaticCacheConfigurationInClusterTemplate() throws Exception {
    return staticCacheConfigurationInClusterTemplate().nodeConfiguration(setClient).afterActivate(new Runnable() {

        @Override
        public void run() {
            for (int i = 0; i < 3; i++) {
                IgniteEx ig = grid(name(i));
                Map<String, DynamicCacheDescriptor> desc = cacheDescriptors(ig);
                Assert.assertEquals(4, desc.size());
                if (!ig.context().discovery().localNode().isClient()) {
                    Assert.assertNotNull(ig.context().cache().cache(cache1));
                    Assert.assertNotNull(ig.context().cache().cache(cache2));
                } else {
                    Assert.assertNull(ig.context().cache().cache(cache1));
                    Assert.assertNull(ig.context().cache().cache(cache2));
                }
                Map<String, GridCacheAdapter> caches = caches(ig);
                Assert.assertEquals(4, caches.size());
            }
        }
    }).afterNodeJoin(new Runnable() {

        @Override
        public void run() {
            for (int i = 0; i < 3; i++) {
                IgniteEx ig = grid(name(i));
                Map<String, DynamicCacheDescriptor> desc = cacheDescriptors(ig);
                Assert.assertEquals(4, desc.size());
                if (!ig.context().discovery().localNode().isClient()) {
                    Assert.assertNotNull(ig.context().cache().cache(cache1));
                    Assert.assertNotNull(ig.context().cache().cache(cache2));
                } else {
                    Assert.assertNull(ig.context().cache().cache(cache1));
                    Assert.assertNull(ig.context().cache().cache(cache2));
                }
                Map<String, GridCacheAdapter> caches = caches(ig);
                Assert.assertEquals(4, caches.size());
            }
        }
    }).setEnd(new Runnable() {

        @Override
        public void run() {
            for (int i = 0; i < 3; i++) {
                IgniteEx ig = grid(name(i));
                Map<String, DynamicCacheDescriptor> desc = cacheDescriptors(ig);
                Assert.assertEquals(4, desc.size());
                if (!ig.context().discovery().localNode().isClient()) {
                    Assert.assertNotNull(ig.context().cache().cache(cache1));
                    Assert.assertNotNull(ig.context().cache().cache(cache2));
                } else {
                    Assert.assertNull(ig.context().cache().cache(cache1));
                    Assert.assertNull(ig.context().cache().cache(cache2));
                }
                Map<String, GridCacheAdapter> caches = caches(ig);
                Assert.assertEquals(4, caches.size());
            }
        }
    });
}
Also used : GridCacheAdapter(org.apache.ignite.internal.processors.cache.GridCacheAdapter) IgniteEx(org.apache.ignite.internal.IgniteEx) DynamicCacheDescriptor(org.apache.ignite.internal.processors.cache.DynamicCacheDescriptor) Map(java.util.Map)

Example 23 with GridCacheAdapter

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

the class JoinActiveNodeToActiveCluster method staticCacheConfigurationDifferentOnBothTemplate.

/**
 * {@inheritDoc}
 */
@Override
public JoinNodeTestPlanBuilder staticCacheConfigurationDifferentOnBothTemplate() throws Exception {
    JoinNodeTestPlanBuilder b = builder();
    b.clusterConfiguration(cfg(name(0)).setActiveOnStart(true).setCacheConfiguration(atomicCfg()), cfg(name(1)).setActiveOnStart(true), cfg(name(2)).setActiveOnStart(true)).afterClusterStarted(new Runnable() {

        @Override
        public void run() {
            for (int i = 0; i < 3; i++) {
                IgniteEx ig = grid(name(i));
                Map<String, DynamicCacheDescriptor> desc = cacheDescriptors(ig);
                Assert.assertEquals(2, desc.size());
                Assert.assertTrue(desc.containsKey(CU.UTILITY_CACHE_NAME));
                Assert.assertTrue(desc.containsKey(cache1));
                Assert.assertNotNull(ig.context().cache().cache(cache1));
                Assert.assertNull(ig.context().cache().cache(cache2));
                Map<String, GridCacheAdapter> caches = caches(ig);
                Assert.assertEquals(2, caches.size());
                Assert.assertTrue(caches.containsKey(CU.UTILITY_CACHE_NAME));
                Assert.assertTrue(caches.containsKey(cache1));
            }
        }
    }).nodeConfiguration(cfg(name(3)).setActiveOnStart(true).setCacheConfiguration(transactionCfg())).afterNodeJoin(b.checkCacheNotEmpty()).stateAfterJoin(true).afterDeActivate(b.checkCacheEmpty()).setEnd(b.checkCacheNotEmpty());
    return b;
}
Also used : GridCacheAdapter(org.apache.ignite.internal.processors.cache.GridCacheAdapter) IgniteEx(org.apache.ignite.internal.IgniteEx) DynamicCacheDescriptor(org.apache.ignite.internal.processors.cache.DynamicCacheDescriptor)

Example 24 with GridCacheAdapter

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

the class GridCacheTxNodeFailureSelfTest method dataCheck.

/**
 * @param orig Originating cache.
 * @param backup Backup cache.
 * @param key Key being committed and checked.
 * @param commit Commit or rollback flag.
 * @throws Exception If check failed.
 */
private void dataCheck(IgniteKernal orig, IgniteKernal backup, int key, boolean commit) throws Exception {
    GridNearCacheEntry nearEntry = null;
    GridCacheAdapter origCache = orig.internalCache(DEFAULT_CACHE_NAME);
    if (origCache.isNear())
        nearEntry = (GridNearCacheEntry) origCache.peekEx(key);
    GridCacheAdapter backupCache = backup.internalCache(DEFAULT_CACHE_NAME);
    if (backupCache.isNear())
        backupCache = backupCache.context().near().dht();
    GridDhtCacheEntry dhtEntry = (GridDhtCacheEntry) backupCache.entryEx(key);
    dhtEntry.unswap();
    if (commit) {
        assertNotNull(dhtEntry);
        assertTrue("dhtEntry=" + dhtEntry, dhtEntry.remoteMvccSnapshot().isEmpty());
        assertTrue("dhtEntry=" + dhtEntry, dhtEntry.localCandidates().isEmpty());
        assertEquals(key, backupCache.localPeek(key, null));
        if (nearEntry != null) {
            assertTrue("near=" + nearEntry, nearEntry.remoteMvccSnapshot().isEmpty());
            assertTrue("near=" + nearEntry, nearEntry.localCandidates().isEmpty());
            // Near peek wil be null since primary node has changed.
            assertNull("near=" + nearEntry, origCache.localPeek(key, null));
        }
    } else {
        assertTrue("near=" + nearEntry + ", hc=" + System.identityHashCode(nearEntry), nearEntry == null);
        assertTrue("Invalid backup cache entry: " + dhtEntry, dhtEntry.rawGet() == null);
    }
    dhtEntry.touch();
}
Also used : GridNearCacheEntry(org.apache.ignite.internal.processors.cache.distributed.near.GridNearCacheEntry) GridCacheAdapter(org.apache.ignite.internal.processors.cache.GridCacheAdapter)

Example 25 with GridCacheAdapter

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

the class IgniteCacheClientNodeChangingTopologyTest method checkData.

/**
 * @param map Expected data.
 * @param keys Expected keys (if expected data is not specified).
 * @param clientCache Client cache.
 * @param expNodes Expected nodes number.
 * @throws Exception If failed.
 */
private void checkData(final Map<Integer, Integer> map, final Set<Integer> keys, IgniteCache<?, ?> clientCache, final int expNodes) throws Exception {
    final List<Ignite> nodes = G.allGrids();
    final Affinity<Integer> aff = nodes.get(0).affinity(DEFAULT_CACHE_NAME);
    assertEquals(expNodes, nodes.size());
    boolean hasNearCache = clientCache.getConfiguration(CacheConfiguration.class).getNearConfiguration() != null;
    final Ignite nearCacheNode = hasNearCache ? clientCache.unwrap(Ignite.class) : null;
    boolean wait = GridTestUtils.waitForCondition(new PA() {

        @Override
        public boolean apply() {
            try {
                Set<Integer> keys0 = map != null ? map.keySet() : keys;
                assertNotNull(keys0);
                for (Integer key : keys0) {
                    GridCacheVersion ver = null;
                    Object val = null;
                    for (Ignite node : nodes) {
                        IgniteCache<Integer, Integer> cache = node.cache(DEFAULT_CACHE_NAME);
                        boolean affNode = aff.isPrimaryOrBackup(node.cluster().localNode(), key);
                        Object val0 = cache.localPeek(key);
                        if (affNode || node == nearCacheNode) {
                            if (map != null)
                                assertEquals("Unexpected value for " + node.name(), map.get(key), val0);
                            else
                                assertNotNull("Unexpected value for " + node.name(), val0);
                            GridCacheAdapter cache0 = ((IgniteKernal) node).internalCache(DEFAULT_CACHE_NAME);
                            if (affNode && cache0.isNear())
                                cache0 = ((GridNearCacheAdapter) cache0).dht();
                            GridCacheEntryEx entry = cache0.entryEx(key);
                            try {
                                entry.unswap(true);
                                assertNotNull("No entry [node=" + node.name() + ", key=" + key + ']', entry);
                                GridCacheVersion ver0 = entry instanceof GridNearCacheEntry ? ((GridNearCacheEntry) entry).dhtVersion() : entry.version();
                                assertNotNull("Null version [node=" + node.name() + ", key=" + key + ']', ver0);
                                if (ver == null) {
                                    ver = ver0;
                                    val = val0;
                                } else {
                                    assertEquals("Version check failed [node=" + node.name() + ", key=" + key + ", affNode=" + affNode + ", primary=" + aff.isPrimary(node.cluster().localNode(), key) + ']', ver0, ver);
                                    assertEquals("Value check failed [node=" + node.name() + ", key=" + key + ", affNode=" + affNode + ", primary=" + aff.isPrimary(node.cluster().localNode(), key) + ']', val0, val);
                                }
                            } finally {
                                entry.touch();
                            }
                        } else
                            assertNull("Unexpected non-null value for " + node.name(), val0);
                    }
                }
            } catch (AssertionError e) {
                log.info("Check failed, will retry: " + e);
                return false;
            } catch (Exception e) {
                fail("Unexpected exception: " + e);
            }
            return true;
        }
    }, 10_000);
    assertTrue("Data check failed.", wait);
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) GridConcurrentHashSet(org.apache.ignite.internal.util.GridConcurrentHashSet) IgniteCache(org.apache.ignite.IgniteCache) TimeoutException(java.util.concurrent.TimeoutException) IgniteException(org.apache.ignite.IgniteException) IgniteSpiException(org.apache.ignite.spi.IgniteSpiException) CacheException(javax.cache.CacheException) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) PA(org.apache.ignite.internal.util.typedef.PA) GridCacheVersion(org.apache.ignite.internal.processors.cache.version.GridCacheVersion) GridCacheEntryEx(org.apache.ignite.internal.processors.cache.GridCacheEntryEx) GridNearCacheEntry(org.apache.ignite.internal.processors.cache.distributed.near.GridNearCacheEntry) GridCacheAdapter(org.apache.ignite.internal.processors.cache.GridCacheAdapter) Ignite(org.apache.ignite.Ignite)

Aggregations

GridCacheAdapter (org.apache.ignite.internal.processors.cache.GridCacheAdapter)50 IgniteEx (org.apache.ignite.internal.IgniteEx)18 Map (java.util.Map)15 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)15 Ignite (org.apache.ignite.Ignite)12 IgniteException (org.apache.ignite.IgniteException)12 IgniteKernal (org.apache.ignite.internal.IgniteKernal)12 ArrayList (java.util.ArrayList)11 UUID (java.util.UUID)11 Test (org.junit.Test)11 IgniteCache (org.apache.ignite.IgniteCache)10 HashMap (java.util.HashMap)9 ClusterNode (org.apache.ignite.cluster.ClusterNode)9 CacheConfiguration (org.apache.ignite.configuration.CacheConfiguration)9 GridCacheContext (org.apache.ignite.internal.processors.cache.GridCacheContext)9 AffinityTopologyVersion (org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion)8 HashSet (java.util.HashSet)7 IgniteConfiguration (org.apache.ignite.configuration.IgniteConfiguration)7 ClusterTopologyCheckedException (org.apache.ignite.internal.cluster.ClusterTopologyCheckedException)7 DynamicCacheDescriptor (org.apache.ignite.internal.processors.cache.DynamicCacheDescriptor)7