@Override public Object call() throws Exception { tx.suspend(); return null; } }, UnsupportedOperationException.class);
@Override public void applyx(Transaction tx) throws Exception { tx.suspend(); } },
/** * @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(); }
@Override public void applyx(Ignite ignite, final IgniteCache<Integer, Integer> cache) throws Exception { for (TransactionIsolation isolation : TransactionIsolation.values()) { final List<Transaction> clientTxs = new ArrayList<>(); for (int i = 0; i < 10; i++) { Transaction tx = ignite.transactions().txStart(OPTIMISTIC, isolation); cache.put(i, i); tx.suspend(); clientTxs.add(tx); } GridTestUtils.runMultiThreaded(new CI1Exc<Integer>() { @Override public void applyx(Integer idx) throws Exception { Transaction tx = clientTxs.get(idx); assertEquals(SUSPENDED, tx.state()); tx.resume(); assertEquals(ACTIVE, tx.state()); tx.commit(); } }, 10, "th-suspend"); for (int i = 0; i < 10; i++) assertEquals(i, (int)cache.get(i)); cache.removeAll(); } } });
@Override public void applyx(Ignite ignite, final IgniteCache<Integer, Integer> cache) throws Exception { for (CI1Exc<Transaction> txOperation : SUSPENDED_TX_PROHIBITED_OPS) { for (TransactionIsolation isolation : TransactionIsolation.values()) { Transaction tx = ignite.transactions().txStart(OPTIMISTIC, isolation); cache.put(1, 1); tx.suspend(); GridTestUtils.assertThrowsWithCause(txOperation, tx, IgniteException.class); tx.resume(); tx.close(); assertNull(cache.get(1)); } } } });
@Override public void applyx(Ignite ignite, final IgniteCache<Integer, Integer> cache) throws Exception { for (TransactionIsolation tx1Isolation : TransactionIsolation.values()) { for (TransactionIsolation tx2Isolation : TransactionIsolation.values()) { Transaction tx1 = ignite.transactions().txStart(OPTIMISTIC, tx1Isolation); cache.put(1, 1); tx1.suspend(); assertFalse(cache.containsKey(1)); Transaction tx2 = ignite.transactions().txStart(OPTIMISTIC, tx2Isolation); cache.put(1, 2); tx2.suspend(); assertFalse(cache.containsKey(1)); tx1.resume(); assertEquals(1, (int)cache.get(1)); tx1.suspend(); tx2.resume(); assertEquals(2, (int)cache.get(1)); tx2.rollback(); tx1.resume(); tx1.rollback(); cache.removeAll(); } } } });
cache.put(cntr.get(), cntr.getAndIncrement()); tx.suspend();
@Override public void applyx(Ignite ignite, final IgniteCache<Integer, Integer> cache) throws Exception { for (final CI1Exc<Transaction> txOperation : SUSPENDED_TX_PROHIBITED_OPS) { for (TransactionIsolation isolation : TransactionIsolation.values()) { final Transaction tx = ignite.transactions().txStart(OPTIMISTIC, isolation); cache.put(1, 1); tx.suspend(); multithreaded(new RunnableX() { @Override public void runx() throws Exception { GridTestUtils.assertThrowsWithCause(txOperation, tx, IgniteException.class); } }, 1); tx.resume(); tx.close(); assertNull(cache.get(1)); } } } });
@Override public void applyx(Ignite ignite, final IgniteCache<Integer, Integer> cache) throws Exception { for (TransactionIsolation isolation : TransactionIsolation.values()) { final Transaction tx = ignite.transactions().txStart(OPTIMISTIC, isolation); cache.put(1, 1); cache.put(2, 2); tx.suspend(); assertNull("There is no transaction for current thread", ignite.transactions().tx()); assertEquals(SUSPENDED, tx.state()); GridTestUtils.runAsync(new Runnable() { @Override public void run() { tx.resume(); assertEquals(ACTIVE, tx.state()); cache.put(3, 3); tx.rollback(); } }).get(FUT_TIMEOUT); assertTrue(GridTestUtils.waitForCondition(new PA() { @Override public boolean apply() { return tx.state() == ROLLED_BACK; } }, getTestTimeout())); assertEquals(ROLLED_BACK, tx.state()); assertFalse(cache.containsKey(1)); assertFalse(cache.containsKey(2)); assertFalse(cache.containsKey(3)); cache.removeAll(); } } });
@Override public void applyx(Ignite ignite, final IgniteCache<Integer, Integer> cache) throws Exception { for (TransactionIsolation isolation : TransactionIsolation.values()) { final Transaction tx = ignite.transactions().txStart(OPTIMISTIC, isolation, TX_TIMEOUT, 0); cache.put(1, 1); tx.suspend(); U.sleep(TX_TIMEOUT * 2); GridTestUtils.assertThrowsWithCause(new Callable<Object>() { @Override public Object call() throws Exception { tx.resume(); return null; } }, TransactionTimeoutException.class); assertTrue(GridTestUtils.waitForCondition(new PA() { @Override public boolean apply() { return tx.state() == ROLLED_BACK; } }, getTestTimeout())); assertEquals(ROLLED_BACK, tx.state()); tx.close(); } } });
otherCache.put(-1, -1); tx.suspend();
@Override public void applyx(Ignite ignite, final IgniteCache<Integer, Integer> cache) throws Exception { for (TransactionIsolation tx1Isolation : TransactionIsolation.values()) { for (TransactionIsolation tx2Isolation : TransactionIsolation.values()) { Transaction tx1 = ignite.transactions().txStart(OPTIMISTIC, tx1Isolation); cache.put(1, 1); tx1.suspend(); assertFalse(cache.containsKey(1)); Transaction tx2 = ignite.transactions().txStart(OPTIMISTIC, tx2Isolation); cache.put(1, 2); tx2.commit(); assertEquals(2, (int)cache.get(1)); tx1.resume(); assertEquals(1, (int)cache.get(1)); tx1.close(); cache.removeAll(); } } } });