use of org.apache.ignite.internal.processors.cache.transactions.IgniteTxManager.TXS_MON_LIST in project ignite by apache.
the class FunctionalTest method testTransactionsWithLabel.
/**
* Test transactions with label.
*/
@Test
public void testTransactionsWithLabel() throws Exception {
try (IgniteEx ignite = (IgniteEx) Ignition.start(Config.getServerConfiguration());
IgniteClient client = Ignition.startClient(getClientConfiguration())) {
ClientCache<Integer, String> cache = client.createCache(new ClientCacheConfiguration().setName("cache").setAtomicityMode(CacheAtomicityMode.TRANSACTIONAL));
SystemView<TransactionView> txsView = ignite.context().systemView().view(TXS_MON_LIST);
cache.put(0, "value1");
try (ClientTransaction tx = client.transactions().withLabel("label").txStart()) {
cache.put(0, "value2");
assertEquals(1, F.size(txsView.iterator()));
TransactionView txv = txsView.iterator().next();
assertEquals("label", txv.label());
assertEquals("value2", cache.get(0));
}
assertEquals("value1", cache.get(0));
try (ClientTransaction tx = client.transactions().withLabel("label1").withLabel("label2").txStart()) {
cache.put(0, "value2");
assertEquals(1, F.size(txsView.iterator()));
TransactionView txv = txsView.iterator().next();
assertEquals("label2", txv.label());
tx.commit();
}
assertEquals("value2", cache.get(0));
// Test concurrent with label and without label transactions.
try (ClientTransaction tx = client.transactions().withLabel("label").txStart(PESSIMISTIC, READ_COMMITTED)) {
CyclicBarrier barrier = new CyclicBarrier(2);
cache.put(0, "value3");
IgniteInternalFuture<?> fut = GridTestUtils.runAsync(() -> {
try (ClientTransaction tx1 = client.transactions().txStart(PESSIMISTIC, READ_COMMITTED)) {
cache.put(1, "value3");
barrier.await();
assertEquals("value2", cache.get(0));
barrier.await();
} catch (InterruptedException | BrokenBarrierException ignore) {
// No-op.
}
});
barrier.await();
assertNull(cache.get(1));
assertEquals(1, F.size(txsView.iterator(), txv -> txv.label() == null));
assertEquals(1, F.size(txsView.iterator(), txv -> "label".equals(txv.label())));
barrier.await();
fut.get();
}
// Test nested transactions is not possible.
try (ClientTransaction tx = client.transactions().withLabel("label1").txStart()) {
try (ClientTransaction tx1 = client.transactions().txStart()) {
fail();
} catch (ClientException expected) {
// No-op.
}
try (ClientTransaction tx1 = client.transactions().withLabel("label2").txStart()) {
fail();
} catch (ClientException expected) {
// No-op.
}
}
}
}
Aggregations