Java Code Examples for org.apache.ignite.transactions.Transaction#suspend()
The following examples show how to use
org.apache.ignite.transactions.Transaction#suspend() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: IgniteAbstractTxSuspendResumeTest.java From ignite with Apache License 2.0 | 4 votes |
/** * @param ignite Ignite. * @param cache Cache. * @param isolation Isolation. * @param suspended Left transaction in suspended state. */ private Transaction initTxWithTimeout(Ignite ignite, IgniteCache cache, TransactionIsolation isolation, boolean suspended) throws Exception { final int RETRIES = 5; // Make several attempts to init transaction, sometimes it takes more time then given timeout. for (int i = 0; i < RETRIES; i++) { try { final Transaction tx = ignite.transactions().txStart(transactionConcurrency(), isolation, TX_TIMEOUT, 0); cache.put(1, 1); tx.suspend(); GridTestUtils.runAsync(() -> { tx.resume(); cache.put(1, 1); cache.put(2, 2); tx.suspend(); }).get(FUT_TIMEOUT); tx.resume(); cache.put(1, 1); cache.put(2, 2); cache.put(3, 3); if (suspended) tx.suspend(); return tx; } catch (Exception e) { if (X.hasCause(e, TransactionTimeoutException.class)) { if (i == RETRIES - 1) { throw new Exception("Can't init transaction within given timeout [isolation=" + isolation + ", cache=" + cache.getName() + ", ignite=" + ignite.configuration().getIgniteInstanceName() + ']', e); } else { log.info("Got timeout on transaction init [attempt=" + i + ", isolation=" + isolation + ", cache=" + cache.getName() + ", ignite=" + ignite.configuration().getIgniteInstanceName() + ']'); } } else throw e; } } return null; }
Example 2
Source File: GridCacheTransactionalAbstractMetricsSelfTest.java From ignite with Apache License 2.0 | 2 votes |
/** * Metrics test for transaction timeout rollback. * * @param concurrency Concurrency control. * @param isolation Isolation level. * @throws Exception If failed. */ private void doTestSuspendedTxTimeoutRollbacks(TransactionConcurrency concurrency, TransactionIsolation isolation) throws Exception { IgniteCache<Integer, Integer> cache = grid(0).cache(DEFAULT_CACHE_NAME); IgniteTransactions transactions = grid(0).transactions(); for (int i = 0; i < TX_CNT; i++) { Transaction tx = transactions.txStart(concurrency, isolation, TX_TIMEOUT, 0); cache.put(1, 1); tx.suspend(); boolean res = GridTestUtils.waitForCondition(() -> tx.state() == ROLLED_BACK, TX_TIMEOUT * 10); assertTrue(res); tx.close(); } TransactionMetrics txMetrics = transactions.metrics(); CacheMetrics cacheMetrics = cache.localMetrics(); assertEquals(0, txMetrics.txCommits()); assertEquals(0, cacheMetrics.getCacheTxCommits()); assertEquals(TX_CNT, txMetrics.txRollbacks()); assertEquals(TX_CNT, cacheMetrics.getCacheTxRollbacks()); assertTrue(cacheMetrics.getAverageTxRollbackTime() > 0); for (int i = 1; i < gridCount(); i++) { txMetrics = grid(i).transactions().metrics(); cacheMetrics = grid(i).cache(DEFAULT_CACHE_NAME).localMetrics(); assertEquals(0, txMetrics.txCommits()); assertEquals(0, cacheMetrics.getCacheTxCommits()); assertEquals(0, txMetrics.txRollbacks()); assertEquals(0, cacheMetrics.getCacheTxRollbacks()); } }