use of org.apache.ignite.internal.processors.cache.distributed.near.GridNearLockRequest in project ignite by apache.
the class IgniteCacheClientNodeChangingTopologyTest method pessimisticTx.
/**
* @param nearCfg Near cache configuration.
* @throws Exception If failed.
*/
private void pessimisticTx(NearCacheConfiguration nearCfg) throws Exception {
ccfg = new CacheConfiguration(DEFAULT_CACHE_NAME);
ccfg.setCacheMode(PARTITIONED);
ccfg.setBackups(1);
ccfg.setAtomicityMode(TRANSACTIONAL);
ccfg.setWriteSynchronizationMode(FULL_SYNC);
ccfg.setRebalanceMode(SYNC);
ccfg.setNearConfiguration(nearCfg);
IgniteEx ignite0 = startGrid(0);
IgniteEx ignite1 = startGrid(1);
awaitPartitionMapExchange();
client = true;
final Ignite ignite2 = startGrid(2);
assertTrue(ignite2.configuration().isClientMode());
final Map<Integer, Integer> map = new HashMap<>();
for (int i = 0; i < 100; i++) map.put(i, i);
TestCommunicationSpi spi = (TestCommunicationSpi) ignite2.configuration().getCommunicationSpi();
spi.blockMessages(GridNearLockRequest.class, ignite0.localNode().id());
spi.blockMessages(GridNearLockRequest.class, ignite1.localNode().id());
spi.record(GridNearLockRequest.class);
final IgniteCache<Integer, Integer> cache = ignite2.cache(DEFAULT_CACHE_NAME);
IgniteInternalFuture<?> putFut = GridTestUtils.runAsync(new Callable<Object>() {
@Override
public Object call() throws Exception {
Thread.currentThread().setName("put-thread");
try (Transaction tx = ignite2.transactions().txStart(PESSIMISTIC, REPEATABLE_READ)) {
cache.putAll(map);
tx.commit();
}
return null;
}
});
assertFalse(putFut.isDone());
client = false;
IgniteEx ignite3 = startGrid(3);
log.info("Stop block1.");
spi.stopBlock();
putFut.get();
spi.record(null);
checkData(map, null, cache, 4);
List<Object> msgs = spi.recordedMessages();
assertTrue(((GridNearLockRequest) msgs.get(0)).firstClientRequest());
assertTrue(((GridNearLockRequest) msgs.get(1)).firstClientRequest());
for (int i = 2; i < msgs.size(); i++) assertFalse(((GridNearLockRequest) msgs.get(i)).firstClientRequest());
ignite3.close();
for (int i = 0; i < 100; i++) map.put(i, i + 1);
spi.blockMessages(GridNearLockRequest.class, ignite0.localNode().id());
spi.blockMessages(GridNearLockRequest.class, ignite1.localNode().id());
putFut = GridTestUtils.runAsync(new Callable<Object>() {
@Override
public Object call() throws Exception {
Thread.currentThread().setName("put-thread");
try (Transaction tx = ignite2.transactions().txStart(PESSIMISTIC, REPEATABLE_READ)) {
for (Map.Entry<Integer, Integer> e : map.entrySet()) cache.put(e.getKey(), e.getValue());
tx.commit();
}
return null;
}
});
startGrid(3);
log.info("Stop block2.");
spi.stopBlock();
putFut.get();
checkData(map, null, cache, 4);
for (int i = 0; i < 100; i++) map.put(i, i + 2);
try (Transaction tx = ignite2.transactions().txStart(PESSIMISTIC, REPEATABLE_READ)) {
cache.putAll(map);
tx.commit();
}
checkData(map, null, cache, 4);
}
Aggregations