/** * Constructor. * * @param platformCtx Context. * @param lbl Label. */ public PlatformTransactions(PlatformContext platformCtx, String lbl) { super(platformCtx); txs = platformCtx.kernalContext().grid().transactions().withLabel(lbl); }
/** * @param txs Transaction manager. * @param cache Ignite cache. */ private void checkRollback(IgniteTransactions txs, IgniteCache<Integer, Integer> cache) { // create & rollback (pessimistic) try (Transaction tx = txs.withLabel(lb).txStart( TransactionConcurrency.PESSIMISTIC, TransactionIsolation.REPEATABLE_READ, timeout, 3)) { cache.put(4, 5); } assertTrue( creation.get() && !commit.get() && rollback.get() && !suspend.get() && !resume.get()); }
/** * Run command in transaction. * * @param startNode Ignite node to start transaction and run passed command. * @param cmdInTx Command which should be done in transaction. */ private void runTransactionally(Ignite startNode, Consumer<Ignite> cmdInTx) { try (Transaction tx = startNode.transactions().withLabel(TX_LABEL).txStart(concurrency, isolation)) { cmdInTx.accept(startNode); tx.commit(); } }
/** * @param txs Transaction manager. * @param cache Ignite cache. */ private void checkCommit(IgniteTransactions txs, IgniteCache<Integer, Integer> cache) { // create & commit try (Transaction tx = txs.withLabel(lb).txStart( TransactionConcurrency.PESSIMISTIC, TransactionIsolation.REPEATABLE_READ, timeout, 3)) { cache.put(1, 1); tx.commit(); } assertTrue( creation.get() && commit.get() && !rollback.get() && !suspend.get() && !resume.get()); clear(); }
/** * @param txs Transaction manager. * @param cache Ignite cache. */ private void checkSuspendResume(IgniteTransactions txs, IgniteCache<Integer, Integer> cache) throws IgniteInterruptedCheckedException { // create & suspend & resume & commit try (Transaction tx = txs.withLabel(lb).txStart( TransactionConcurrency.OPTIMISTIC, TransactionIsolation.SERIALIZABLE, timeout, 3)) { cache.put(2, 7); tx.suspend(); U.sleep(100); tx.resume(); tx.commit(); } assertTrue( creation.get() && commit.get() && !rollback.get() && suspend.get() && resume.get()); clear(); }
/** * @param ignite Ignite. * @param lbl Label. */ private void testLabel0(Ignite ignite, String lbl) { try(Transaction tx = ignite.transactions().withLabel(lbl).txStart()) { assertEquals(lbl, tx.label()); ignite.cache(DEFAULT_CACHE_NAME).put(0, 0); tx.commit(); } } }
try (Transaction tx = grid(0).transactions().withLabel("label1").txStart(PESSIMISTIC, READ_COMMITTED, Integer.MAX_VALUE, 0)) { grid(0).cache(DEFAULT_CACHE_NAME).putAll(generate(200, 110)); try (Transaction tx = client.transactions().withLabel("label2").txStart(OPTIMISTIC, READ_COMMITTED, 0, 0)) { U.awaitQuiet(lockLatch);
/** * */ @Test public void testLabelFilledLocalGuarantee() throws Exception { Ignite ignite = startGrid(0); ignite.events().localListen((IgnitePredicate<Event>)e -> { assert e instanceof TransactionStateChangedEvent; TransactionStateChangedEvent evt = (TransactionStateChangedEvent)e; Transaction tx = evt.tx(); if (tx.label() == null) tx.setRollbackOnly(); return true; }, EVT_TX_STARTED); IgniteCache cache = ignite.getOrCreateCache(defaultCacheConfiguration()); try (Transaction tx = ignite.transactions().withLabel("test").txStart()) { cache.put(1, 1); tx.commit(); } try (Transaction tx = ignite.transactions().txStart()) { cache.put(1, 2); tx.commit(); fail("Should fail prior this line."); } catch (CacheException ignored) { // No-op. } }
/** * Constructor. * * @param platformCtx Context. * @param lbl Label. */ public PlatformTransactions(PlatformContext platformCtx, String lbl) { super(platformCtx); txs = platformCtx.kernalContext().grid().transactions().withLabel(lbl); }