use of org.apache.ignite.internal.IgniteEx in project ignite by apache.
the class IgniteDynamicCacheStartSelfTest method testStartStopCacheAddNode.
/**
* @throws Exception If failed.
*/
public void testStartStopCacheAddNode() throws Exception {
final IgniteEx kernal = grid(0);
CacheConfiguration ccfg = new CacheConfiguration(DEFAULT_CACHE_NAME);
ccfg.setCacheMode(CacheMode.REPLICATED);
ccfg.setWriteSynchronizationMode(CacheWriteSynchronizationMode.FULL_SYNC);
ccfg.setName(DYNAMIC_CACHE_NAME);
kernal.createCache(ccfg);
info(">>>>>>> Deployed dynamic cache");
startGrid(nodeCount());
try {
// Check that cache got deployed on new node.
IgniteCache<Object, Object> cache = ignite(nodeCount()).cache(DYNAMIC_CACHE_NAME);
cache.put("1", "1");
for (int g = 0; g < nodeCount() + 1; g++) {
assertEquals("1", grid(g).cache(DYNAMIC_CACHE_NAME).get("1"));
Collection<ClusterNode> nodes = grid(g).affinity(DYNAMIC_CACHE_NAME).mapKeyToPrimaryAndBackups(0);
assertEquals(nodeCount() + 1, nodes.size());
}
// Undeploy cache.
kernal.destroyCache(DYNAMIC_CACHE_NAME);
startGrid(nodeCount() + 1);
// Check that cache is not deployed on new node after undeploy.
for (int g = 0; g < nodeCount() + 2; g++) {
final IgniteKernal kernal0 = (IgniteKernal) grid(g);
for (IgniteInternalFuture f : kernal0.context().cache().context().exchange().exchangeFutures()) f.get();
assertNull(kernal0.cache(DYNAMIC_CACHE_NAME));
}
} finally {
stopGrid(nodeCount() + 1);
stopGrid(nodeCount());
}
}
use of org.apache.ignite.internal.IgniteEx in project ignite by apache.
the class IgniteDynamicCacheStartSelfTest method testStartFromClientNode.
/**
* @throws Exception If failed.
*/
public void testStartFromClientNode() throws Exception {
try {
testAttribute = false;
startGrid(nodeCount());
final IgniteEx kernal = grid(0);
CacheConfiguration ccfg = new CacheConfiguration(DEFAULT_CACHE_NAME);
ccfg.setWriteSynchronizationMode(CacheWriteSynchronizationMode.FULL_SYNC);
ccfg.setName(DYNAMIC_CACHE_NAME);
ccfg.setNodeFilter(NODE_FILTER);
final IgniteKernal started = (IgniteKernal) grid(nodeCount());
started.createCache(ccfg);
GridCacheAdapter<Object, Object> cache = started.internalCache(DYNAMIC_CACHE_NAME);
assertNotNull(cache);
assertFalse(cache.context().affinityNode());
// Should obtain client cache on new node.
IgniteCache<Object, Object> clientCache = ignite(nodeCount()).cache(DYNAMIC_CACHE_NAME);
clientCache.put("1", "1");
for (int g = 0; g < nodeCount() + 1; g++) assertEquals("1", ignite(g).cache(DYNAMIC_CACHE_NAME).get("1"));
kernal.destroyCache(DYNAMIC_CACHE_NAME);
} finally {
stopGrid(nodeCount());
}
}
use of org.apache.ignite.internal.IgniteEx in project ignite by apache.
the class IgniteDynamicCacheStartSelfTest method checkStartStopCachesSimple.
/**
* @param mode Cache atomicity mode.
* @throws Exception If failed.
*/
private void checkStartStopCachesSimple(CacheAtomicityMode mode) throws Exception {
final IgniteEx kernal = grid(0);
final int cacheCnt = 3;
List<CacheConfiguration> ccfgList = new ArrayList<>();
for (int i = 0; i < cacheCnt; i++) {
CacheConfiguration ccfg = new CacheConfiguration(DEFAULT_CACHE_NAME);
ccfg.setWriteSynchronizationMode(CacheWriteSynchronizationMode.FULL_SYNC);
ccfg.setAtomicityMode(mode);
ccfg.setName(DYNAMIC_CACHE_NAME + Integer.toString(i));
ccfgList.add(ccfg);
}
kernal.createCaches(ccfgList);
for (int g = 0; g < nodeCount(); g++) {
IgniteEx kernal0 = grid(g);
for (IgniteInternalFuture f : kernal0.context().cache().context().exchange().exchangeFutures()) f.get();
info("Getting cache for node: " + g);
for (int i = 0; i < cacheCnt; i++) assertNotNull(grid(g).cache(DYNAMIC_CACHE_NAME + Integer.toString(i)));
}
for (int i = 0; i < cacheCnt; i++) grid(0).cache(DYNAMIC_CACHE_NAME + Integer.toString(i)).put(Integer.toString(i), Integer.toString(i));
for (int g = 0; g < nodeCount(); g++) {
for (int i = 0; i < cacheCnt; i++) {
assertEquals(Integer.toString(i), grid(g).cache(DYNAMIC_CACHE_NAME + Integer.toString(i)).get(Integer.toString(i)));
}
}
// Grab caches before stop.
final IgniteCache[] caches = new IgniteCache[nodeCount() * cacheCnt];
for (int g = 0; g < nodeCount(); g++) {
for (int i = 0; i < cacheCnt; i++) caches[g * nodeCount() + i] = grid(g).cache(DYNAMIC_CACHE_NAME + Integer.toString(i));
}
List<String> namesToDestroy = new ArrayList<>();
for (int i = 0; i < cacheCnt; i++) namesToDestroy.add(DYNAMIC_CACHE_NAME + Integer.toString(i));
kernal.destroyCaches(namesToDestroy);
for (int g = 0; g < nodeCount(); g++) {
final IgniteKernal kernal0 = (IgniteKernal) grid(g);
for (int i = 0; i < cacheCnt; i++) {
final int idx = g * nodeCount() + i;
final int expVal = i;
for (IgniteInternalFuture f : kernal0.context().cache().context().exchange().exchangeFutures()) f.get();
assertNull(kernal0.cache(DYNAMIC_CACHE_NAME));
GridTestUtils.assertThrows(log, new Callable<Object>() {
@Override
public Object call() throws Exception {
return caches[idx].get(Integer.toString(expVal));
}
}, IllegalStateException.class, null);
}
}
}
use of org.apache.ignite.internal.IgniteEx in project ignite by apache.
the class IgniteDynamicCacheWithConfigStartSelfTest method testStartCacheOnClient.
/**
* @throws Exception If failed.
*/
public void testStartCacheOnClient() throws Exception {
int srvCnt = 3;
startGrids(srvCnt);
try {
client = true;
IgniteEx client = startGrid(srvCnt);
for (int i = 0; i < 100; i++) client.cache(CACHE_NAME).put(i, i);
for (int i = 0; i < 100; i++) assertEquals(i, grid(0).cache(CACHE_NAME).get(i));
client.cache(CACHE_NAME).removeAll();
for (int i = 0; i < 100; i++) assertNull(grid(0).cache(CACHE_NAME).get(i));
} finally {
stopAllGrids();
}
}
use of org.apache.ignite.internal.IgniteEx in project ignite by apache.
the class IgniteDynamicCacheStartNoExchangeTimeoutTest method oldestNotAffinityNode1.
/**
* @param ccfg Cache configuration.
* @throws Exception If failed.
*/
private void oldestNotAffinityNode1(final CacheConfiguration ccfg) throws Exception {
log.info("Test with cache: " + ccfg.getName());
IgniteEx ignite = grid(0);
assertEquals(1L, ignite.localNode().order());
ccfg.setNodeFilter(new TestFilterExcludeOldest());
assertNotNull(ignite.getOrCreateCache(ccfg));
awaitPartitionMapExchange();
checkCache(ccfg.getName());
}
Aggregations