use of org.apache.ignite.internal.IgniteEx in project ignite by apache.
the class IgniteWalRecoveryTest method testRecoveryOnTransactionalAndPartitionedCache.
/**
* Test recovery from WAL on 3 nodes in case of transactional cache.
*
* @throws Exception If fail.
*/
public void testRecoveryOnTransactionalAndPartitionedCache() throws Exception {
IgniteEx ignite = (IgniteEx) startGrids(3);
ignite.active(true);
try {
final String cacheName = "transactional";
CacheConfiguration<Object, Object> cacheConfiguration = new CacheConfiguration<>(cacheName).setAtomicityMode(CacheAtomicityMode.TRANSACTIONAL).setAffinity(new RendezvousAffinityFunction(false, 32)).setCacheMode(CacheMode.PARTITIONED).setRebalanceMode(CacheRebalanceMode.SYNC).setWriteSynchronizationMode(CacheWriteSynchronizationMode.FULL_SYNC).setBackups(2);
ignite.createCache(cacheConfiguration);
IgniteCache<Object, Object> cache = ignite.cache(cacheName);
Map<Object, Object> map = new HashMap<>();
final int transactions = 100;
final int operationsPerTransaction = 40;
Random random = new Random();
for (int t = 1; t <= transactions; t++) {
Transaction tx = ignite.transactions().txStart(TransactionConcurrency.OPTIMISTIC, TransactionIsolation.READ_COMMITTED);
Map<Object, Object> changesInTransaction = new HashMap<>();
for (int op = 0; op < operationsPerTransaction; op++) {
int key = random.nextInt(1000) + 1;
Object value;
if (random.nextBoolean())
value = randomString(random) + key;
else
value = new BigObject(key);
changesInTransaction.put(key, value);
cache.put(key, value);
}
if (random.nextBoolean()) {
tx.commit();
map.putAll(changesInTransaction);
} else {
tx.rollback();
}
if (t % 50 == 0)
log.info("Finished transaction " + t);
}
stopAllGrids();
ignite = (IgniteEx) startGrids(3);
ignite.active(true);
cache = ignite.cache(cacheName);
for (Object key : map.keySet()) {
Object expectedValue = map.get(key);
Object actualValue = cache.get(key);
Assert.assertEquals("Unexpected value for key " + key, expectedValue, actualValue);
}
} finally {
stopAllGrids();
}
}
use of org.apache.ignite.internal.IgniteEx in project ignite by apache.
the class IgniteWalRecoveryTest method testWalSimple.
/**
* @throws Exception if failed.
*/
public void testWalSimple() throws Exception {
try {
IgniteEx ignite = startGrid(1);
ignite.active(true);
IgniteCache<Object, Object> cache = ignite.cache("partitioned");
info(" --> step1");
for (int i = 0; i < 10_000; i += 2) {
// X.println(" -> put: " + i);
cache.put(i, new IndexedObject(i));
}
info(" --> step2");
for (int i = 0; i < 10_000; i += 3) cache.put(i, new IndexedObject(i * 2));
info(" --> step3");
for (int i = 0; i < 10_000; i += 7) cache.put(i, new IndexedObject(i * 3));
info(" --> check1");
// Check.
for (int i = 0; i < 10_000; i++) {
IndexedObject o;
if (i % 7 == 0)
o = new IndexedObject(i * 3);
else if (i % 3 == 0)
o = new IndexedObject(i * 2);
else if (i % 2 == 0)
o = new IndexedObject(i);
else
o = null;
assertEquals(o, cache.get(i));
}
stopGrid(1);
ignite = startGrid(1);
ignite.active(true);
cache = ignite.cache("partitioned");
info(" --> check2");
// Check.
for (int i = 0; i < 10_000; i++) {
IndexedObject o;
if (i % 7 == 0)
o = new IndexedObject(i * 3);
else if (i % 3 == 0)
o = new IndexedObject(i * 2);
else if (i % 2 == 0)
o = new IndexedObject(i);
else
o = null;
assertEquals(o, cache.get(i));
}
info(" --> ok");
} finally {
stopAllGrids();
}
}
use of org.apache.ignite.internal.IgniteEx in project ignite by apache.
the class IgniteWalRecoveryTest method testRecoveryNoCheckpoint.
/**
* @throws Exception if failed.
*/
public void testRecoveryNoCheckpoint() throws Exception {
try {
IgniteEx ctrlGrid = startGrid(0);
fork = true;
IgniteEx cacheGrid = startGrid(1);
ctrlGrid.active(true);
ctrlGrid.compute(ctrlGrid.cluster().forRemotes()).run(new LoadRunnable(false));
info("Killing remote process...");
((IgniteProcessProxy) cacheGrid).kill();
final IgniteEx g0 = ctrlGrid;
GridTestUtils.waitForCondition(new PA() {
/**
* {@inheritDoc}
*/
@Override
public boolean apply() {
return g0.cluster().nodes().size() == 1;
}
}, getTestTimeout());
fork = false;
// Now start the grid and verify that updates were restored from WAL.
cacheGrid = startGrid(1);
IgniteCache<Object, Object> cache = cacheGrid.cache("partitioned");
for (int i = 0; i < 10_000; i++) assertEquals(new IndexedObject(i), cache.get(i));
List<List<?>> res = cache.query(new SqlFieldsQuery("select count(iVal) from IndexedObject")).getAll();
assertEquals(1, res.size());
assertEquals(10_000L, res.get(0).get(0));
} finally {
stopAllGrids();
}
}
use of org.apache.ignite.internal.IgniteEx in project ignite by apache.
the class IgniteWalRecoveryTest method testRandomCrash.
/**
* @throws Exception if failed.
*/
public void testRandomCrash() throws Exception {
try {
IgniteEx ctrlGrid = startGrid(0);
fork = true;
IgniteEx cacheGrid = startGrid(1);
ctrlGrid.active(true);
IgniteCompute rmt = ctrlGrid.compute(ctrlGrid.cluster().forRemotes());
rmt.run(new LoadRunnable(false));
info(">>> Finished cache population.");
rmt.run(new AsyncLoadRunnable());
Thread.sleep(20_000);
info(">>> Killing remote process...");
((IgniteProcessProxy) cacheGrid).kill();
startGrid(1);
Boolean res = rmt.call(new VerifyCallable());
assertTrue(res);
} finally {
stopAllGrids();
}
}
use of org.apache.ignite.internal.IgniteEx in project ignite by apache.
the class IgniteWalRecoveryTest method testLargeRandomCrash.
/**
* @throws Exception if failed.
*/
public void testLargeRandomCrash() throws Exception {
try {
IgniteEx ctrlGrid = startGrid(0);
fork = true;
IgniteEx cacheGrid = startGrid(1);
ctrlGrid.active(true);
IgniteCompute rmt = ctrlGrid.compute(ctrlGrid.cluster().forRemotes());
rmt.run(new LargeLoadRunnable(false));
info(">>> Finished cache population.");
rmt.run(new AsyncLargeLoadRunnable());
Thread.sleep(20_000);
info(">>> Killing remote process...");
((IgniteProcessProxy) cacheGrid).kill();
startGrid(1);
Boolean res = rmt.call(new VerifyLargeCallable());
assertTrue(res);
} finally {
stopAllGrids();
}
}
Aggregations