@Override public void applyx(Transaction tx) throws Exception { tx.commitAsync().get(FUT_TIMEOUT); } },
/** {@inheritDoc} */ @Override public long processInStreamOutLong(int type, BinaryRawReaderEx reader) throws IgniteCheckedException { long txId = reader.readLong(); IgniteFuture fut0; switch (type) { case OP_COMMIT_ASYNC: fut0 = tx(txId).commitAsync(); break; case OP_ROLLBACK_ASYNC: fut0 = tx(txId).rollbackAsync(); break; default: return super.processInStreamOutLong(type, reader); } // Future result is the tx itself, we do not want to return it to the platform. IgniteFuture fut = fut0.chain(new C1<IgniteFuture, Object>() { private static final long serialVersionUID = 0L; @Override public Object apply(IgniteFuture fut) { return null; } }); readAndListenFuture(reader, fut); return TRUE; }
@Override public Void call() throws Exception { IgniteCache<Integer, String> cache = originatingNodeGrid.cache(DEFAULT_CACHE_NAME); assertNotNull(cache); Transaction tx = originatingNodeGrid.transactions().txStart(); assertEquals(PESSIMISTIC, tx.concurrency()); try { cache.putAll(map); info("Before commitAsync"); IgniteFuture<?> fut = tx.commitAsync(); info("Got future for commitAsync()."); fut.get(3, TimeUnit.SECONDS); } catch (IgniteFutureTimeoutException ignored) { info("Failed to wait for commit future completion [fullFailure=" + fullFailure + ']'); } return null; } }).get();
cache.put(key, key); IgniteFuture<?> fut = tx.commitAsync();
tx.commitAsync().get();
tx.commitAsync().get(); break;
/** * @throws Exception If failed. */ @Test public void testPutAsync() throws Exception { Transaction tx = txShouldBeUsed() ? transactions().txStart() : null; try { jcache().put("key2", 1); IgniteFuture<?> fut1 = jcache().putAsync("key1", 10); IgniteFuture<?> fut2 = jcache().putAsync("key2", 11); IgniteFuture<Void> f = null; if (tx != null) f = tx.commitAsync(); assertNull(fut1.get()); assertNull(fut2.get()); try { if (f != null) f.get(); } catch (Throwable t) { assert false : "Unexpected exception " + t; } } finally { if (tx != null) tx.close(); } checkSize(F.asSet("key1", "key2")); assert jcache().get("key1") == 10; assert jcache().get("key2") == 11; }
/** * @throws Exception If failed. */ @Test public void testPutAsync() throws Exception { Transaction tx = txShouldBeUsed() ? transactions().txStart() : null; try { jcache().put("key2", 1); IgniteFuture<?> fut1 = jcache().putAsync("key1", 10); IgniteFuture<?> fut2 = jcache().putAsync("key2", 11); IgniteFuture<Void> f = null; if (tx != null) f = tx.commitAsync(); assertNull(fut1.get()); assertNull(fut2.get()); try { if (f != null) f.get(); } catch (Throwable t) { assert false : "Unexpected exception " + t; } } finally { if (tx != null) tx.close(); } checkSize(F.asSet("key1", "key2")); assert (Integer)jcache().get("key1") == 10; assert (Integer)jcache().get("key2") == 11; }
cache2.putAsync(key, 2); fut = tx.commitAsync();
/** {@inheritDoc} */ @Override public long processInStreamOutLong(int type, BinaryRawReaderEx reader) throws IgniteCheckedException { long txId = reader.readLong(); IgniteFuture fut0; switch (type) { case OP_COMMIT_ASYNC: fut0 = tx(txId).commitAsync(); break; case OP_ROLLBACK_ASYNC: fut0 = tx(txId).rollbackAsync(); break; default: return super.processInStreamOutLong(type, reader); } // Future result is the tx itself, we do not want to return it to the platform. IgniteFuture fut = fut0.chain(new C1<IgniteFuture, Object>() { private static final long serialVersionUID = 0L; @Override public Object apply(IgniteFuture fut) { return null; } }); readAndListenFuture(reader, fut); return TRUE; }