use of org.apache.ignite.internal.processors.cache.distributed.near.GridNearTxFinishRequest in project ignite by apache.
the class TxRollbackOnTimeoutTest method testRollbackOnNearNodeLeft.
/**
* Tests that transactions from near node that has left are rolled back on server nodes.
*
* @throws Exception If failed.
*/
@Test
public void testRollbackOnNearNodeLeft() throws Exception {
Ignite client = startClient();
Integer pk0 = primaryKey(grid(0).cache(CACHE_NAME));
Integer pk1 = primaryKey(grid(1).cache(CACHE_NAME));
CountDownLatch locked = new CountDownLatch(1);
CountDownLatch blocked = new CountDownLatch(1);
IgniteInternalFuture<Void> fut = runAsync(new Callable<Void>() {
@Override
public Void call() {
try (Transaction tx0 = client.transactions().txStart()) {
client.cache(CACHE_NAME).put(pk0, 0);
locked.countDown();
awaitQuiet(blocked);
tx0.commit();
} catch (Exception ignored) {
// No-op.
}
return null;
}
});
IgniteInternalFuture fut2 = runAsync(new Runnable() {
@Override
public void run() {
try (Transaction tx1 = client.transactions().txStart(PESSIMISTIC, REPEATABLE_READ, 1000, 0)) {
awaitQuiet(locked);
client.cache(CACHE_NAME).put(pk1, 1);
spi(client).blockMessages((node, msg) -> msg instanceof GridNearTxFinishRequest);
spi(grid(0)).blockMessages((node, msg) -> msg instanceof GridNearLockResponse);
client.cache(CACHE_NAME).put(pk0, 1);
fail();
} catch (Exception e) {
assertTrue(X.hasCause(e, TransactionTimeoutException.class));
}
}
});
spi(client).waitForBlocked();
spi(grid(0)).waitForBlocked();
fut2.get();
client.close();
spi(grid(0)).stopBlock();
blocked.countDown();
fut.get();
for (int i = 0; i < GRID_CNT; i++) assertTrue(grid(i).context().cache().context().tm().activeTransactions().isEmpty());
}
Aggregations