use of org.apache.ignite.internal.TestRecordingCommunicationSpi in project ignite by apache.
the class IgniteClusterActivateDeactivateTest method getConfiguration.
/**
* {@inheritDoc}
*/
@Override
protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName);
if (testReconnectSpi) {
TcpDiscoverySpi spi = new IgniteClientReconnectAbstractTest.TestTcpDiscoverySpi();
cfg.setDiscoverySpi(spi);
spi.setJoinTimeout(2 * 60_000);
}
((TcpDiscoverySpi) cfg.getDiscoverySpi()).setIpFinder(IP_FINDER);
cfg.setConsistentId(igniteInstanceName);
cfg.setClientMode(client);
cfg.setActiveOnStart(active);
if (ccfgs != null) {
cfg.setCacheConfiguration(ccfgs);
ccfgs = null;
}
DataStorageConfiguration memCfg = new DataStorageConfiguration();
memCfg.setPageSize(4 * 1024);
memCfg.setDefaultDataRegionConfiguration(new DataRegionConfiguration().setMaxSize(300 * 1024 * 1024).setPersistenceEnabled(persistenceEnabled()));
memCfg.setDataRegionConfigurations(new DataRegionConfiguration().setMaxSize(300 * 1024 * 1024).setName(NO_PERSISTENCE_REGION).setPersistenceEnabled(false));
if (persistenceEnabled())
memCfg.setWalMode(WALMode.LOG_ONLY);
cfg.setDataStorageConfiguration(memCfg);
if (testSpi) {
TestRecordingCommunicationSpi spi = new TestRecordingCommunicationSpi();
if (testSpiRecord != null)
spi.record(testSpiRecord);
cfg.setCommunicationSpi(spi);
}
return cfg;
}
use of org.apache.ignite.internal.TestRecordingCommunicationSpi in project ignite by apache.
the class IgniteCacheSingleGetMessageTest method checkSingleGetMessage.
/**
* @param cache Cache.
* @param key Key.
* @param backup {@code True} if given key is backup key.
* @throws Exception If failed.
*/
@SuppressWarnings("unchecked")
private void checkSingleGetMessage(IgniteCache<Integer, Integer> cache, Integer key, boolean backup) throws Exception {
CacheConfiguration<Integer, Integer> ccfg = cache.getConfiguration(CacheConfiguration.class);
Ignite node = cache.unwrap(Ignite.class);
TestRecordingCommunicationSpi spi = (TestRecordingCommunicationSpi) node.configuration().getCommunicationSpi();
spi.record(GridNearSingleGetRequest.class);
Ignite primary = primaryNode(key, cache.getName());
assertNotSame(node, primary);
TestRecordingCommunicationSpi primarySpi = (TestRecordingCommunicationSpi) primary.configuration().getCommunicationSpi();
primarySpi.record(GridNearSingleGetResponse.class);
assertNull(cache.get(key));
if (backup)
checkNoMessages(spi, primarySpi);
else
checkMessages(spi, primarySpi);
assertFalse(cache.containsKey(key));
if (backup)
checkNoMessages(spi, primarySpi);
else
checkMessages(spi, primarySpi);
cache.put(key, 1);
assertNotNull(cache.get(key));
if (backup)
checkNoMessages(spi, primarySpi);
else
checkMessages(spi, primarySpi);
assertTrue(cache.containsKey(key));
if (backup)
checkNoMessages(spi, primarySpi);
else
checkMessages(spi, primarySpi);
if (ccfg.getAtomicityMode() == TRANSACTIONAL) {
cache.remove(key);
try (Transaction tx = node.transactions().txStart(OPTIMISTIC, REPEATABLE_READ)) {
assertNull(cache.get(key));
tx.commit();
}
if (backup)
checkNoMessages(spi, primarySpi);
else
checkMessages(spi, primarySpi);
try (Transaction tx = node.transactions().txStart(OPTIMISTIC, REPEATABLE_READ)) {
assertFalse(cache.containsKey(key));
tx.commit();
}
if (backup)
checkNoMessages(spi, primarySpi);
else
checkMessages(spi, primarySpi);
cache.put(key, 1);
try (Transaction tx = node.transactions().txStart(OPTIMISTIC, REPEATABLE_READ)) {
assertNotNull(cache.get(key));
tx.commit();
}
if (backup)
checkNoMessages(spi, primarySpi);
else
checkMessages(spi, primarySpi);
try (Transaction tx = node.transactions().txStart(OPTIMISTIC, REPEATABLE_READ)) {
assertTrue(cache.containsKey(key));
tx.commit();
}
if (backup)
checkNoMessages(spi, primarySpi);
else
checkMessages(spi, primarySpi);
}
}
use of org.apache.ignite.internal.TestRecordingCommunicationSpi in project ignite by apache.
the class IgniteTxCachePrimarySyncTest method checkOnePhaseMessages.
/**
* @param client Node executing cache operation.
* @param ccfg Cache configuration.
* @param c Cache update closure.
* @throws Exception If failed.
*/
private void checkOnePhaseMessages(Ignite client, final CacheConfiguration<Object, Object> ccfg, final IgniteBiInClosure<Integer, IgniteCache<Object, Object>> c) throws Exception {
Ignite ignite = ignite(0);
assertNotSame(ignite, client);
TestRecordingCommunicationSpi commSpiClient = (TestRecordingCommunicationSpi) client.configuration().getCommunicationSpi();
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.record(GridNearTxFinishResponse.class, GridNearTxPrepareResponse.class);
commSpiClient.record(GridNearTxPrepareRequest.class, GridNearTxFinishRequest.class);
c.apply(key, clientCache);
List<Object> srvMsgs = commSpi0.recordedMessages(true);
assertEquals("Unexpected messages: " + srvMsgs, 1, srvMsgs.size());
assertTrue("Unexpected message: " + srvMsgs.get(0), srvMsgs.get(0) instanceof GridNearTxPrepareResponse);
List<Object> clientMsgs = commSpiClient.recordedMessages(true);
assertEquals("Unexpected messages: " + clientMsgs, 1, clientMsgs.size());
assertTrue("Unexpected message: " + clientMsgs.get(0), clientMsgs.get(0) instanceof GridNearTxPrepareRequest);
GridNearTxPrepareRequest req = (GridNearTxPrepareRequest) clientMsgs.get(0);
assertTrue(req.onePhaseCommit());
for (Ignite ignite0 : G.allGrids()) assertEquals(key, ignite0.cache(cache.getName()).get(key));
}
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 CacheExchangeMessageDuplicatedStateTest method checkFullMessages.
/**
* @param crdIdx Coordinator node index.
*/
private void checkFullMessages(int crdIdx) {
TestRecordingCommunicationSpi commSpi0 = (TestRecordingCommunicationSpi) ignite(crdIdx).configuration().getCommunicationSpi();
List<Object> msgs = commSpi0.recordedMessages(false);
assertTrue(!msgs.isEmpty());
for (Object msg : msgs) {
assertTrue("Unexpected messages: " + msg, msg instanceof GridDhtPartitionsFullMessage);
checkFullMessage((GridDhtPartitionsFullMessage) msg);
}
}
Aggregations