use of org.apache.ignite.internal.TestRecordingCommunicationSpi in project ignite by apache.
the class GridCacheDhtPreloadMessageCountTest method getConfiguration.
/** {@inheritDoc} */
@Override
protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
IgniteConfiguration c = super.getConfiguration(igniteInstanceName);
assert preloadMode != null;
CacheConfiguration cc = defaultCacheConfiguration();
cc.setCacheMode(PARTITIONED);
cc.setWriteSynchronizationMode(FULL_SYNC);
cc.setRebalanceMode(preloadMode);
cc.setAffinity(new RendezvousAffinityFunction(false, 521));
cc.setBackups(1);
TcpDiscoverySpi disco = new TcpDiscoverySpi();
disco.setIpFinder(ipFinder);
c.setFailureDetectionTimeout(Integer.MAX_VALUE);
c.setDiscoverySpi(disco);
c.setCacheConfiguration(cc);
TestRecordingCommunicationSpi commSpi = new TestRecordingCommunicationSpi();
commSpi.record(GridDhtPartitionsSingleMessage.class);
c.setCommunicationSpi(commSpi);
return c;
}
use of org.apache.ignite.internal.TestRecordingCommunicationSpi in project ignite by apache.
the class IgniteOnePhaseCommitInvokeTest method getConfiguration.
/** {@inheritDoc} */
@Override
protected IgniteConfiguration getConfiguration(String gridName) throws Exception {
IgniteConfiguration cfg = super.getConfiguration(gridName);
((TcpDiscoverySpi) cfg.getDiscoverySpi()).setIpFinder(ipFinder);
TestRecordingCommunicationSpi commSpi = new TestRecordingCommunicationSpi();
cfg.setCommunicationSpi(commSpi);
cfg.setClientMode(client);
CacheConfiguration ccfg = new CacheConfiguration();
ccfg.setName(CACHE_NAME);
ccfg.setAtomicityMode(TRANSACTIONAL);
ccfg.setBackups(1);
ccfg.setRebalanceMode(ASYNC);
ccfg.setWriteSynchronizationMode(FULL_SYNC);
cfg.setCacheConfiguration(ccfg);
return cfg;
}
use of org.apache.ignite.internal.TestRecordingCommunicationSpi in project ignite by apache.
the class CacheLateAffinityAssignmentTest method testDelayAssignmentCacheStart.
/**
* Wait for rebalance, cache is started.
*
* @throws Exception If failed.
*/
public void testDelayAssignmentCacheStart() throws Exception {
Ignite ignite0 = startServer(0, 1);
TestRecordingCommunicationSpi spi = (TestRecordingCommunicationSpi) ignite0.configuration().getCommunicationSpi();
blockSupplySend(spi, CACHE_NAME1);
startServer(1, 2);
startServer(2, 3);
checkAffinity(3, topVer(3, 0), false);
CacheConfiguration ccfg = cacheConfiguration();
ccfg.setName(CACHE_NAME2);
ignite0.createCache(ccfg);
calculateAffinity(3);
checkAffinity(3, topVer(3, 1), false);
spi.stopBlock();
checkAffinity(3, topVer(3, 2), true);
}
use of org.apache.ignite.internal.TestRecordingCommunicationSpi in project ignite by apache.
the class IgniteCacheReadFromBackupTest method testGetFromPrimaryPreloadInProgress.
/**
* @throws Exception If failed.
*/
public void testGetFromPrimaryPreloadInProgress() throws Exception {
for (final CacheConfiguration<Object, Object> ccfg : cacheConfigurations()) {
boolean near = (ccfg.getNearConfiguration() != null);
log.info("Test cache [mode=" + ccfg.getCacheMode() + ", atomicity=" + ccfg.getAtomicityMode() + ", backups=" + ccfg.getBackups() + ", near=" + near + "]");
ignite(0).createCache(ccfg);
awaitPartitionMapExchange();
try {
Map<Ignite, Integer> backupKeys = new HashMap<>();
Map<Ignite, Integer> nearKeys = new HashMap<>();
for (int i = 0; i < NODES; i++) {
Ignite ignite = ignite(i);
IgniteCache<Integer, Integer> cache = ignite.cache(ccfg.getName());
backupKeys.put(ignite, backupKey(cache));
if (ccfg.getCacheMode() == PARTITIONED)
nearKeys.put(ignite, nearKey(cache));
TestRecordingCommunicationSpi spi = (TestRecordingCommunicationSpi) ignite.configuration().getCommunicationSpi();
spi.blockMessages(new IgniteBiPredicate<ClusterNode, Message>() {
@Override
public boolean apply(ClusterNode node, Message msg) {
if (!msg.getClass().equals(GridDhtPartitionSupplyMessage.class))
return false;
return ((GridDhtPartitionSupplyMessage) msg).cacheId() == CU.cacheId(ccfg.getName());
}
});
}
try (Ignite newNode = startGrid(NODES)) {
IgniteCache<Integer, Integer> cache = newNode.cache(ccfg.getName());
TestRecordingCommunicationSpi newNodeSpi = recordGetRequests(newNode, near);
Integer key = backupKey(cache);
assertNull(cache.get(key));
List<Object> msgs = newNodeSpi.recordedMessages(false);
assertEquals(1, msgs.size());
for (int i = 0; i < NODES; i++) {
Ignite ignite = ignite(i);
log.info("Check node: " + ignite.name());
checkLocalRead(ignite, ccfg, backupKeys.get(ignite), nearKeys.get(ignite));
}
for (int i = 0; i < NODES; i++) {
Ignite ignite = ignite(i);
TestRecordingCommunicationSpi spi = (TestRecordingCommunicationSpi) ignite.configuration().getCommunicationSpi();
spi.stopBlock(true);
}
awaitPartitionMapExchange();
checkLocalRead(NODES + 1, ccfg);
}
} finally {
ignite(0).destroyCache(ccfg.getName());
}
}
}
use of org.apache.ignite.internal.TestRecordingCommunicationSpi in project ignite by apache.
the class IgniteCacheReadFromBackupTest method checkLocalRead.
/**
* @param ignite Node.
* @param ccfg Cache configuration.
* @param backupKey Backup key.
* @param nearKey Near key.
* @throws Exception If failed.
*/
private void checkLocalRead(Ignite ignite, CacheConfiguration<Object, Object> ccfg, Integer backupKey, Integer nearKey) throws Exception {
IgniteCache<Integer, Integer> cache = ignite.cache(ccfg.getName());
TestRecordingCommunicationSpi spi = recordGetRequests(ignite, ccfg.getNearConfiguration() != null);
List<Object> msgs;
if (nearKey != null) {
assertNull(cache.get(nearKey));
msgs = spi.recordedMessages(false);
assertEquals(1, msgs.size());
}
assertNull(cache.get(backupKey));
msgs = spi.recordedMessages(false);
assertTrue(msgs.isEmpty());
}
Aggregations