Search in sources :

Example 41 with GridCacheAdapter

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

the class JoinInActiveNodeToActiveCluster method joinClientStaticCacheConfigurationInClusterTemplate.

/**
 * {@inheritDoc}
 */
@Override
public JoinNodeTestPlanBuilder joinClientStaticCacheConfigurationInClusterTemplate() throws Exception {
    return staticCacheConfigurationInClusterTemplate().nodeConfiguration(setClient).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(3, desc.size());
                Assert.assertTrue(desc.containsKey(CU.UTILITY_CACHE_NAME));
                Assert.assertTrue(desc.containsKey(cache1));
                Assert.assertTrue(desc.containsKey(cache2));
                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(3, caches.size());
                Assert.assertTrue(caches.containsKey(CU.UTILITY_CACHE_NAME));
                Assert.assertTrue(caches.containsKey(cache1));
                Assert.assertTrue(caches.containsKey(cache2));
            }
        }
    }).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(3, 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(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 42 with GridCacheAdapter

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

the class JoinInActiveNodeToActiveCluster method joinClientStaticCacheConfigurationDifferentOnBothTemplate.

/**
 * {@inheritDoc}
 */
@Override
public JoinNodeTestPlanBuilder joinClientStaticCacheConfigurationDifferentOnBothTemplate() throws Exception {
    return staticCacheConfigurationDifferentOnBothTemplate().nodeConfiguration(setClient).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 43 with GridCacheAdapter

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

the class JoinInActiveNodeToActiveCluster 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(false).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 44 with GridCacheAdapter

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

the class IgniteStandByClusterTest method testStartDynamicCachesAfterActivation.

/**
 * @throws Exception if fail.
 */
@Test
public void testStartDynamicCachesAfterActivation() throws Exception {
    final String cacheName0 = "cache0";
    final String cacheName = "cache";
    IgniteConfiguration cfg1 = getConfiguration("serv1");
    IgniteConfiguration cfg2 = getConfiguration("serv2");
    IgniteConfiguration cfg3 = getConfiguration("client");
    cfg3.setCacheConfiguration(new CacheConfiguration(cacheName0));
    IgniteEx ig1 = startGrid(cfg1);
    IgniteEx ig2 = startGrid(cfg2);
    IgniteEx ig3 = startClientGrid(cfg3);
    assertTrue(!ig1.active());
    assertTrue(!ig2.active());
    assertTrue(!ig3.active());
    ig3.active(true);
    assertTrue(ig1.active());
    assertTrue(ig2.active());
    assertTrue(ig3.active());
    ig3.createCache(new CacheConfiguration<>(cacheName));
    assertNotNull(ig3.cache(cacheName));
    assertNotNull(ig1.cache(cacheName));
    assertNotNull(ig2.cache(cacheName));
    assertNotNull(ig1.cache(cacheName0));
    assertNotNull(ig3.cache(cacheName0));
    assertNotNull(ig2.cache(cacheName0));
    ig3.active(false);
    assertTrue(!ig1.active());
    assertTrue(!ig2.active());
    assertTrue(!ig3.active());
    ig3.active(true);
    assertTrue(ig1.active());
    assertTrue(ig2.active());
    assertTrue(ig3.active());
    assertNotNull(ig1.cache(cacheName));
    assertNotNull(ig2.cache(cacheName));
    Map<String, GridCacheAdapter<?, ?>> caches = U.field(ig3.context().cache(), "caches");
    // Only system cache and cache0
    assertEquals("Unexpected caches: " + caches.keySet(), 3, caches.size());
    assertTrue(caches.containsKey(CU.UTILITY_CACHE_NAME));
    assertTrue(caches.containsKey(cacheName0));
    assertTrue(caches.containsKey(cacheName));
    assertNotNull(ig3.cache(cacheName));
}
Also used : IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) GridCacheAdapter(org.apache.ignite.internal.processors.cache.GridCacheAdapter) IgniteEx(org.apache.ignite.internal.IgniteEx) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 45 with GridCacheAdapter

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

the class GridCacheMultithreadedFailoverTest method compareCaches.

/**
 * Compare caches.
 *
 * @param expVals Expected values.
 * @return {@code True} if check passed successfully.
 * @throws Exception If failed.
 */
@SuppressWarnings({ "TooBroadScope" })
private boolean compareCaches(Map<Integer, Integer> expVals) throws Exception {
    List<IgniteCache<Integer, Integer>> caches = new ArrayList<>(dataNodes());
    List<GridDhtCacheAdapter<Integer, Integer>> dhtCaches = null;
    for (int i = 0; i < dataNodes(); i++) {
        IgniteCache<Integer, Integer> cache = G.ignite(nodeName(i)).cache(CACHE_NAME);
        assert cache != null;
        caches.add(cache);
        GridCacheAdapter<Integer, Integer> cache0 = (GridCacheAdapter<Integer, Integer>) ((IgniteKernal) cache.unwrap(Ignite.class)).<Integer, Integer>getCache(CACHE_NAME);
        if (cache0.isNear()) {
            if (dhtCaches == null)
                dhtCaches = new ArrayList<>(dataNodes());
            dhtCaches.add(((GridNearCacheAdapter<Integer, Integer>) cache0).dht());
        }
    }
    // Compare key sets on each cache.
    Collection<Integer> cacheKeys = new HashSet<>();
    Collection<Integer> dhtCacheKeys = new HashSet<>();
    for (int i = 0; i < dataNodes(); i++) {
        for (Cache.Entry<Integer, Integer> entry : caches.get(i)) cacheKeys.add(entry.getKey());
        if (dhtCaches != null)
            dhtCacheKeys.addAll(dhtCaches.get(i).keySet());
    }
    boolean failed = false;
    if (!F.eq(expVals.keySet(), cacheKeys)) {
        Collection<Integer> expOnly = new HashSet<>();
        Collection<Integer> cacheOnly = new HashSet<>();
        expOnly.addAll(expVals.keySet());
        expOnly.removeAll(cacheKeys);
        cacheOnly.addAll(cacheKeys);
        cacheOnly.removeAll(expVals.keySet());
        if (!expOnly.isEmpty())
            log.error("Cache does not contain expected keys: " + expOnly);
        if (!cacheOnly.isEmpty())
            log.error("Cache does contain unexpected keys: " + cacheOnly);
        failed = true;
    }
    if (dhtCaches != null && !F.eq(expVals.keySet(), dhtCacheKeys)) {
        Collection<Integer> expOnly = new HashSet<>();
        Collection<Integer> cacheOnly = new HashSet<>();
        expOnly.addAll(expVals.keySet());
        expOnly.removeAll(dhtCacheKeys);
        cacheOnly.addAll(dhtCacheKeys);
        cacheOnly.removeAll(expVals.keySet());
        if (!expOnly.isEmpty())
            log.error("DHT cache does not contain expected keys: " + expOnly);
        if (!cacheOnly.isEmpty())
            log.error("DHT cache does contain unexpected keys: " + cacheOnly);
        failed = true;
    }
    // Compare values.
    Collection<Integer> failedKeys = new HashSet<>();
    for (Map.Entry<Integer, Integer> entry : expVals.entrySet()) {
        for (int i = 0; i < dataNodes(); i++) {
            if (!F.eq(caches.get(i).get(entry.getKey()), entry.getValue()))
                failedKeys.add(entry.getKey());
        }
    }
    if (!failedKeys.isEmpty()) {
        log.error("Cache content is incorrect for " + failedKeys.size() + " keys:");
        for (Integer key : failedKeys) {
            for (int i = 0; i < dataNodes(); i++) {
                IgniteCache<Integer, Integer> cache = caches.get(i);
                UUID nodeId = G.ignite(nodeName(i)).cluster().localNode().id();
                if (!F.eq(cache.get(key), expVals.get(key)))
                    log.error("key=" + key + ", expVal=" + expVals.get(key) + ", nodeId=" + nodeId);
            }
        }
        failed = true;
    }
    return !failed;
}
Also used : GridDhtCacheAdapter(org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtCacheAdapter) IgniteCache(org.apache.ignite.IgniteCache) ArrayList(java.util.ArrayList) GridCacheAdapter(org.apache.ignite.internal.processors.cache.GridCacheAdapter) UUID(java.util.UUID) HashMap(java.util.HashMap) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashSet(java.util.HashSet) Cache(javax.cache.Cache) IgniteCache(org.apache.ignite.IgniteCache)

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