use of org.apache.ignite.internal.processors.cache.GridCacheAffinityManager in project ignite by apache.
the class TxOptimisticOnPartitionExchangeTest method doTest.
/**
* @param isolation {@link TransactionIsolation}.
* @param txInitiatorPrimary False If the transaction does not use the keys of the node that initiated it.
* @throws Exception If failed.
*/
@SuppressWarnings("unchecked")
public void doTest(final TransactionIsolation isolation, boolean txInitiatorPrimary) throws Exception {
final CountDownLatch txStarted = new CountDownLatch(1);
final IgniteCache cache = ignite(0).cache(CACHE_NAME);
final Map<Integer, Integer> txValues = new TreeMap<>();
ClusterNode node = ignite(0).cluster().node();
GridCacheAffinityManager affinity = ((IgniteCacheProxy) cache).context().affinity();
for (int i = 0; txValues.size() < TX_SIZE; i++) {
if (!txInitiatorPrimary && node.equals(affinity.primaryByKey(i, NONE)))
continue;
txValues.put(i, i);
}
TestCommunicationSpi.init();
msgInterception = true;
IgniteInternalFuture<Object> fut = GridTestUtils.runAsync(new Callable<Object>() {
@Override
public Object call() {
try (Transaction tx = ignite(0).transactions().txStart(OPTIMISTIC, isolation)) {
info(">>> TX started.");
txStarted.countDown();
cache.putAll(txValues);
tx.commit();
info(">>> TX committed.");
}
return null;
}
});
txStarted.await();
try {
info(">>> Grid starting.");
IgniteEx ignite = startGrid(NODES_CNT);
info(">>> Grid started.");
fut.get();
awaitPartitionMapExchange();
msgInterception = false;
IgniteCache<Object, Object> cacheStartedNode = ignite.cache(CACHE_NAME);
try (Transaction tx = ignite.transactions().txStart(PESSIMISTIC, REPEATABLE_READ)) {
Set<Object> keys = cacheStartedNode.getAll(txValues.keySet()).keySet();
assertEquals(txValues.keySet(), new TreeSet<>(keys));
tx.commit();
}
} finally {
msgInterception = false;
stopGrid(NODES_CNT);
}
}
Aggregations