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