use of org.apache.ignite.internal.processors.cache.GridCacheMvccManager in project ignite by apache.
the class CacheGetReadFromBackupFailoverTest method testFailover.
/**
* @throws Exception If failed.
*/
@Test
public void testFailover() throws Exception {
Ignite ignite = ignite(0);
ignite.cluster().active(true);
ThreadLocalRandom rnd = ThreadLocalRandom.current();
try (IgniteDataStreamer<Object, Object> stmr = ignite.dataStreamer(TX_CACHE)) {
for (int i = 0; i < KEYS_CNT; i++) stmr.addData(i, rnd.nextLong());
}
try (IgniteDataStreamer<Object, Object> stmr = ignite.dataStreamer(ATOMIC_CACHE)) {
for (int i = 0; i < KEYS_CNT; i++) stmr.addData(i, rnd.nextLong());
}
AtomicInteger idx = new AtomicInteger(-1);
AtomicInteger successGet = new AtomicInteger();
IgniteInternalFuture fut = GridTestUtils.runAsync(() -> {
ThreadLocalRandom rnd0 = ThreadLocalRandom.current();
while (!stop.get()) {
Ignite ig = null;
while (ig == null) {
int n = rnd0.nextInt(gridCount());
if (idx.get() != n) {
try {
ig = ignite(n);
} catch (IgniteIllegalStateException e) {
// No-op.
}
}
}
try {
if (rnd.nextBoolean()) {
ig.cache(TX_CACHE).get(rnd0.nextLong(KEYS_CNT));
ig.cache(ATOMIC_CACHE).get(rnd0.nextLong(KEYS_CNT));
} else {
ig.cache(TX_CACHE).getAll(rnd.longs(16, 0, KEYS_CNT).boxed().collect(Collectors.toSet()));
ig.cache(ATOMIC_CACHE).getAll(rnd.longs(16, 0, KEYS_CNT).boxed().collect(Collectors.toSet()));
}
successGet.incrementAndGet();
} catch (CacheException e) {
if (!X.hasCause(e, NodeStoppingException.class))
throw e;
}
}
}, "load-thread");
long startTime = System.currentTimeMillis();
while (System.currentTimeMillis() - startTime < 30 * 1000L) {
int idx0 = idx.get();
if (idx0 >= 0)
startGrid(idx0);
U.sleep(500);
int next = rnd.nextInt(gridCount());
idx.set(next);
stopGrid(next);
U.sleep(500);
}
stop.set(true);
while (true) {
try {
fut.get(10_000);
break;
} catch (IgniteFutureTimeoutCheckedException e) {
for (Ignite i : G.allGrids()) {
IgniteEx ex = (IgniteEx) i;
log.info(">>>> " + ex.context().localNodeId());
GridCacheMvccManager mvcc = ex.context().cache().context().mvcc();
for (GridCacheFuture<?> fut0 : mvcc.activeFutures()) {
log.info("activeFut - " + fut0);
}
for (GridCacheFuture<?> fut0 : mvcc.atomicFutures()) {
log.info("atomicFut - " + fut0);
}
}
}
}
Assert.assertTrue(String.valueOf(successGet.get()), successGet.get() > 50);
Throwable e = err.get();
if (e != null) {
log.error("Test failed", e);
fail("Test failed");
}
}
Aggregations