use of org.apache.ignite.internal.IgniteEx in project ignite by apache.
the class IgnitePdsCheckpointSimpleTest method testRecoveryAfterCpEnd.
/**
* Checks if same data can be loaded after checkpoint.
* @throws Exception if failed.
*/
public void testRecoveryAfterCpEnd() throws Exception {
IgniteEx ignite = startGrid(0);
ignite.active(true);
IgniteCache<Object, Object> cache = ignite.getOrCreateCache("cache");
for (int i = 0; i < 10000; i++) cache.put(i, valueWithRedundancyForKey(i));
ignite.context().cache().context().database().waitForCheckpoint("test");
stopAllGrids();
IgniteEx igniteRestart = startGrid(0);
igniteRestart.active(true);
IgniteCache<Object, Object> cacheRestart = igniteRestart.getOrCreateCache("cache");
for (int i = 0; i < 10000; i++) assertEquals(valueWithRedundancyForKey(i), cacheRestart.get(i));
stopAllGrids();
}
use of org.apache.ignite.internal.IgniteEx in project ignite by apache.
the class ReplicatedAtomicCacheGetsDistributionTest method runTestSameHostDistribution.
/**
* Tests that the 'get' and 'getAll' requests are routed to node with same MAC address as at requester.
*
* @param destId Destination Ignite instance id for requests distribution.
* @param batchMode Test mode.
* @throws Exception In case of an error.
*/
protected void runTestSameHostDistribution(final UUID destId, final boolean batchMode) throws Exception {
Map<UUID, String> macs = getClusterMacs();
String clientMac = macs.get(grid(CLIENT_NAME).localNode().id());
macs.put(destId, clientMac);
replaceMacAddresses(G.allGrids(), macs);
IgniteCache<Integer, String> cache = grid(0).createCache(cacheConfiguration());
List<Integer> keys = primaryKeys(cache, PRIMARY_KEYS_NUMBER);
for (Integer key : keys) cache.put(key, VAL_PREFIX + key);
IgniteCache<Integer, String> clientCache = grid(CLIENT_NAME).getOrCreateCache(CACHE_NAME);
try (Transaction tx = grid(CLIENT_NAME).transactions().txStart()) {
if (batchMode) {
Map<Integer, String> results = clientCache.getAll(new TreeSet<>(keys));
for (Map.Entry<Integer, String> entry : results.entrySet()) assertEquals(VAL_PREFIX + entry.getKey(), entry.getValue());
} else {
for (Integer key : keys) assertEquals(VAL_PREFIX + key, clientCache.get(key));
}
tx.commit();
}
for (int i = 0; i < gridCount(); i++) {
IgniteEx ignite = grid(i);
long getsCnt = ignite.cache(CACHE_NAME).localMetrics().getCacheGets();
if (destId.equals(ignite.localNode().id()))
assertEquals(PRIMARY_KEYS_NUMBER, getsCnt);
else
assertEquals(0L, getsCnt);
}
}
use of org.apache.ignite.internal.IgniteEx in project ignite by apache.
the class GridCacheRebalancingWithAsyncClearingTest method testPartitionClearingNotBlockExchange.
/**
* Test that partition clearing doesn't block partitions map exchange.
*
* @throws Exception If failed.
*/
public void testPartitionClearingNotBlockExchange() throws Exception {
System.setProperty(IgniteSystemProperties.IGNITE_PDS_MAX_CHECKPOINT_MEMORY_HISTORY_SIZE, "1");
IgniteEx ig = (IgniteEx) startGrids(3);
ig.cluster().active(true);
// High number of keys triggers long partition eviction.
final int keysCount = 300_000;
try (IgniteDataStreamer ds = ig.dataStreamer(CACHE_NAME)) {
log.info("Writing initial data...");
ds.allowOverwrite(true);
for (int k = 1; k <= keysCount; k++) {
ds.addData(k, k);
if (k % 50_000 == 0)
log.info("Written " + k + " entities.");
}
log.info("Writing initial data finished.");
}
stopGrid(2);
awaitPartitionMapExchange();
try (IgniteDataStreamer ds = ig.dataStreamer(CACHE_NAME)) {
log.info("Writing external data...");
ds.allowOverwrite(true);
for (int k = 1; k <= keysCount; k++) {
ds.addData(k, 2 * k);
if (k % 50_000 == 0)
log.info("Written " + k + " entities.");
}
log.info("Writing external data finished.");
}
IgniteCache<Integer, Integer> cache = ig.cache(CACHE_NAME);
forceCheckpoint();
GridCachePartitionExchangeManager exchangeManager = ig.cachex(CACHE_NAME).context().shared().exchange();
long topVer = exchangeManager.lastTopologyFuture().topologyVersion().topologyVersion();
startGrid(2);
// Check that exchange future is completed and version is incremented
GridDhtPartitionsExchangeFuture fut1 = exchangeManager.lastTopologyFuture();
fut1.get();
Assert.assertEquals(topVer + 1, fut1.topologyVersion().topologyVersion());
// Check that additional exchange didn't influence on asynchronous partitions eviction.
boolean asyncClearingIsRunning = false;
for (int p = 0; p < PARTITIONS_CNT; p++) {
GridDhtLocalPartition part = grid(2).cachex(CACHE_NAME).context().topology().localPartition(p);
if (part != null && part.state() == GridDhtPartitionState.MOVING && part.isClearing()) {
asyncClearingIsRunning = true;
break;
}
}
Assert.assertTrue("Async clearing is not running at the moment", asyncClearingIsRunning);
// Check that stopping & starting node didn't break rebalance process.
stopGrid(1);
startGrid(1);
// Wait for rebalance on all nodes.
for (Ignite ignite : G.allGrids()) ignite.cache(CACHE_NAME).rebalance().get();
// Check no data loss.
for (int k = 1; k <= keysCount; k++) {
Integer value = cache.get(k);
Assert.assertNotNull("Value for " + k + " is null", value);
Assert.assertEquals("Check failed for " + k + " " + value, 2 * k, (int) value);
}
}
use of org.apache.ignite.internal.IgniteEx 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.IgniteEx 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());
}
}
});
}
Aggregations