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());
}
}
});
}
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());
}
}
});
}
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;
}
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));
}
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;
}
Aggregations