use of org.apache.ignite.internal.IgniteKernal in project ignite by apache.
the class IgniteClientAffinityAssignmentSelfTest method checkAffinityFunction.
/**
* @throws Exception If failed.
*/
private void checkAffinityFunction() throws Exception {
startGridsMultiThreaded(3, true);
long topVer = 3;
try {
checkAffinity(topVer++);
final Ignite ignite3 = startClientGrid(3);
GridTestUtils.assertThrows(log, new Callable<Object>() {
@Override
public Object call() throws Exception {
((IgniteKernal) ignite3).getCache(DEFAULT_CACHE_NAME);
return null;
}
}, IllegalArgumentException.class, null);
// Start client cache.
assertNotNull(ignite3.cache(DEFAULT_CACHE_NAME));
((IgniteKernal) ignite3).getCache(DEFAULT_CACHE_NAME);
checkAffinity(topVer++);
final Ignite ignite4 = startClientGrid(4);
GridTestUtils.assertThrows(log, new Callable<Object>() {
@Override
public Object call() throws Exception {
((IgniteKernal) ignite4).getCache(DEFAULT_CACHE_NAME);
return null;
}
}, IllegalArgumentException.class, null);
// Start client cache.
assertNotNull(ignite4.cache(DEFAULT_CACHE_NAME));
((IgniteKernal) ignite4).getCache(DEFAULT_CACHE_NAME);
checkAffinity(topVer++);
// Node without cache.
final Ignite ignite5 = startClientGrid(5);
GridTestUtils.assertThrows(log, new Callable<Object>() {
@Override
public Object call() throws Exception {
((IgniteKernal) ignite5).getCache(DEFAULT_CACHE_NAME);
return null;
}
}, IllegalArgumentException.class, null);
checkAffinity(topVer++);
stopGrid(5);
checkAffinity(topVer++);
stopGrid(4);
checkAffinity(topVer++);
stopGrid(3);
checkAffinity(topVer);
} finally {
stopAllGrids();
}
}
use of org.apache.ignite.internal.IgniteKernal in project ignite by apache.
the class IgniteClientCacheStartFailoverTest method testRebalanceStateConcurrentStart.
/**
* @throws Exception If failed.
*/
@Test
public void testRebalanceStateConcurrentStart() throws Exception {
final int SRVS1 = 3;
final int CLIENTS = 5;
final int SRVS2 = 5;
startGrids(SRVS1);
Ignite srv0 = ignite(0);
final int KEYS = 1000;
final List<String> cacheNames = startCaches(srv0, KEYS);
final List<Ignite> clients = new ArrayList<>();
for (int i = 0; i < CLIENTS; i++) clients.add(startClientGrid(SRVS1 + i));
final CyclicBarrier barrier = new CyclicBarrier(clients.size() + SRVS2);
final AtomicInteger clientIdx = new AtomicInteger();
final Set<Integer> keys = new HashSet<>();
for (int i = 0; i < KEYS; i++) keys.add(i);
IgniteInternalFuture<?> fut1 = GridTestUtils.runMultiThreadedAsync(new Callable<Void>() {
@Override
public Void call() throws Exception {
barrier.await();
Ignite client = clients.get(clientIdx.getAndIncrement());
for (String cacheName : cacheNames) client.cache(cacheName);
ThreadLocalRandom rnd = ThreadLocalRandom.current();
for (int i = 0; i < 10; i++) {
for (String cacheName : cacheNames) {
IgniteCache<Object, Object> cache = client.cache(cacheName);
Map<Object, Object> map0 = cache.getAll(keys);
assertEquals("[cache=" + cacheName + ", expected=" + KEYS + ", actual=" + map0.size() + ']', KEYS, map0.size());
int key = rnd.nextInt(KEYS);
try {
cache.put(key, i);
} catch (CacheException e) {
log.error("It couldn't put a value [cache=" + cacheName + ", key=" + key + ", val=" + i + ']', e);
CacheConfiguration ccfg = cache.getConfiguration(CacheConfiguration.class);
TransactionSerializationException txEx = X.cause(e, TransactionSerializationException.class);
boolean notContains = !txEx.getMessage().contains("Cannot serialize transaction due to write conflict (transaction is marked for rollback)");
if (txEx == null || ccfg.getAtomicityMode() != TRANSACTIONAL_SNAPSHOT || notContains)
fail("Assert violated because exception was thrown [e=" + e.getMessage() + ']');
}
}
}
return null;
}
}, clients.size(), "client-cache-start");
final AtomicInteger srvIdx = new AtomicInteger(SRVS1 + CLIENTS);
IgniteInternalFuture<?> fut2 = GridTestUtils.runMultiThreadedAsync(new Callable<Void>() {
@Override
public Void call() throws Exception {
barrier.await();
startGrid(srvIdx.incrementAndGet());
return null;
}
}, SRVS2, "node-start");
fut1.get();
fut2.get();
final AffinityTopologyVersion topVer = new AffinityTopologyVersion(SRVS1 + SRVS2 + CLIENTS, 1);
for (Ignite client : clients) {
for (String cacheName : cacheNames) {
final GridDhtPartitionTopology top = ((IgniteKernal) client).context().cache().internalCache(cacheName).context().topology();
GridTestUtils.waitForCondition(new GridAbsPredicate() {
@Override
public boolean apply() {
return top.rebalanceFinished(topVer);
}
}, 5000);
assertTrue(top.rebalanceFinished(topVer));
}
}
}
use of org.apache.ignite.internal.IgniteKernal in project ignite by apache.
the class IgniteDynamicCacheStartSelfTest method checkStartStopCacheSimple.
/**
* @param mode Cache atomicity mode.
* @throws Exception If failed.
*/
private void checkStartStopCacheSimple(CacheAtomicityMode mode) throws Exception {
final IgniteEx kernal = grid(0);
CacheConfiguration ccfg = new CacheConfiguration(DEFAULT_CACHE_NAME);
ccfg.setWriteSynchronizationMode(CacheWriteSynchronizationMode.FULL_SYNC);
ccfg.setAtomicityMode(mode);
ccfg.setName(DYNAMIC_CACHE_NAME);
kernal.createCache(ccfg);
for (int g = 0; g < nodeCount(); g++) {
IgniteEx kernal0 = grid(g);
info("Getting cache for node: " + g);
assertNotNull(grid(g).cache(DYNAMIC_CACHE_NAME));
}
grid(0).cache(DYNAMIC_CACHE_NAME).put("1", "1");
for (int g = 0; g < nodeCount(); g++) assertEquals("1", grid(g).cache(DYNAMIC_CACHE_NAME).get("1"));
// Grab caches before stop.
final IgniteCache[] caches = new IgniteCache[nodeCount()];
for (int g = 0; g < nodeCount(); g++) caches[g] = grid(g).cache(DYNAMIC_CACHE_NAME);
kernal.destroyCache(DYNAMIC_CACHE_NAME);
awaitPartitionMapExchange();
for (int g = 0; g < nodeCount(); g++) {
final IgniteKernal kernal0 = (IgniteKernal) grid(g);
final int idx = g;
assertNull(kernal0.cache(DYNAMIC_CACHE_NAME));
GridTestUtils.assertThrows(log, new Callable<Object>() {
@Override
public Object call() throws Exception {
return caches[idx].get("1");
}
}, IllegalStateException.class, null);
}
}
use of org.apache.ignite.internal.IgniteKernal in project ignite by apache.
the class IgniteDynamicCacheStartSelfTest method testStartFromClientNode.
/**
* @throws Exception If failed.
*/
@Test
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.IgniteKernal in project ignite by apache.
the class IgniteDynamicCacheStartSelfTest method testStartStopCacheAddNode.
/**
* @throws Exception If failed.
*/
@Test
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);
awaitPartitionMapExchange();
// 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);
assertNull(kernal0.cache(DYNAMIC_CACHE_NAME));
}
} finally {
stopGrid(nodeCount() + 1);
stopGrid(nodeCount());
}
}
Aggregations