use of org.apache.ignite.internal.TestRecordingCommunicationSpi in project ignite by apache.
the class IgniteCacheSingleGetMessageTest method getConfiguration.
/** {@inheritDoc} */
@Override
protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName);
cfg.setClientMode(client);
TestRecordingCommunicationSpi commSpi = new TestRecordingCommunicationSpi();
cfg.setCommunicationSpi(commSpi);
((TcpDiscoverySpi) cfg.getDiscoverySpi()).setIpFinder(ipFinder);
return cfg;
}
use of org.apache.ignite.internal.TestRecordingCommunicationSpi in project ignite by apache.
the class IgniteTxCachePrimarySyncTest method checkWaitPrimaryResponse.
/**
* @param client Node executing cache operation.
* @param ccfg Cache configuration.
* @param c Cache update closure.
* @throws Exception If failed.
*/
private void checkWaitPrimaryResponse(Ignite client, final CacheConfiguration<Object, Object> ccfg, final IgniteBiInClosure<Integer, IgniteCache<Object, Object>> c) throws Exception {
Ignite ignite = ignite(0);
assertNotSame(ignite, client);
TestRecordingCommunicationSpi commSpi0 = (TestRecordingCommunicationSpi) ignite.configuration().getCommunicationSpi();
IgniteCache<Object, Object> cache = ignite.cache(ccfg.getName());
final Integer key = primaryKey(cache);
cache.remove(key);
waitKeyRemoved(ccfg.getName(), key);
final IgniteCache<Object, Object> clientCache = client.cache(ccfg.getName());
commSpi0.blockMessages(GridNearTxFinishResponse.class, client.name());
IgniteInternalFuture<?> fut = GridTestUtils.runAsync(new Callable<Void>() {
@Override
public Void call() throws Exception {
c.apply(key, clientCache);
return null;
}
}, "tx-thread");
U.sleep(100);
assertFalse(fut.isDone());
commSpi0.stopBlock(true);
fut.get();
waitKeyUpdated(ignite, ccfg.getBackups() + 1, ccfg.getName(), key);
}
use of org.apache.ignite.internal.TestRecordingCommunicationSpi 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.internal.TestRecordingCommunicationSpi in project ignite by apache.
the class CacheLateAffinityAssignmentTest method testDelayAssignmentClientJoin.
/**
* Wait for rebalance, client node joins.
*
* @throws Exception If failed.
*/
public void testDelayAssignmentClientJoin() throws Exception {
Ignite ignite0 = startServer(0, 1);
TestRecordingCommunicationSpi spi = (TestRecordingCommunicationSpi) ignite0.configuration().getCommunicationSpi();
blockSupplySend(spi, CACHE_NAME1);
startServer(1, 2);
startClient(2, 3);
checkAffinity(3, topVer(3, 0), false);
spi.stopBlock();
checkAffinity(3, topVer(3, 1), true);
}
use of org.apache.ignite.internal.TestRecordingCommunicationSpi in project ignite by apache.
the class CacheLateAffinityAssignmentTest method testDelayAssignmentCoordinatorLeave1.
/**
* Wait for rebalance, coordinator leaves, 2 nodes.
*
* @throws Exception If failed.
*/
public void testDelayAssignmentCoordinatorLeave1() throws Exception {
Ignite ignite0 = startServer(0, 1);
TestRecordingCommunicationSpi spi = (TestRecordingCommunicationSpi) ignite0.configuration().getCommunicationSpi();
blockSupplySend(spi, CACHE_NAME1);
startServer(1, 2);
stopNode(0, 3);
checkAffinity(1, topVer(3, 0), true);
checkNoExchange(1, topVer(3, 1));
awaitPartitionMapExchange();
}
Aggregations