use of org.apache.ignite.internal.TestRecordingCommunicationSpi in project ignite by apache.
the class CacheExchangeMessageDuplicatedStateTest method checkSingleMessages.
/**
* @param crdIdx Coordinator node index.
*/
private void checkSingleMessages(int crdIdx) {
int cnt = 0;
for (Ignite ignite : Ignition.allGrids()) {
if (getTestIgniteInstanceName(crdIdx).equals(ignite.name()) || ignite.configuration().isClientMode())
continue;
TestRecordingCommunicationSpi commSpi0 = (TestRecordingCommunicationSpi) ignite.configuration().getCommunicationSpi();
List<Object> msgs = commSpi0.recordedMessages(false);
assertTrue(msgs.size() > 0);
for (Object msg : msgs) {
assertTrue("Unexpected messages: " + msg, msg instanceof GridDhtPartitionsSingleMessage);
checkSingleMessage((GridDhtPartitionsSingleMessage) msg);
}
cnt++;
}
assertTrue(cnt > 0);
}
use of org.apache.ignite.internal.TestRecordingCommunicationSpi in project ignite by apache.
the class CacheExchangeMessageDuplicatedStateTest method getConfiguration.
/** {@inheritDoc} */
@Override
protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName);
((TcpDiscoverySpi) cfg.getDiscoverySpi()).setIpFinder(ipFinder);
cfg.setClientMode(client);
TestRecordingCommunicationSpi commSpi = new TestRecordingCommunicationSpi();
commSpi.record(new IgniteBiPredicate<ClusterNode, Message>() {
@Override
public boolean apply(ClusterNode node, Message msg) {
return (msg.getClass() == GridDhtPartitionsSingleMessage.class || msg.getClass() == GridDhtPartitionsFullMessage.class) && ((GridDhtPartitionsAbstractMessage) msg).exchangeId() != null;
}
});
cfg.setCommunicationSpi(commSpi);
List<CacheConfiguration> ccfgs = new ArrayList<>();
{
CacheConfiguration ccfg = new CacheConfiguration(DEFAULT_CACHE_NAME);
ccfg.setName(AFF1_CACHE1);
ccfg.setAffinity(new RendezvousAffinityFunction(false, 512));
ccfgs.add(ccfg);
}
{
CacheConfiguration ccfg = new CacheConfiguration(DEFAULT_CACHE_NAME);
ccfg.setName(AFF1_CACHE2);
ccfg.setAffinity(new RendezvousAffinityFunction(false, 512));
ccfgs.add(ccfg);
}
{
CacheConfiguration ccfg = new CacheConfiguration(DEFAULT_CACHE_NAME);
ccfg.setName(AFF3_CACHE1);
ccfg.setBackups(3);
RendezvousAffinityFunction aff = new RendezvousAffinityFunction(false, 64);
ccfg.setAffinity(aff);
ccfgs.add(ccfg);
}
{
CacheConfiguration ccfg = new CacheConfiguration(DEFAULT_CACHE_NAME);
ccfg.setName(AFF4_FILTER_CACHE1);
ccfg.setNodeFilter(new TestNodeFilter());
ccfg.setAffinity(new RendezvousAffinityFunction());
ccfgs.add(ccfg);
}
{
CacheConfiguration ccfg = new CacheConfiguration(DEFAULT_CACHE_NAME);
ccfg.setName(AFF4_FILTER_CACHE2);
ccfg.setNodeFilter(new TestNodeFilter());
ccfg.setAffinity(new RendezvousAffinityFunction());
ccfgs.add(ccfg);
}
cfg.setCacheConfiguration(ccfgs.toArray(new CacheConfiguration[ccfgs.size()]));
return cfg;
}
use of org.apache.ignite.internal.TestRecordingCommunicationSpi in project ignite by apache.
the class CacheLateAffinityAssignmentTest method testDelayAssignmentClientCacheStart.
/**
* Wait for rebalance, client cache is started.
*
* @throws Exception If failed.
*/
public void testDelayAssignmentClientCacheStart() throws Exception {
Ignite ignite0 = startServer(0, 1);
TestRecordingCommunicationSpi spi = (TestRecordingCommunicationSpi) ignite0.configuration().getCommunicationSpi();
blockSupplySend(spi, CACHE_NAME1);
startServer(1, 2);
startServer(2, 3);
cacheC = new IgniteClosure<String, CacheConfiguration[]>() {
@Override
public CacheConfiguration[] apply(String nodeName) {
return null;
}
};
Ignite client = startClient(3, 4);
checkAffinity(4, topVer(4, 0), false);
assertNotNull(client.cache(CACHE_NAME1));
checkAffinity(4, topVer(4, 1), false);
spi.stopBlock();
checkAffinity(4, topVer(4, 2), true);
}
use of org.apache.ignite.internal.TestRecordingCommunicationSpi in project ignite by apache.
the class CacheLateAffinityAssignmentTest method testDelayAssignmentCacheDestroy.
/**
* Wait for rebalance, cache is destroyed.
*
* @throws Exception If failed.
*/
public void testDelayAssignmentCacheDestroy() throws Exception {
Ignite ignite0 = startServer(0, 1);
CacheConfiguration ccfg = cacheConfiguration();
ccfg.setName(CACHE_NAME2);
ignite0.createCache(ccfg);
TestRecordingCommunicationSpi spi = (TestRecordingCommunicationSpi) ignite0.configuration().getCommunicationSpi();
blockSupplySend(spi, CACHE_NAME2);
startServer(1, 2);
startServer(2, 3);
checkAffinity(3, topVer(3, 0), false);
ignite0.destroyCache(CACHE_NAME2);
checkAffinity(3, topVer(3, 1), false);
checkAffinity(3, topVer(3, 2), true);
spi.stopBlock();
}
use of org.apache.ignite.internal.TestRecordingCommunicationSpi in project ignite by apache.
the class IgniteCacheNearLockValueSelfTest method testDhtVersion.
/**
* @throws Exception If failed.
*/
public void testDhtVersion() throws Exception {
CacheConfiguration<Object, Object> pCfg = new CacheConfiguration<>("partitioned");
pCfg.setAtomicityMode(CacheAtomicityMode.TRANSACTIONAL);
try (IgniteCache<Object, Object> cache = ignite(0).getOrCreateCache(pCfg, new NearCacheConfiguration<>())) {
cache.put("key1", "val1");
for (int i = 0; i < 3; i++) {
try (Transaction tx = ignite(0).transactions().txStart(PESSIMISTIC, REPEATABLE_READ)) {
cache.get("key1");
tx.commit();
}
TestRecordingCommunicationSpi comm = (TestRecordingCommunicationSpi) ignite(0).configuration().getCommunicationSpi();
Collection<GridNearLockRequest> reqs = (Collection) comm.recordedMessages(false);
assertEquals(1, reqs.size());
GridCacheAdapter<Object, Object> primary = ((IgniteKernal) grid(1)).internalCache("partitioned");
GridCacheEntryEx dhtEntry = primary.peekEx(primary.context().toCacheKeyObject("key1"));
assertNotNull(dhtEntry);
GridNearLockRequest req = reqs.iterator().next();
assertEquals(dhtEntry.version(), req.dhtVersion(0));
// Check entry version in near cache after commit.
GridCacheAdapter<Object, Object> near = ((IgniteKernal) grid(0)).internalCache("partitioned");
GridNearCacheEntry nearEntry = (GridNearCacheEntry) near.peekEx(near.context().toCacheKeyObject("key1"));
assertNotNull(nearEntry);
assertEquals(dhtEntry.version(), nearEntry.dhtVersion());
}
}
}
Aggregations