use of org.apache.ignite.internal.TestRecordingCommunicationSpi in project ignite by apache.
the class CacheLateAffinityAssignmentTest method testAffinitySimpleNoCacheOnCoordinator2.
/**
* @throws Exception If failed.
*/
public void testAffinitySimpleNoCacheOnCoordinator2() throws Exception {
System.setProperty(IGNITE_EXCHANGE_COMPATIBILITY_VER_1, "true");
try {
cacheC = new IgniteClosure<String, CacheConfiguration[]>() {
@Override
public CacheConfiguration[] apply(String igniteInstanceName) {
if (igniteInstanceName.equals(getTestIgniteInstanceName(1)) || igniteInstanceName.equals(getTestIgniteInstanceName(2)))
return null;
return new CacheConfiguration[] { cacheConfiguration() };
}
};
cacheNodeFilter = new TestCacheNodeExcludingFilter(F.asList(getTestIgniteInstanceName(1), getTestIgniteInstanceName(2)));
startServer(0, 1);
startServer(1, 2);
startServer(2, 3);
startServer(3, 4);
for (int i = 0; i < 4; i++) {
TestRecordingCommunicationSpi spi = (TestRecordingCommunicationSpi) ignite(i).configuration().getCommunicationSpi();
// Prevent exchange finish while node0 or node1 is coordinator.
spi.blockMessages(GridDhtPartitionsSingleMessage.class, ignite(0).name());
spi.blockMessages(GridDhtPartitionsSingleMessage.class, ignite(1).name());
}
stopGrid(0);
stopGrid(1);
calculateAffinity(5);
calculateAffinity(6);
checkAffinity(2, topVer(6, 0), true);
assertNull(((IgniteKernal) ignite(2)).context().cache().internalCache(CACHE_NAME1));
assertNotNull(((IgniteKernal) ignite(3)).context().cache().internalCache(CACHE_NAME1));
assertNotNull(ignite(2).cache(CACHE_NAME1));
checkAffinity(2, topVer(6, 0), true);
startServer(4, 7);
checkAffinity(3, topVer(7, 0), false);
checkAffinity(3, topVer(7, 1), true);
} finally {
System.clearProperty(IGNITE_EXCHANGE_COMPATIBILITY_VER_1);
}
}
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();
}
use of org.apache.ignite.internal.TestRecordingCommunicationSpi in project ignite by apache.
the class CacheLateAffinityAssignmentTest method testDelayAssignmentAffinityChanged2.
/**
* Wait for rebalance, send affinity change message, but affinity already changed (new node joined).
*
* @throws Exception If failed.
*/
public void testDelayAssignmentAffinityChanged2() throws Exception {
System.setProperty(IGNITE_EXCHANGE_COMPATIBILITY_VER_1, "true");
try {
Ignite ignite0 = startServer(0, 1);
TestTcpDiscoverySpi discoSpi0 = (TestTcpDiscoverySpi) ignite0.configuration().getDiscoverySpi();
TestRecordingCommunicationSpi commSpi0 = (TestRecordingCommunicationSpi) ignite0.configuration().getCommunicationSpi();
startClient(1, 2);
checkAffinity(2, topVer(2, 0), true);
startServer(2, 3);
checkAffinity(3, topVer(3, 1), false);
discoSpi0.blockCustomEvent();
stopNode(2, 4);
discoSpi0.waitCustomEvent();
blockSupplySend(commSpi0, CACHE_NAME1);
final IgniteInternalFuture<?> startedFuture = multithreadedAsync(new Callable<Void>() {
@Override
public Void call() throws Exception {
startServer(3, 5);
return null;
}
}, 1, "server-starter");
Thread.sleep(2_000);
discoSpi0.stopBlock();
boolean started = GridTestUtils.waitForCondition(new GridAbsPredicate() {
@Override
public boolean apply() {
return startedFuture.isDone();
}
}, 10_000);
if (!started)
startedFuture.cancel();
assertTrue(started);
checkAffinity(3, topVer(5, 0), false);
checkNoExchange(3, topVer(5, 1));
commSpi0.stopBlock();
checkAffinity(3, topVer(5, 1), true);
long nodeJoinTopVer = grid(3).context().discovery().localJoinEvent().topologyVersion();
assertEquals(5, nodeJoinTopVer);
List<GridDhtPartitionsExchangeFuture> exFutures = grid(3).context().cache().context().exchange().exchangeFutures();
for (GridDhtPartitionsExchangeFuture f : exFutures) {
// Shouldn't contains staled futures.
assertTrue(f.initialVersion().topologyVersion() >= nodeJoinTopVer);
}
} finally {
System.clearProperty(IGNITE_EXCHANGE_COMPATIBILITY_VER_1);
}
}
use of org.apache.ignite.internal.TestRecordingCommunicationSpi in project ignite by apache.
the class CachePartitionStateTest method getConfiguration.
/**
* {@inheritDoc}
*/
protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName);
((TcpDiscoverySpi) cfg.getDiscoverySpi()).setIpFinder(ipFinder);
cfg.setCommunicationSpi(new TestRecordingCommunicationSpi());
cfg.setClientMode(client);
if (ccfg != null) {
cfg.setCacheConfiguration(ccfg);
ccfg = null;
}
return cfg;
}
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));
}
Aggregations