use of org.apache.ignite.internal.IgniteInternalFuture in project ignite by apache.
the class CacheLateAffinityAssignmentTest method doTestCoordLeaveBlockedFinishExchangeMessage.
/**
* Coordinator leaves without sending all {@link GridDhtPartitionsFullMessage} messages,
* exchange must be completed.
*
* @param cnt Number of nodes.
* @param stopId Node to stop.
* @param lastClient {@code True} if last started node is client.
* @param blockedIds Nodes not receiving exchange finish message.
* @throws Exception If failed.
*/
private void doTestCoordLeaveBlockedFinishExchangeMessage(int cnt, int stopId, boolean lastClient, int... blockedIds) throws Exception {
int ord = 1;
for (int i = 0; i < cnt; i++) {
if (i == cnt - 1 && lastClient)
startClient(ord - 1, ord++);
else
startServer(ord - 1, ord++);
}
awaitPartitionMapExchange();
TestRecordingCommunicationSpi spi0 = TestRecordingCommunicationSpi.spi(grid(0));
final Set<String> blocked = new HashSet<>();
for (int id : blockedIds) {
String name = grid(id).name();
blocked.add(name);
}
spi0.blockMessages(new IgniteBiPredicate<ClusterNode, Message>() {
@Override
public boolean apply(ClusterNode node, Message msg) {
return blocked.contains(node.attribute(IgniteNodeAttributes.ATTR_IGNITE_INSTANCE_NAME)) && (msg instanceof GridDhtPartitionsFullMessage) && (((GridDhtPartitionsFullMessage) msg).exchangeId() != null);
}
});
checkAffinity(cnt, topVer(ord - 1, 1), true);
stopNode(stopId, ord);
AffinityTopologyVersion topVer = topVer(ord, 0);
List<IgniteInternalFuture<?>> futs = new ArrayList<>(cnt);
List<Ignite> grids = G.allGrids();
for (Ignite ignite : grids) futs.add(affinityReadyFuture(topVer, ignite));
assertEquals(futs.size(), grids.size());
for (int i = 0; i < futs.size(); i++) {
final IgniteInternalFuture<?> fut = futs.get(i);
Ignite ignite = grids.get(i);
if (!blocked.contains(ignite.name())) {
GridTestUtils.waitForCondition(new GridAbsPredicate() {
@Override
public boolean apply() {
return fut.isDone();
}
}, 5000);
assertTrue(ignite.name(), fut.isDone());
} else
assertFalse(ignite.name(), fut.isDone());
}
ord++;
// Triggers exchange completion from new coordinator.
stopNode(0, ord);
checkAffinity(cnt - 2, topVer(ord - 1, 0), true, false);
checkAffinity(cnt - 2, topVer(ord, 0), true);
awaitPartitionMapExchange();
}
use of org.apache.ignite.internal.IgniteInternalFuture in project ignite by apache.
the class CacheLateAffinityAssignmentTest method testNodeLeaveExchangeWaitAffinityMessage.
/**
* @throws Exception If failed.
*/
public void testNodeLeaveExchangeWaitAffinityMessage() throws Exception {
System.setProperty(IGNITE_EXCHANGE_COMPATIBILITY_VER_1, "true");
try {
Ignite ignite0 = startServer(0, 1);
startServer(1, 2);
startServer(2, 3);
checkAffinity(3, topVer(3, 1), true);
checkOrderCounters(3, topVer(3, 1));
startClient(3, 4);
checkAffinity(4, topVer(4, 0), true);
TestTcpDiscoverySpi discoSpi = (TestTcpDiscoverySpi) ignite0.configuration().getDiscoverySpi();
discoSpi.blockCustomEvent();
stopGrid(1);
List<IgniteInternalFuture<?>> futs = affFutures(3, topVer(5, 0));
U.sleep(1000);
for (IgniteInternalFuture<?> fut : futs) assertFalse(fut.isDone());
discoSpi.stopBlock();
checkAffinity(3, topVer(5, 0), false);
checkOrderCounters(3, topVer(5, 0));
} finally {
System.clearProperty(IGNITE_EXCHANGE_COMPATIBILITY_VER_1);
}
}
use of org.apache.ignite.internal.IgniteInternalFuture in project ignite by apache.
the class CacheLockReleaseNodeLeaveTest method testLockTopologyChange.
/**
* @throws Exception If failed.
*/
public void testLockTopologyChange() throws Exception {
final int nodeCnt = 5;
int threadCnt = 8;
final int keys = 100;
try {
final AtomicBoolean stop = new AtomicBoolean(false);
Queue<IgniteInternalFuture<Long>> q = new ArrayDeque<>(nodeCnt);
for (int i = 0; i < nodeCnt; i++) {
final Ignite ignite = startGrid(i);
IgniteInternalFuture<Long> f = GridTestUtils.runMultiThreadedAsync(new Runnable() {
@Override
public void run() {
while (!Thread.currentThread().isInterrupted() && !stop.get()) {
IgniteCache<Integer, Integer> cache = ignite.cache(REPLICATED_TEST_CACHE);
for (int i = 0; i < keys; i++) {
Lock lock = cache.lock(i);
lock.lock();
cache.put(i, i);
lock.unlock();
}
}
}
}, threadCnt, "test-lock-thread");
q.add(f);
U.sleep(1_000);
}
stop.set(true);
IgniteInternalFuture<Long> f;
while ((f = q.poll()) != null) f.get(2_000);
} finally {
stopAllGrids();
}
}
use of org.apache.ignite.internal.IgniteInternalFuture in project ignite by apache.
the class IgniteCacheCreatePutMultiNodeSelfTest method testStartNodes.
/**
* @throws Exception If failed.
*/
public void testStartNodes() throws Exception {
try {
Collection<IgniteInternalFuture<?>> futs = new ArrayList<>(GRID_CNT);
int scale = 3;
final CyclicBarrier barrier = new CyclicBarrier(GRID_CNT * scale);
final AtomicReferenceArray<Exception> err = new AtomicReferenceArray<>(GRID_CNT * scale);
for (int i = 0; i < GRID_CNT * scale; i++) {
if (i < GRID_CNT)
startGrid(i);
final int idx = i;
IgniteInternalFuture<Void> fut = GridTestUtils.runAsync(new Callable<Void>() {
@Override
public Void call() throws Exception {
Ignite ignite = ignite(idx % GRID_CNT);
try {
for (int k = 0; k < 50; k++) {
barrier.await();
String cacheName = "cache-" + k;
IgniteCache<Integer, Integer> cache = getCache(ignite, cacheName);
for (int i = 0; i < 100; i++) cache.getAndPut(i, i);
barrier.await();
ignite.destroyCache(cacheName);
}
} catch (Exception e) {
err.set(idx, e);
}
return null;
}
});
futs.add(fut);
}
for (IgniteInternalFuture<?> fut : futs) fut.get(getTestTimeout());
info("Errors: " + err);
for (int i = 0; i < err.length(); i++) {
Exception ex = err.get(i);
if (ex != null)
throw ex;
}
} finally {
stopAllGrids();
}
}
use of org.apache.ignite.internal.IgniteInternalFuture in project ignite by apache.
the class IgniteTxMultiThreadedAbstractTest method testOptimisticSerializableConsistency.
/**
* @throws Exception If failed.
*/
public void testOptimisticSerializableConsistency() throws Exception {
final IgniteCache<Integer, Long> cache = grid(0).cache(DEFAULT_CACHE_NAME);
final int THREADS = 3;
final int ITERATIONS = 100;
for (int key0 = 100_000; key0 < 100_000 + 20; key0++) {
final int key = key0;
cache.put(key, 0L);
List<IgniteInternalFuture<Collection<Long>>> futs = new ArrayList<>(THREADS);
for (int i = 0; i < THREADS; i++) {
futs.add(GridTestUtils.runAsync(new Callable<Collection<Long>>() {
@Override
public Collection<Long> call() throws Exception {
Collection<Long> res = new ArrayList<>();
for (int i = 0; i < ITERATIONS; i++) {
while (true) {
try (Transaction tx = grid(0).transactions().txStart(OPTIMISTIC, SERIALIZABLE)) {
long val = cache.get(key);
cache.put(key, val + 1);
tx.commit();
assertTrue(res.add(val + 1));
break;
} catch (TransactionOptimisticException ignored) {
// Retry.
}
}
}
return res;
}
}));
}
long total = 0;
List<Collection<Long>> cols = new ArrayList<>(THREADS);
for (IgniteInternalFuture<Collection<Long>> fut : futs) {
Collection<Long> col = fut.get();
assertEquals(ITERATIONS, col.size());
total += col.size();
cols.add(col);
}
log.info("Cache value: " + cache.get(key));
Set<Long> duplicates = new HashSet<>();
for (Collection<Long> col1 : cols) {
for (Long val1 : col1) {
for (Collection<Long> col2 : cols) {
if (col1 == col2)
continue;
for (Long val2 : col2) {
if (val1.equals(val2)) {
duplicates.add(val2);
break;
}
}
}
}
}
assertTrue("Found duplicated values: " + duplicates, duplicates.isEmpty());
assertEquals((long) THREADS * ITERATIONS, total);
// Try to update one more time to make sure cache is in consistent state.
try (Transaction tx = grid(0).transactions().txStart(OPTIMISTIC, SERIALIZABLE)) {
long val = cache.get(key);
cache.put(key, val);
tx.commit();
}
for (int i = 0; i < gridCount(); i++) assertEquals(total, grid(i).cache(DEFAULT_CACHE_NAME).get(key));
}
}
Aggregations