Search in sources :

Example 16 with Transaction

use of org.apache.ignite.transactions.Transaction in project ignite by apache.

the class IgniteSqlNotNullConstraintTest method testTxGetAndReplace.

/**
 */
public void testTxGetAndReplace() throws Exception {
    executeWithAllTxCaches(new TestClosure() {

        @Override
        public void run() throws Exception {
            GridTestUtils.assertThrows(log, new Callable<Object>() {

                @Override
                public Object call() throws Exception {
                    cache.put(key1, okValue);
                    try (Transaction tx = ignite.transactions().txStart(concurrency, isolation)) {
                        cache.getAndReplace(key1, badValue);
                        tx.commit();
                    }
                    assertEquals(1, cache.size());
                    assertEquals(okValue, cache.get(key1));
                    return null;
                }
            }, CacheException.class, ERR_MSG);
        }
    });
}
Also used : Transaction(org.apache.ignite.transactions.Transaction) CacheException(javax.cache.CacheException) EntryProcessorException(javax.cache.processor.EntryProcessorException) CacheException(javax.cache.CacheException) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) Callable(java.util.concurrent.Callable)

Example 17 with Transaction

use of org.apache.ignite.transactions.Transaction in project ignite by apache.

the class IgniteSqlNotNullConstraintTest method testTxReplace.

/**
 */
public void testTxReplace() throws Exception {
    executeWithAllTxCaches(new TestClosure() {

        @Override
        public void run() throws Exception {
            GridTestUtils.assertThrows(log, new Callable<Object>() {

                @Override
                public Object call() throws Exception {
                    cache.put(1, okValue);
                    try (Transaction tx = ignite.transactions().txStart(concurrency, isolation)) {
                        cache.replace(key1, badValue);
                        tx.commit();
                    }
                    assertEquals(1, cache.size());
                    assertEquals(okValue, cache.get(key1));
                    return null;
                }
            }, CacheException.class, ERR_MSG);
        }
    });
}
Also used : Transaction(org.apache.ignite.transactions.Transaction) CacheException(javax.cache.CacheException) EntryProcessorException(javax.cache.processor.EntryProcessorException) CacheException(javax.cache.CacheException) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) Callable(java.util.concurrent.Callable)

Example 18 with Transaction

use of org.apache.ignite.transactions.Transaction in project ignite by apache.

the class IgniteSqlNotNullConstraintTest method testTxPutAll.

/**
 */
public void testTxPutAll() 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.putAll(F.asMap(key1, okValue, key2, badValue));
                        tx.commit();
                    }
                    assertEquals(0, cache.size());
                    return null;
                }
            }, CacheException.class, ERR_MSG);
        }
    });
}
Also used : Transaction(org.apache.ignite.transactions.Transaction) CacheException(javax.cache.CacheException) EntryProcessorException(javax.cache.processor.EntryProcessorException) CacheException(javax.cache.CacheException) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) Callable(java.util.concurrent.Callable)

Example 19 with Transaction

use of org.apache.ignite.transactions.Transaction in project ignite by apache.

the class IgniteSqlNotNullConstraintTest method testTxGetAndPutIfAbsent.

/**
 */
public void testTxGetAndPutIfAbsent() 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.getAndPutIfAbsent(key1, badValue);
                        tx.commit();
                    }
                    assertEquals(0, cache.size());
                    return null;
                }
            }, CacheException.class, ERR_MSG);
        }
    });
}
Also used : Transaction(org.apache.ignite.transactions.Transaction) CacheException(javax.cache.CacheException) EntryProcessorException(javax.cache.processor.EntryProcessorException) CacheException(javax.cache.CacheException) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) Callable(java.util.concurrent.Callable)

Example 20 with Transaction

use of org.apache.ignite.transactions.Transaction in project ignite by apache.

the class SpringTransactionManager method doCleanupAfterCompletion.

/**
 * {@inheritDoc}
 */
@Override
protected void doCleanupAfterCompletion(Object transaction) {
    IgniteTransactionObject txObj = (IgniteTransactionObject) transaction;
    // Remove the transaction holder from the thread, if exposed.
    if (txObj.isNewTransactionHolder()) {
        Transaction tx = txObj.getTransactionHolder().getTransaction();
        TransactionSynchronizationManager.unbindResource(this.ignite);
        if (log.isDebugEnabled())
            log.debug("Releasing Ignite transaction: " + tx);
    }
    txObj.getTransactionHolder().clear();
}
Also used : Transaction(org.apache.ignite.transactions.Transaction)

Aggregations

Transaction (org.apache.ignite.transactions.Transaction)493 Ignite (org.apache.ignite.Ignite)204 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)183 IgniteCache (org.apache.ignite.IgniteCache)88 IgniteTransactions (org.apache.ignite.IgniteTransactions)78 IgniteException (org.apache.ignite.IgniteException)74 CacheException (javax.cache.CacheException)60 HashMap (java.util.HashMap)54 CacheConfiguration (org.apache.ignite.configuration.CacheConfiguration)45 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)44 TransactionOptimisticException (org.apache.ignite.transactions.TransactionOptimisticException)42 ArrayList (java.util.ArrayList)41 Callable (java.util.concurrent.Callable)41 Map (java.util.Map)36 IgniteEx (org.apache.ignite.internal.IgniteEx)34 CountDownLatch (java.util.concurrent.CountDownLatch)32 IgniteKernal (org.apache.ignite.internal.IgniteKernal)30 TransactionConcurrency (org.apache.ignite.transactions.TransactionConcurrency)30 ThreadLocalRandom (java.util.concurrent.ThreadLocalRandom)29 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)29