Refine search
/** * @param concurrency Concurrency mode. * @param isolation Isolation mode. * @return Transaction. */ private Transaction startTx(TransactionConcurrency concurrency, TransactionIsolation isolation) { IgniteTransactions txs = ignite(0).transactions(); if (concurrency == null) return txs.txStart(); return txs.txStart(concurrency, isolation); }
@Override public Void call() throws Exception { Transaction tx = ignite0.transactions().txStart(PESSIMISTIC, REPEATABLE_READ); ignite0.cache(DEFAULT_CACHE_NAME).get(key); return null; } }, "lock-thread1");
@Override public void applyx() throws IgniteCheckedException { try (Transaction tx = ignite.transactions().txStart(TransactionConcurrency.PESSIMISTIC, isolation, timeout, keys.size())) { List<Integer> keys0 = getAndFlip(reverse) ? keys : keysReversed; for (int i = 0; i < keys0.size(); i++) { Integer key = keys0.get(i); if(oneOp) cache.getAndPut(key, new Account(key, (key + 1) * 100)); else cache.put(key, new Account(cache.get(key).id, (key + 1) * 100)); if (i == 0) barrier.await(timeout >> 1, TimeUnit.MILLISECONDS); } tx.commit(); } catch (Exception e) { ex.compareAndSet(null, e); } } }, 2, "tx");
/** * @param cache Cache. * @param key Key. * @param concurrency Transaction concurrency. * @param isolation Transaction isolation. * @throws Exception If failed. */ private void checkReadThroughGetAndInvoke(IgniteCache<Object, Object> cache, Object key, TransactionConcurrency concurrency, TransactionIsolation isolation) throws Exception { putDataInStore(Collections.singletonMap(key, key), cache.getName()); try (Transaction tx = cache.unwrap(Ignite.class).transactions().txStart(concurrency, isolation)) { cache.get(key); Object ret = cache.invoke(key, new TestEntryProcessor()); assertEquals(key, ret); tx.commit(); } checkValue(cache.getName(), key, (Integer)key + 1); }
@Override public Void call() throws Exception { try (Transaction tx = ignite.transactions().txStart(OPTIMISTIC, SERIALIZABLE)) { if (entry) readCache.get(readKey); else readCache.getEntry(readKey); barrier.await(); writeCache.put(putKey.incrementAndGet(), 0); tx.commit(); } return null; } }, THREADS, "test-thread");
/** * Test simple key/value. * @param key Simple key. * @throws Exception If failed. */ private void checkSimple(String key) throws Exception { for (int i = INIT_GRID_NUM; i < MAX_GRID_NUM; i++) { startGrid(i); assert PARTITIONED == grid(i).cache(DEFAULT_CACHE_NAME).getConfiguration(CacheConfiguration.class).getCacheMode(); try (Transaction tx = grid(i).transactions().txStart(PESSIMISTIC, REPEATABLE_READ)) { Integer val = (Integer) grid(i).cache(DEFAULT_CACHE_NAME).get(key); assertEquals("Simple check failed for node: " + i, (Integer) i, val); grid(i).cache(DEFAULT_CACHE_NAME).put(key, i + 1); tx.commit(); } stopGrid(i); } }
@Override public Void call() throws Exception { IgniteCache<Object, Object> cache = node1.cache(DEFAULT_CACHE_NAME); try (Transaction tx = node1.transactions().txStart()) { Integer key = keys.get(idx.getAndIncrement()); cache.getAndPut(key, "new-" + key); tx.commit(); } return null; } }, txCnt, "tx");
@Override public Object call() throws Exception { info(">>>> Starting grid."); Ignite g4 = startGrid(4); started.set(true); IgniteCache<Object, Object> c = g4.cache(DEFAULT_CACHE_NAME); info(">>>> Checking tx in new grid."); try (Transaction tx = g4.transactions().txStart(PESSIMISTIC, REPEATABLE_READ)) { assertEquals(2, c.get("a")); assertEquals(4, c.get("b")); assertEquals(6, c.get("c")); } return null; } }, 1);
@Override public void run() { IgniteTransactions txs = grid(0).transactions(); cache.put(key2, new TestValue(key2)); long stopTime = System.currentTimeMillis() + 3000; while (System.currentTimeMillis() < stopTime) { try (Transaction tx = txs.txStart(OPTIMISTIC, txIsolation)) { cache.get(key1); tx.commit(); } catch (Exception ignored) { fail("Unexpected exception: " + ignored); } } } }, 10, "tx-thread");
@Override public Object call() throws Exception { try (Transaction tx = ignite(0).transactions().txStart()) { jcache(0).lockAll(Arrays.asList("key1", "key2")).lock(); } return null; } },
@Override public void run(IgniteCache<String, Integer> cache) throws IgniteCheckedException { Map.Entry<String, Integer> e = F.first(pairs(1).entrySet()); assert e != null; String key = e.getKey(); Integer val = e.getValue(); try (Transaction tx = cache.unwrap(Ignite.class).transactions().txStart()) { assert cache.getAndPut(key, val) == null; assert cache.containsKey(key); assert val.equals(cache.get(key)); assert val.equals(cache.getAndRemove(key)); assert !cache.containsKey(key); tx.commit(); } assert !cache.containsKey(key); } }, F.t(EVT_CACHE_OBJECT_REMOVED, gridCnt));
@Override public void run() { Ignite node = ignite(0); IgniteCache<Integer, Integer> cache = node.cache(DEFAULT_CACHE_NAME); ThreadLocalRandom rnd = ThreadLocalRandom.current(); while (!stop.get()) { try (Transaction tx = node.transactions().txStart(PESSIMISTIC, REPEATABLE_READ)) { for (int i = 0; i < KEYS; i++) { if (rnd.nextBoolean()) cache.get(i); } } } } }, 3, "tx-thread");
@Override public void applyx() { IgniteCache<Integer, Integer> c = grid(0).cache(DEFAULT_CACHE_NAME); for (int i = 0; i < TX_CNT; i++) { int kv = cntr.incrementAndGet(); try (Transaction tx = grid(0).transactions().txStart(concurrency, isolation)) { assertNull(c.get(kv)); c.put(kv, kv); assertEquals(Integer.valueOf(kv), c.get(kv)); // Again. c.put(kv, kv); assertEquals(Integer.valueOf(kv), c.get(kv)); tx.commit(); } if (TEST_INFO && kv % 1000 == 0) info("Transactions: " + kv); } } }, THREAD_CNT);
/** * @param txMode Transaction concurrency mode. * @return Transaction. */ @Nullable private Transaction startTx(@Nullable TransactionConcurrency txMode) { return txMode == null ? null : ignite(0).transactions().txStart(txMode, REPEATABLE_READ); }
@Override public void run(IgniteCache<String, Integer> cache) throws IgniteCheckedException { Map.Entry<String, Integer> e = F.first(pairs(1).entrySet()); assert e != null; String key = e.getKey(); Integer val = e.getValue(); try (Transaction tx = cache.unwrap(Ignite.class).transactions().txStart()) { assert cache.getAndPut(key, val) == null; assert cache.containsKey(key); assert val.equals(cache.get(key)); assert val.equals(cache.getAndRemove(key)); assert !cache.containsKey(key); cache.put(key, val); assert cache.containsKey(key); tx.commit(); } assert cache.containsKey(key); } }, F.t(EVT_CACHE_OBJECT_PUT, gridCnt));
@Override public void run() { U.awaitQuiet(l); try (final Transaction tx = ignite.transactions().txStart()) { cache.get(0); tx.commit(); } } });
/** * @param txMode Transaction concurrency mode. * @return Transaction. */ @Nullable private Transaction startTx(@Nullable TransactionConcurrency txMode) { return txMode == null ? null : ignite(0).transactions().txStart(txMode, REPEATABLE_READ); }
@Override public void run() { try { try (Transaction ignored = g0.transactions().txStart(PESSIMISTIC, REPEATABLE_READ)) { g0.cache(DEFAULT_CACHE_NAME).get(1); latch.countDown(); Thread.sleep(500); info("Before stop."); G.stop(getTestIgniteInstanceName(1), true); } } catch (Exception e) { error("Error.", e); } } });