use of org.apache.ignite.plugin.extensions.communication.Message in project ignite by apache.
the class IgniteCacheClientMultiNodeUpdateTopologyLockTest method testPessimisticTx.
/**
* @throws Exception If failed.
*/
public void testPessimisticTx() throws Exception {
startGrids(3);
client = true;
Ignite clientNode = startGrid(3);
client = false;
IgniteCache<Integer, Integer> cache = clientNode.createCache(cacheConfiguration(0, FULL_SYNC));
awaitPartitionMapExchange();
Integer key1 = movingKeysAfterJoin(ignite(1), TEST_CACHE, 1).get(0);
Integer key2 = movingKeysAfterJoin(ignite(2), TEST_CACHE, 1).get(0);
log.info("Start tx [key1=" + key1 + ", key2=" + key2 + ']');
IgniteInternalFuture<?> startFut;
TestRecordingCommunicationSpi spi2 = TestRecordingCommunicationSpi.spi(ignite(2));
final TestRecordingCommunicationSpi clientSpi = TestRecordingCommunicationSpi.spi(clientNode);
final UUID node0Id = ignite(0).cluster().localNode().id();
final UUID node2Id = ignite(2).cluster().localNode().id();
spi2.record(new IgniteBiPredicate<ClusterNode, Message>() {
@Override
public boolean apply(ClusterNode node, Message msg) {
if (!node0Id.equals(node.id()))
return false;
return (msg instanceof GridDhtPartitionsSingleMessage) && ((GridDhtPartitionsSingleMessage) msg).exchangeId() != null;
}
});
clientSpi.blockMessages(new IgniteBiPredicate<ClusterNode, Message>() {
@Override
public boolean apply(final ClusterNode node, final Message msg) {
if (!node2Id.equals(node.id()))
return false;
if (msg instanceof GridNearTxFinishRequest) {
log.info("Delay message [msg=" + msg + ']');
GridTestUtils.runAsync(new Runnable() {
@Override
public void run() {
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
e.printStackTrace();
}
log.info("Send delayed message [msg=" + msg + ']');
clientSpi.stopBlock(true);
}
});
return true;
}
return false;
}
});
try (Transaction tx = clientNode.transactions().txStart(PESSIMISTIC, REPEATABLE_READ)) {
cache.put(key1, 1);
startFut = GridTestUtils.runAsync(new Callable<Object>() {
@Override
public Object call() throws Exception {
startGrid(4);
return null;
}
}, "start-thread");
spi2.waitForRecorded();
U.sleep(5);
cache.put(key2, 2);
log.info("Commit tx");
tx.commit();
}
assertEquals((Integer) 1, cache.get(key1));
assertEquals((Integer) 2, cache.get(key2));
startFut.get();
assertEquals((Integer) 1, cache.get(key1));
assertEquals((Integer) 2, cache.get(key2));
awaitPartitionMapExchange();
assertEquals((Integer) 1, cache.get(key1));
assertEquals((Integer) 2, cache.get(key2));
}
use of org.apache.ignite.plugin.extensions.communication.Message in project ignite by apache.
the class IgniteTxPessimisticOriginatingNodeFailureAbstractSelfTest method getConfiguration.
/**
* {@inheritDoc}
*/
@Override
protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName);
cfg.setCommunicationSpi(new TcpCommunicationSpi() {
@Override
public void sendMessage(ClusterNode node, Message msg, IgniteInClosure<IgniteException> ackClosure) throws IgniteSpiException {
if (getSpiContext().localNode().id().equals(failingNodeId)) {
if (ignoredMessage((GridIoMessage) msg) && ignoreMsgNodeIds != null) {
for (UUID ignored : ignoreMsgNodeIds) {
if (node.id().equals(ignored))
return;
}
}
}
super.sendMessage(node, msg, ackClosure);
}
});
cfg.getTransactionConfiguration().setDefaultTxConcurrency(PESSIMISTIC);
return cfg;
}
use of org.apache.ignite.plugin.extensions.communication.Message in project ignite by apache.
the class GridH2ValueMessageFactory method fillArray.
/**
* @param src Source iterator.
* @param dst Array to fill with values.
* @param ctx Kernal context.
* @return Filled array.
* @throws IgniteCheckedException If failed.
*/
public static Value[] fillArray(Iterator<? extends Message> src, Value[] dst, GridKernalContext ctx) throws IgniteCheckedException {
for (int i = 0; i < dst.length; i++) {
Message msg = src.next();
dst[i] = ((GridH2ValueMessage) msg).value(ctx);
}
return dst;
}
use of org.apache.ignite.plugin.extensions.communication.Message in project ignite by apache.
the class IgniteCacheTxRecoveryRollbackTest method nearTx2.
/**
* Stop both tx near node (client2) and primary node, near cache tx on client1 is invalidated.
*
* @param concurrency Tx concurrency or {@code null} for implicit transaction.
* @throws Exception If failed.
*/
private void nearTx2(final TransactionConcurrency concurrency) throws Exception {
startGrids(4);
Ignite srv0 = grid(0);
srv0.createCache(cacheConfiguration(2, false, false));
awaitPartitionMapExchange();
client = true;
Ignite client1 = startGrid(4);
final Ignite client2 = startGrid(5);
final Integer key = primaryKey(srv0.cache(DEFAULT_CACHE_NAME));
final IgniteCache<Integer, Integer> cache1 = client1.createNearCache(DEFAULT_CACHE_NAME, new NearCacheConfiguration<Integer, Integer>());
final IgniteCache<Integer, Integer> cache2 = client2.createNearCache(DEFAULT_CACHE_NAME, new NearCacheConfiguration<Integer, Integer>());
cache1.put(key, 1);
final Integer newVal = 2;
testSpi(client2).blockMessages(GridNearTxFinishRequest.class, srv0.name());
testSpi(srv0).blockMessages(new IgniteBiPredicate<ClusterNode, Message>() {
@Override
public boolean apply(ClusterNode node, Message msg) {
return msg instanceof GridDhtTxFinishRequest;
}
});
IgniteInternalFuture<?> fut = GridTestUtils.runAsync(new Callable<Void>() {
@Override
public Void call() throws Exception {
log.info("Start put, concurrency: " + concurrency);
if (concurrency != null) {
try (Transaction tx = client2.transactions().txStart(concurrency, REPEATABLE_READ)) {
cache2.put(key, newVal);
tx.commit();
}
} else
cache2.put(key, newVal);
return null;
}
});
U.sleep(500);
assertFalse(fut.isDone());
testSpi(client2).waitForBlocked(GridNearTxFinishRequest.class, srv0.name());
stopGrid(client2.name());
stopGrid(srv0.name());
try {
fut.get();
} catch (IgniteCheckedException ignore) {
// No-op.
}
final IgniteCache<Integer, Integer> srvCache = grid(1).cache(DEFAULT_CACHE_NAME);
GridTestUtils.waitForCondition(new GridAbsPredicate() {
@Override
public boolean apply() {
return newVal.equals(srvCache.get(key)) && newVal.equals(cache1.get(key));
}
}, 5000);
checkData(F.asMap(key, newVal));
}
use of org.apache.ignite.plugin.extensions.communication.Message in project ignite by apache.
the class IgniteCacheAtomicProtocolTest method putAllMissedDhtRequest_UnstableTopology.
/**
* @param fail0 Fail node 0 flag.
* @param fail1 Fail node 1 flag.
* @throws Exception If failed.
*/
private void putAllMissedDhtRequest_UnstableTopology(boolean fail0, boolean fail1) throws Exception {
blockRebalance = true;
ccfg = cacheConfiguration(1, FULL_SYNC);
startServers(4);
client = true;
Ignite client = startGrid(4);
IgniteCache<Integer, Integer> nearCache = client.cache(TEST_CACHE);
if (fail0) {
testSpi(ignite(0)).blockMessages(new IgniteBiPredicate<ClusterNode, Message>() {
@Override
public boolean apply(ClusterNode node, Message msg) {
return msg instanceof GridDhtAtomicAbstractUpdateRequest;
}
});
}
if (fail1) {
testSpi(ignite(2)).blockMessages(new IgniteBiPredicate<ClusterNode, Message>() {
@Override
public boolean apply(ClusterNode node, Message msg) {
return msg instanceof GridDhtAtomicAbstractUpdateRequest;
}
});
}
Integer key1 = primaryKey(ignite(0).cache(TEST_CACHE));
Integer key2 = primaryKey(ignite(2).cache(TEST_CACHE));
log.info("Start put [key1=" + key1 + ", key2=" + key1 + ']');
Map<Integer, Integer> map = new HashMap<>();
map.put(key1, 10);
map.put(key2, 20);
IgniteFuture<?> fut = nearCache.putAllAsync(map);
U.sleep(500);
assertFalse(fut.isDone());
if (fail0)
stopGrid(0);
if (fail1)
stopGrid(2);
fut.get();
checkData(map);
}
Aggregations