org.apache.ignite.transactions.Transaction Java Examples
The following examples show how to use
org.apache.ignite.transactions.Transaction.
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: IgniteSqlNotNullConstraintTest.java From ignite with Apache License 2.0 | 6 votes |
/** */ @Test public void testTxPutUpdate() throws Exception { executeWithAllTxCaches(new TestClosure() { @Override public void run() throws Exception { GridTestUtils.assertThrows(log, new Callable<Object>() { @Override public Object call() throws Exception { try (Transaction tx = ignite.transactions().txStart(concurrency, isolation)) { cache.put(key1, okValue); cache.put(key2, okValue); cache.put(key2, badValue); tx.commit(); } assertEquals(0, cache.size()); return null; } }, CacheException.class, ERR_MSG); } }); }
Example #2
Source File: IgniteCacheP2pUnmarshallingTxErrorTest.java From ignite with Apache License 2.0 | 6 votes |
/** {@inheritDoc} */ @Test @Override public void testResponseMessageOnUnmarshallingFailed() { //GridNearTxPrepareRequest unmarshalling failed test readCnt.set(2); failOptimistic(); //GridDhtTxPrepareRequest unmarshalling failed test readCnt.set(3); failOptimistic(); //GridNearLockRequest unmarshalling failed test readCnt.set(2); failPessimictic(); //GridDhtLockRequest unmarshalling failed test readCnt.set(3); try (Transaction tx = grid(0).transactions().txStart(PESSIMISTIC, REPEATABLE_READ)) { jcache(0).put(new TestKey(String.valueOf(++key)), ""); //No failure at client side. } }
Example #3
Source File: GridCacheTransactionalAbstractMetricsSelfTest.java From ignite with Apache License 2.0 | 6 votes |
/** */ @Test public void testCommitTime() { IgniteCache<Integer, Integer> cache = grid(0).cache(DEFAULT_CACHE_NAME); HistogramMetricImpl m = metric("CommitTime"); assertTrue(Arrays.stream(m.value()).allMatch(v -> v == 0)); try (Transaction tx = grid(0).transactions().txStart()) { cache.put(1, 1); tx.commit(); } assertEquals(1, Arrays.stream(m.value()).filter(v -> v == 1).count()); }
Example #4
Source File: GridCacheVersionMultinodeTest.java From ignite with Apache License 2.0 | 6 votes |
/** * @param key Key. * @param txMode Non null tx mode if explicit transaction should be started. * @throws Exception If failed. */ private void checkVersion(String key, @Nullable TransactionConcurrency txMode) throws Exception { IgniteCache<String, Integer> cache = jcache(0); Transaction tx = null; if (txMode != null) tx = cache.unwrap(Ignite.class).transactions().txStart(txMode, REPEATABLE_READ); try { cache.put(key, 1); if (tx != null) tx.commit(); } finally { if (tx != null) tx.close(); } checkEntryVersion(key); }
Example #5
Source File: GridCacheAbstractFullApiSelfTest.java From ignite with Apache License 2.0 | 6 votes |
/** * @param concurrency Concurrency. * @throws Exception If failed. */ private void checkPeekTxRemove(TransactionConcurrency concurrency) throws Exception { if (txShouldBeUsed()) { Ignite ignite = primaryIgnite("key"); IgniteCache<String, Integer> cache = ignite.cache(DEFAULT_CACHE_NAME).withAllowAtomicOpsInTx(); cache.put("key", 1); try (Transaction tx = ignite.transactions().txStart(concurrency, READ_COMMITTED)) { cache.remove("key"); assertNull(cache.get("key")); // localPeek ignores transactions. assertNotNull(peek(cache, "key")); // localPeek ignores transactions. tx.commit(); } } }
Example #6
Source File: GridCacheBinaryObjectsAbstractSelfTest.java From ignite with Apache License 2.0 | 6 votes |
/** * @throws Exception if failed. */ @Test public void testKeepBinaryTxOverwrite() throws Exception { if (atomicityMode() != TRANSACTIONAL) return; IgniteCache<Integer, TestObject> cache = ignite(0).cache(DEFAULT_CACHE_NAME); cache.put(0, new TestObject(1)); for (TransactionConcurrency conc : TransactionConcurrency.values()) { for (TransactionIsolation iso : TransactionIsolation.values()) { try (Transaction tx = ignite(0).transactions().txStart(conc, iso)) { cache.withKeepBinary().get(0); cache.invoke(0, new ObjectEntryProcessor()); tx.commit(); } } } }
Example #7
Source File: CacheMvccSqlConfigurationValidationTest.java From ignite with Apache License 2.0 | 6 votes |
/** * @throws Exception If failed. */ @Test public void testTxDifferentMvccSettingsTransactional() throws Exception { ccfg = defaultCacheConfiguration().setSqlSchema("PUBLIC"); Ignite node = startGrid(); IgniteCache cache = node.cache(DEFAULT_CACHE_NAME); cache.query(new SqlFieldsQuery("CREATE TABLE Person (id int primary key, name varchar) WITH " + "\"atomicity=transactional_snapshot,template=partitioned,backups=1\"")).getAll(); cache.query(new SqlFieldsQuery("CREATE TABLE City (id int primary key, name varchar, population int) WITH " + "\"atomicity=transactional,template=partitioned,backups=3\"")).getAll(); GridTestUtils.assertThrows(log, new Callable<Object>() { @Override public Object call() throws Exception { try (Transaction tx = node.transactions().txStart(TransactionConcurrency.PESSIMISTIC, TransactionIsolation.REPEATABLE_READ)) { cache.query(new SqlFieldsQuery("SELECT * FROM Person, City")).getAll(); tx.commit(); } return null; } }, CacheException.class, "Caches with transactional_snapshot atomicity mode cannot participate in the same transaction"); }
Example #8
Source File: ClusterStateServerAbstractTest.java From ignite with Apache License 2.0 | 6 votes |
/** */ private void changeStateWithPendingTransaction( ClusterState state, TransactionConcurrency concurrency, TransactionIsolation isolation, String exceptionMsg ) { final IgniteCache<Object, Object> cache0 = grid(0).cache(CACHE_NAME); assertNotSame(state, grid(0).cluster().state()); try (Transaction ignore = grid(0).transactions().txStart(concurrency, isolation)) { if (grid(0).cluster().state() != ACTIVE_READ_ONLY) cache0.put(1, "1"); //noinspection ThrowableNotThrown assertThrowsAnyCause(log, changeStateClo(state), IgniteException.class, exceptionMsg); } assertNotSame(state, grid(0).cluster().state()); if (grid(0).cluster().state() != ACTIVE_READ_ONLY) assertNull(cache0.get(1)); assertNull(grid(0).transactions().tx()); }
Example #9
Source File: CacheKeepBinaryTransactionTest.java From ignite with Apache License 2.0 | 6 votes |
/** * @throws Exception If failed. */ @Test public void testBinaryPutGetContains() throws Exception { IgniteEx ignite = grid(0); IgniteCache<Object, Object> cache = ignite.cache("tx-cache").withKeepBinary(); try (Transaction tx = ignite.transactions().txStart()) { IgniteBinary binary = ignite.binary(); BinaryObject key = binary.builder("test-key").setField("id", 1).build(); BinaryObject val = binary.builder("test-val").setField("id", 22).build(); cache.put(key, val); assertTrue(cache.containsKey(key)); assertEquals(val, cache.get(key)); } }
Example #10
Source File: GridCacheFastNodeLeftForTransactionTest.java From ignite with Apache License 2.0 | 6 votes |
/** * Transaction creation. * * @param node Node. * @param cacheName Cache name. * @param keys Keys. * @return Transactions. * @throws Exception If failed. */ private Collection<Transaction> createTxs( IgniteEx node, String cacheName, Collection<Integer> keys ) throws Exception { assert nonNull(node); assert nonNull(cacheName); assert nonNull(keys); IgniteCache<Object, Object> cache = node.cache(cacheName); Collection<Transaction> txs = new ArrayList<>(); for (Integer key : keys) { Transaction tx = node.transactions().txStart(); cache.put(key, key + 10); ((TransactionProxyImpl)tx).tx().prepare(true); txs.add(tx); } return txs; }
Example #11
Source File: GridCacheStopSelfTest.java From ignite with Apache License 2.0 | 6 votes |
/** * @param node Node. * @param cache Cache. */ @SuppressWarnings("unchecked") private void cacheOperations(Ignite node, IgniteCache<Integer, Integer> cache) { ThreadLocalRandom rnd = ThreadLocalRandom.current(); Integer key = rnd.nextInt(1000); cache.put(key, key); cache.get(key); if (cache.getConfiguration(CacheConfiguration.class).getAtomicityMode() != TRANSACTIONAL_SNAPSHOT) { try (Transaction tx = node.transactions().txStart(OPTIMISTIC, REPEATABLE_READ)) { cache.put(key, key); tx.commit(); } } try (Transaction tx = node.transactions().txStart(PESSIMISTIC, REPEATABLE_READ)) { cache.put(key, key); tx.commit(); } }
Example #12
Source File: CacheEntryProcessorNonSerializableTest.java From ignite with Apache License 2.0 | 6 votes |
/** * @param node Grid node. * @param cache Node cache. * @param txConcurrency Transaction concurrency. * @param txIsolation Transaction isolation. */ @SuppressWarnings({"unchecked", "ThrowableNotThrown"}) private void checkMvccInvoke(Ignite node, IgniteCache cache, TransactionConcurrency txConcurrency, TransactionIsolation txIsolation) { try (final Transaction tx = node.transactions().txStart(txConcurrency, txIsolation)) { cache.put(KEY, WRONG_VALUE); GridTestUtils.assertThrowsWithCause(new Callable<Object>() { @Override public Object call() { cache.invoke(KEY, new NonSerialazibleEntryProcessor()); fail("Should never happened."); tx.commit(); return null; } }, NotSerializableException.class); } }
Example #13
Source File: IgniteStartCacheInTransactionSelfTest.java From ignite with Apache License 2.0 | 6 votes |
/** * @throws Exception If failed. */ @Test public void testGetOrCreateCache() throws Exception { final Ignite ignite = grid(0); final String key = "key"; final String val = "val"; IgniteCache<String, String> cache = ignite.cache(DEFAULT_CACHE_NAME).withAllowAtomicOpsInTx(); try (Transaction tx = ignite.transactions().txStart(PESSIMISTIC, REPEATABLE_READ)) { cache.put(key, val); GridTestUtils.assertThrows(log, new Callable<Object>() { @Override public Object call() throws Exception { ignite.getOrCreateCache("NEW_CACHE"); return null; } }, IgniteException.class, EXPECTED_MSG); tx.commit(); } }
Example #14
Source File: CacheStoreListenerRWThroughDisabledTransactionalCacheTest.java From ignite with Apache License 2.0 | 6 votes |
/** * @param concurrency Transaction concurrency level. * @param isolation Transaction isolation level. */ private void testTransactionalRemove(TransactionConcurrency concurrency, TransactionIsolation isolation) { IgniteCache cache = grid(0).getOrCreateCache(DEFAULT_CACHE_NAME); Random r = new Random(); try (Transaction tx = grid(0).transactions().txStart(concurrency, isolation)) { for (int i = 0; i < CNT; ++i) { int key = r.nextInt(); cache.put(key, "test-value"); cache.remove(key, "test-value"); } tx.commit(); } }
Example #15
Source File: IgniteClientReconnectCacheTest.java From ignite with Apache License 2.0 | 5 votes |
/** * @throws Exception If failed. */ @Test public void testTxStateAfterClientReconnect() throws Exception { IgniteEx client = startClientGrid(SRV_CNT); Ignite srv = ignite(0); CacheConfiguration<Object, Object> ccfg = new CacheConfiguration<>(DEFAULT_CACHE_NAME); ccfg.setAtomicityMode(TRANSACTIONAL); ccfg.setCacheMode(PARTITIONED); ccfg.setBackups(1); IgniteCache<Object, Object> cache = client.getOrCreateCache(ccfg); final IgniteTransactions txs = client.transactions(); for (TransactionConcurrency concurrency : TransactionConcurrency.values()) { for (TransactionIsolation isolation : TransactionIsolation.values()) { Transaction tx = txs.txStart(concurrency, isolation); cache.put(1, 1); reconnectClientNode(client, srv, null); GridTestUtils.assertThrowsWithCause(() -> { tx.commit(); return null; }, TransactionRollbackException.class); } } }
Example #16
Source File: CacheMvccSqlTxQueriesAbstractTest.java From ignite with Apache License 2.0 | 5 votes |
/** * @throws Exception If failed. */ @Test public void testQueryUpdateStaticCache() throws Exception { ccfg = cacheConfiguration(cacheMode(), FULL_SYNC, 2, DFLT_PARTITION_COUNT) .setIndexedTypes(Integer.class, Integer.class); startGridsMultiThreaded(4); Random rnd = ThreadLocalRandom.current(); Ignite checkNode = grid(rnd.nextInt(4)); Ignite updateNode = grid(rnd.nextInt(4)); IgniteCache cache = checkNode.cache(DEFAULT_CACHE_NAME); cache.putAll(F.asMap(1, 1, 2, 2, 3, 3)); assertEquals(1, cache.get(1)); assertEquals(2, cache.get(2)); assertEquals(3, cache.get(3)); try (Transaction tx = updateNode.transactions().txStart(PESSIMISTIC, REPEATABLE_READ)) { tx.timeout(TX_TIMEOUT); SqlFieldsQuery qry = new SqlFieldsQuery("UPDATE Integer SET _val = (_key * 10)"); IgniteCache<Object, Object> cache0 = updateNode.cache(DEFAULT_CACHE_NAME); try (FieldsQueryCursor<List<?>> cur = cache0.query(qry)) { assertEquals(3L, cur.iterator().next().get(0)); } tx.commit(); } assertEquals(10, cache.get(1)); assertEquals(20, cache.get(2)); assertEquals(30, cache.get(3)); }
Example #17
Source File: CacheMvccSqlTxQueriesAbstractTest.java From ignite with Apache License 2.0 | 5 votes |
/** * @throws Exception If failed. */ @Test public void testInsertAndFastUpdateWithoutVersionConflict() throws Exception { ccfg = cacheConfiguration(cacheMode(), FULL_SYNC, 2, DFLT_PARTITION_COUNT) .setIndexedTypes(Integer.class, Integer.class); startGridsMultiThreaded(2); IgniteCache<?, ?> cache0 = grid(0).cache(DEFAULT_CACHE_NAME); try (Transaction tx1 = grid(0).transactions().txStart(PESSIMISTIC, REPEATABLE_READ)) { // obtain tx version cache0.query(new SqlFieldsQuery("select * from Integer where _key = 1")); runAsync(() -> { cache0.query(new SqlFieldsQuery("insert into Integer(_key, _val) values(?, ?)").setArgs(1, 1)); }).get(); cache0.query(new SqlFieldsQuery("update Integer set _val = ? where _key = ?").setArgs(1, 1)); tx1.commit(); } catch (Exception e) { e.printStackTrace(); fail("Exception is not expected here"); } }
Example #18
Source File: MvccUnsupportedTxModesTest.java From ignite with Apache License 2.0 | 5 votes |
/** */ private void assertNotSupportedInTx(Runnable action, TransactionConcurrency conc, TransactionIsolation iso) { try (Transaction ignored = grid(0).transactions().txStart(conc, iso)) { action.run(); fail("Action failure is expected."); } catch (TransactionException e) { assertEquals("Only pessimistic transactions are supported when MVCC is enabled.", e.getMessage()); } }
Example #19
Source File: TxRollbackAsyncTest.java From ignite with Apache License 2.0 | 5 votes |
/** * */ private void testEnlistMany(boolean write, TransactionIsolation isolation, TransactionConcurrency conc) throws Exception { final Ignite client = startClient(); Map<Integer, Integer> entries = new TreeMap<>(); for (int i = 0; i < 1000000; i++) entries.put(i, i); IgniteInternalFuture<?> fut = null; try (Transaction tx = client.transactions().txStart(conc, isolation, 0, 0)) { fut = rollbackAsync(tx, 200); if (write) client.cache(CACHE_NAME).putAll(entries); else client.cache(CACHE_NAME).getAll(entries.keySet()); tx.commit(); fail("Commit must fail"); } catch (Throwable t) { assertTrue(X.hasCause(t, TransactionRollbackException.class)); } fut.get(); assertEquals(0, client.cache(CACHE_NAME).size()); checkFutures(); }
Example #20
Source File: TxStateChangeEventTest.java From ignite with Apache License 2.0 | 5 votes |
/** * @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()); }
Example #21
Source File: ExplicitTransactionalReadRepairTest.java From ignite with Apache License 2.0 | 5 votes |
/** {@inheritDoc} */ @Override protected void testContains(Ignite initiator, Integer cnt, boolean all) throws Exception { prepareAndCheck( initiator, cnt, raw, async, (ReadRepairData data) -> { try (Transaction tx = initiator.transactions().txStart(concurrency, isolation)) { // Recovery (inside tx). if (all) CONTAINS_ALL_CHECK_AND_FIX.accept(data); else CONTAINS_CHECK_AND_FIX.accept(data); ENSURE_FIXED.accept(data); // Checks (inside tx). try { tx.commit(); } catch (TransactionRollbackException e) { fail("Should not happen. " + e); } } ENSURE_FIXED.accept(data); // Checks (outside tx). }); }
Example #22
Source File: TestThreadLocalCacheSession.java From ignite with Apache License 2.0 | 5 votes |
/** * @param tx Transaction. */ public void newSession(@Nullable Transaction tx) { TestCacheSession ses = new TestCacheSession(); ses.newSession(tx); sesHolder.set(ses); }
Example #23
Source File: GridCacheNearMultiNodeSelfTest.java From ignite with Apache License 2.0 | 5 votes |
/** * @param key Key * @throws Exception If failed. */ public void checkTransactionSingleGetRemove(int key) throws Exception { IgniteCache<Object, Object> cache = jcache(0); String val = Integer.toString(key); cache.put(key, val); assertEquals(val, dhtPeek(0, key)); assertEquals(val, dhtPeek(1, key)); assertNull(near(0).peekEx(key)); assertNull(near(1).peekEx(key)); if (transactional()) { try (Transaction tx = grid(0).transactions().txStart(PESSIMISTIC, REPEATABLE_READ)) { // Read. assertEquals(val, cache.get(key)); // Remove. assertTrue(cache.remove(key)); tx.commit(); } } else { // Read. assertEquals(val, cache.get(key)); // Remove. assertTrue(cache.remove(key)); } assertNull(dhtPeek(0, key)); assertNull(dhtPeek(1, key)); assertNull(near(0).peekEx(key)); assertNull(near(1).peekEx(key)); }
Example #24
Source File: DmlInsideTransactionTest.java From ignite with Apache License 2.0 | 5 votes |
/** * Run DML query and check that DML is not allowed or not inside transaction. Also checked that using DML will not * lead to rollback. * * @param query Query with DML operation to be run. * @param isAllowed true in case DML should work inside transaction, false otherwise. */ private void runDmlInTransactionTest(Query query, boolean isAllowed) { IgniteEx ignite = grid(0); IgniteCache<PersonKey, Person> cache = ignite.cache(CACHE_PERSON); cache.removeAll(); assertEquals(0, cache.query(new SqlFieldsQuery("SELECT * FROM TEST.Person")).getAll().size()); try (Transaction tx = ignite.transactions().txStart()) { cache.put(new PersonKey(1L), new Person("person", 2)); if (isAllowed) cache.query(query); else { assertThrows(log, () -> { cache.query(query); return null; }, CacheException.class, "DML statements are not allowed inside a transaction over cache(s) with TRANSACTIONAL atomicity"); } tx.commit(); } assertTrue(!cache.query(new SqlFieldsQuery("SELECT * FROM TEST.Person")).getAll().isEmpty()); }
Example #25
Source File: MvccDeadlockDetectionConfigTest.java From ignite with Apache License 2.0 | 5 votes |
/** */ @Test public void deadlockDetectionEnabled() throws Exception { deadlockDetectionEnabled = true; Ignite ign = startGrid(); IgniteCache<Object, Object> cache = ign.createCache(new CacheConfiguration<>(DEFAULT_CACHE_NAME) .setAtomicityMode(TRANSACTIONAL_SNAPSHOT)); CyclicBarrier b = new CyclicBarrier(2); IgniteInternalFuture<?> futA = GridTestUtils.runAsync(() -> { try (Transaction tx = ign.transactions().txStart(PESSIMISTIC, REPEATABLE_READ)) { cache.put(1, 'a'); b.await(); cache.put(2, 'a'); } return null; }); IgniteInternalFuture<?> futB = GridTestUtils.runAsync(() -> { try (Transaction tx = ign.transactions().txStart(PESSIMISTIC, REPEATABLE_READ)) { cache.put(2, 'b'); b.await(); cache.put(1, 'b'); } return null; }); IgniteCheckedException e = awaitCompletion(futA, futB); assertTrue(e.toString(), X.hasCause(e, "Deadlock", IgniteTxRollbackCheckedException.class)); }
Example #26
Source File: MvccDeadlockDetectionTest.java From ignite with Apache License 2.0 | 5 votes |
/** */ private void tryPutRepeatedly(IgniteCache<Object, Object> cache, Integer key0) { for (int i = 0; i < 100; i++) { try (Transaction tx = client.transactions().txStart(PESSIMISTIC, REPEATABLE_READ, 200, 1)) { cache.put(key0, 33); break; } catch (Exception ignored) { } } }
Example #27
Source File: CacheHibernateBlobStore.java From ignite with Apache License 2.0 | 5 votes |
/** {@inheritDoc} */ @Override public void write(javax.cache.Cache.Entry<? extends K, ? extends V> entry) { init(); Transaction tx = transaction(); K key = entry.getKey(); V val = entry.getValue(); if (log.isDebugEnabled()) log.debug("Store put [key=" + key + ", val=" + val + ", tx=" + tx + ']'); if (val == null) { delete(key); return; } Session ses = session(tx); try { CacheHibernateBlobStoreEntry entry0 = new CacheHibernateBlobStoreEntry(toBytes(key), toBytes(val)); ses.saveOrUpdate(entry0); } catch (IgniteCheckedException | HibernateException e) { rollback(ses, tx); throw new CacheWriterException("Failed to put value to cache store [key=" + key + ", val" + val + "]", e); } finally { end(ses, tx); } }
Example #28
Source File: CacheMvccSqlTxModesTest.java From ignite with Apache License 2.0 | 5 votes |
/** * @throws Exception If failed */ @Test public void testConsequentMvccNonMvccOperations() throws Exception { IgniteEx node = startGrid(0); IgniteCache<Object, Object> mvccCache = node.createCache(new CacheConfiguration<>("mvcc-cache") .setAtomicityMode(TRANSACTIONAL_SNAPSHOT).setIndexedTypes(Integer.class, Integer.class)); IgniteCache<Object, Object> nonMvccCache = node.createCache(new CacheConfiguration<>("no-mvcc-cache") .setAtomicityMode(TRANSACTIONAL).setIndexedTypes(Integer.class, Integer.class)); nonMvccCache.put(1, 1); try (Transaction tx = node.transactions().txStart(PESSIMISTIC, REPEATABLE_READ)) { mvccCache.query(new SqlFieldsQuery("INSERT INTO Integer (_key, _val) VALUES (3,3)")).getAll(); tx.commit(); } try (Transaction tx = node.transactions().txStart(PESSIMISTIC, REPEATABLE_READ)) { nonMvccCache.put(2, 2); tx.commit(); } try (Transaction tx = node.transactions().txStart(PESSIMISTIC, REPEATABLE_READ)) { mvccCache.query(new SqlFieldsQuery("INSERT INTO Integer (_key, _val) VALUES (5,5)")).getAll(); tx.commit(); } nonMvccCache.put(6, 6); try (Transaction tx = node.transactions().txStart(PESSIMISTIC, REPEATABLE_READ)) { mvccCache.query(new SqlFieldsQuery("INSERT INTO Integer (_key, _val) VALUES (7,7)")).getAll(); tx.commit(); } }
Example #29
Source File: TxMultiCacheAsyncOpsTest.java From ignite with Apache License 2.0 | 5 votes |
/** * */ @Test public void testCommitAfterAsyncPut() { CacheConfiguration[] caches = cacheConfigurations(); try { for (int i = 0; i < caches.length; i++) grid(0).cache(caches[i].getName()).put(1, i + 1); try (Transaction tx = grid(0).transactions().txStart()) { for (int i = 0; i < caches.length; i++) grid(0).cache(caches[i].getName()).putAsync(1, (i + 1) * 10); tx.commit(); } catch (Exception e) { System.out.println(); } for (int i = 0; i < caches.length; i++) assertEquals((i + 1) * 10, grid(0).cache(caches[i].getName()).get(1)); } finally { for (int i = 0; i < caches.length; i++) grid(0).cache(caches[i].getName()).removeAll(); } }
Example #30
Source File: TxLabelTest.java From ignite with Apache License 2.0 | 5 votes |
/** * @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(); } }