use of org.apache.ignite.internal.TestRecordingCommunicationSpi in project ignite by apache.
the class IgniteCacheReadFromBackupTest method recordGetRequests.
/**
* @param ignite Node.
* @param near Near cache flag.
* @return Communication SPI.
*/
private TestRecordingCommunicationSpi recordGetRequests(Ignite ignite, boolean near) {
TestRecordingCommunicationSpi spi = (TestRecordingCommunicationSpi) ignite.configuration().getCommunicationSpi();
spi.record(near ? GridNearGetRequest.class : GridNearSingleGetRequest.class);
return spi;
}
use of org.apache.ignite.internal.TestRecordingCommunicationSpi in project ignite by apache.
the class IgniteCacheReadFromBackupTest method testGetFromBackupStoreReadThroughEnabled.
/**
* @throws Exception If failed.
*/
public void testGetFromBackupStoreReadThroughEnabled() throws Exception {
for (CacheConfiguration<Object, Object> ccfg : cacheConfigurations()) {
ccfg.setCacheStoreFactory(new TestStoreFactory());
ccfg.setReadThrough(true);
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 {
for (int i = 0; i < NODES; i++) {
Ignite ignite = ignite(i);
log.info("Check node: " + ignite.name());
IgniteCache<Integer, Integer> cache = ignite.cache(ccfg.getName());
TestRecordingCommunicationSpi spi = recordGetRequests(ignite, near);
Integer key = backupKey(cache);
assertNull(cache.get(key));
List<Object> msgs = spi.recordedMessages(false);
assertEquals(1, msgs.size());
}
} finally {
ignite(0).destroyCache(ccfg.getName());
}
}
}
use of org.apache.ignite.internal.TestRecordingCommunicationSpi in project ignite by apache.
the class IgniteCacheReadFromBackupTest method checkLocalRead.
/**
* @param nodes Number of nodes.
* @param ccfg Cache configuration.
* @throws Exception If failed.
*/
private void checkLocalRead(int nodes, CacheConfiguration<Object, Object> ccfg) throws Exception {
for (int i = 0; i < nodes; i++) {
Ignite ignite = ignite(i);
log.info("Check node: " + ignite.name());
IgniteCache<Integer, Integer> cache = ignite.cache(ccfg.getName());
List<Integer> backupKeys = backupKeys(cache, 2, 0);
Integer backupKey = backupKeys.get(0);
Integer nearKey = ccfg.getCacheMode() == PARTITIONED ? nearKey(cache) : null;
checkLocalRead(ignite, ccfg, backupKey, nearKey);
Set<Integer> keys = new HashSet<>(backupKeys);
Map<Integer, Integer> vals = cache.getAll(keys);
for (Integer key : keys) assertNull(vals.get(key));
TestRecordingCommunicationSpi spi = (TestRecordingCommunicationSpi) ignite.configuration().getCommunicationSpi();
List<Object> msgs = spi.recordedMessages(false);
assertEquals(0, msgs.size());
}
}
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 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);
}
}
Aggregations