use of org.apache.ignite.internal.IgniteInternalFuture in project ignite by apache.
the class CacheExchangeMergeTest method concurrentStart.
/**
* @param withClients If {@code true} also starts client nodes.
* @throws Exception If failed.
*/
private void concurrentStart(final boolean withClients) throws Exception {
for (int i = 0; i < 5; i++) {
log.info("Iteration: " + i);
startGrid(0);
final AtomicInteger idx = new AtomicInteger(1);
IgniteInternalFuture fut = GridTestUtils.runMultiThreadedAsync(new Callable<Void>() {
@Override
public Void call() throws Exception {
if (withClients)
client.set(ThreadLocalRandom.current().nextBoolean());
int nodeIdx = idx.getAndIncrement();
Ignite node = startGrid(nodeIdx);
checkNodeCaches(node, nodeIdx * 1000, 1000);
return null;
}
}, 10, "start-node");
fut.get();
checkCaches();
startGrid(1000);
checkCaches();
stopAllGrids();
}
}
use of org.apache.ignite.internal.IgniteInternalFuture in project ignite by apache.
the class CacheExchangeMergeTest method startCacheOnJoinAndJoinMerge1.
/**
* @param nodes Number of nodes to start.
* @param withClients If {@code true} starts both servers and clients.
* @throws Exception If failed.
*/
private void startCacheOnJoinAndJoinMerge1(int nodes, boolean withClients) throws Exception {
cfgCache = false;
final IgniteEx srv0 = startGrid(0);
mergeExchangeWaitVersion(srv0, nodes + 1);
if (withClients) {
clientC = new IgniteClosure<String, Boolean>() {
@Override
public Boolean apply(String nodeName) {
return getTestIgniteInstanceIndex(nodeName) % 2 == 0;
}
};
}
cfgCache = true;
IgniteInternalFuture fut = startGridsAsync(srv0, 1, nodes);
fut.get();
checkCaches();
}
use of org.apache.ignite.internal.IgniteInternalFuture in project ignite by apache.
the class CacheExchangeMergeTest method testStartCacheOnJoinAndCoordinatorFailed2.
/**
* @throws Exception If failed.
*/
public void testStartCacheOnJoinAndCoordinatorFailed2() throws Exception {
cfgCache = false;
final Ignite srv0 = startGrid(0);
mergeExchangeWaitVersion(srv0, 3);
cfgCache = true;
IgniteInternalFuture fut = startGridsAsync(srv0, 1, 2);
stopGrid(0);
fut.get();
checkCaches();
}
use of org.apache.ignite.internal.IgniteInternalFuture in project ignite by apache.
the class CacheExchangeMergeTest method testMergeStartStopRandomClientsServers.
/**
* @throws Exception If failed.
*/
public void testMergeStartStopRandomClientsServers() throws Exception {
for (int iter = 0; iter < 3; iter++) {
log.info("Iteration: " + iter);
final int srvs = 5;
final int clients = 5;
Ignite srv0 = startGrids(srvs);
for (int i = 0; i < clients; i++) {
client.set(true);
startGrid(srvs + i);
}
final int threads = 8;
final int initNodes = srvs + clients;
mergeExchangeWaitVersion(srv0, initNodes + threads);
final AtomicInteger idx = new AtomicInteger(initNodes);
final ConcurrentHashSet<Integer> stopNodes = new ConcurrentHashSet<>();
IgniteInternalFuture fut = GridTestUtils.runMultiThreadedAsync(new Callable<Void>() {
@Override
public Void call() throws Exception {
ThreadLocalRandom rnd = ThreadLocalRandom.current();
if (rnd.nextBoolean()) {
Integer stopIdx;
for (; ; ) {
stopIdx = rnd.nextInt(initNodes - 1) + 1;
if (stopNodes.add(stopIdx))
break;
}
log.info("Stop node: " + stopIdx);
stopGrid(getTestIgniteInstanceName(stopIdx), true, false);
} else {
int nodeIdx = idx.incrementAndGet();
if (rnd.nextInt(5) == 0) {
log.info("Start client: " + nodeIdx);
client.set(true);
} else
log.info("Start server: " + nodeIdx);
startGrid(nodeIdx);
}
return null;
}
}, threads, "test-thread");
fut.get();
checkCaches();
stopAllGrids();
}
}
use of org.apache.ignite.internal.IgniteInternalFuture in project ignite by apache.
the class CacheAbstractRestartSelfTest method testRestart.
/**
* @throws Exception If failed.
*/
public void testRestart() throws Exception {
final int clientGrid = gridCount() - 1;
assertTrue(ignite(clientGrid).configuration().isClientMode());
final IgniteEx grid = grid(clientGrid);
final IgniteCache cache = jcache(clientGrid);
updateCache(grid, cache);
final AtomicBoolean stop = new AtomicBoolean();
ArrayList<IgniteInternalFuture> updaterFuts = new ArrayList<>();
for (int i = 0; i < updatersNumber(); i++) {
final int threadIdx = i;
IgniteInternalFuture<?> updateFut = GridTestUtils.runAsync(new Callable<Void>() {
@Override
public Void call() throws Exception {
Thread.currentThread().setName("update-thread-" + threadIdx);
assertTrue(cacheCheckedLatch.await(30_000, TimeUnit.MILLISECONDS));
int iter = 0;
while (!stop.get()) {
log.info("Start update: " + iter);
rwl.readLock().lock();
try {
updateCache(grid, cache);
} finally {
rwl.readLock().unlock();
}
log.info("End update: " + iter++);
}
log.info("Update iterations: " + iter);
return null;
}
});
updaterFuts.add(updateFut);
}
IgniteInternalFuture<?> restartFut = GridTestUtils.runAsync(new Callable<Void>() {
@Override
public Void call() throws Exception {
Thread.currentThread().setName("restart-thread");
ThreadLocalRandom rnd = ThreadLocalRandom.current();
while (!stop.get()) {
assertTrue(cacheCheckedLatch.await(30_000, TimeUnit.MILLISECONDS));
int node = rnd.nextInt(0, gridCount() - 1);
log.info("Stop node: " + node);
stopGrid(node);
U.sleep(restartSleep());
log.info("Start node: " + node);
startGrid(node);
cacheCheckedLatch = new CountDownLatch(1);
U.sleep(restartDelay());
awaitPartitionMapExchange();
}
return null;
}
});
long endTime = System.currentTimeMillis() + getTestDuration();
try {
int iter = 0;
while (System.currentTimeMillis() < endTime && !isAnyDone(updaterFuts) && !restartFut.isDone()) {
try {
log.info("Start of cache checking: " + iter);
rwl.writeLock().lock();
try {
checkCache(grid, cache);
} finally {
rwl.writeLock().unlock();
}
log.info("End of cache checking: " + iter++);
} finally {
cacheCheckedLatch.countDown();
}
}
log.info("Checking iteration: " + iter);
} finally {
cacheCheckedLatch.countDown();
stop.set(true);
}
for (IgniteInternalFuture fut : updaterFuts) fut.get();
restartFut.get();
checkCache(grid, cache);
}
Aggregations