Search in sources :

Example 46 with TransactionIsolation

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

the class TcpClientTransactions method txStart0.

/**
 * @param concurrency Concurrency.
 * @param isolation Isolation.
 * @param timeout Timeout.
 */
private ClientTransaction txStart0(TransactionConcurrency concurrency, TransactionIsolation isolation, Long timeout, String lb) {
    TcpClientTransaction tx0 = tx();
    if (tx0 != null)
        throw new ClientException("A transaction has already been started by the current thread.");
    tx0 = ch.service(ClientOperation.TX_START, req -> {
        ProtocolContext protocolCtx = req.clientChannel().protocolCtx();
        if (!protocolCtx.isFeatureSupported(TRANSACTIONS)) {
            throw new ClientProtocolError(String.format("Transactions are not supported by the server's " + "protocol version %s, required version %s", protocolCtx.version(), TRANSACTIONS.verIntroduced()));
        }
        try (BinaryRawWriterEx writer = new BinaryWriterExImpl(marsh.context(), req.out(), null, null)) {
            writer.writeByte((byte) (concurrency == null ? txCfg.getDefaultTxConcurrency() : concurrency).ordinal());
            writer.writeByte((byte) (isolation == null ? txCfg.getDefaultTxIsolation() : isolation).ordinal());
            writer.writeLong(timeout == null ? txCfg.getDefaultTxTimeout() : timeout);
            writer.writeString(lb);
        }
    }, res -> new TcpClientTransaction(res.in().readInt(), res.clientChannel()));
    threadLocTxUid.set(tx0.txUid);
    txMap.put(tx0.txUid, tx0);
    return tx0;
}
Also used : TransactionIsolation(org.apache.ignite.transactions.TransactionIsolation) BinaryRawWriterEx(org.apache.ignite.internal.binary.BinaryRawWriterEx) A(org.apache.ignite.internal.util.typedef.internal.A) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) TransactionConcurrency(org.apache.ignite.transactions.TransactionConcurrency) ClientTransactions(org.apache.ignite.client.ClientTransactions) BinaryWriterExImpl(org.apache.ignite.internal.binary.BinaryWriterExImpl) AtomicLong(java.util.concurrent.atomic.AtomicLong) ClientException(org.apache.ignite.client.ClientException) ClientTransaction(org.apache.ignite.client.ClientTransaction) Map(java.util.Map) TRANSACTIONS(org.apache.ignite.internal.client.thin.ProtocolVersionFeature.TRANSACTIONS) ClientTransactionConfiguration(org.apache.ignite.configuration.ClientTransactionConfiguration) ClientException(org.apache.ignite.client.ClientException) BinaryWriterExImpl(org.apache.ignite.internal.binary.BinaryWriterExImpl) BinaryRawWriterEx(org.apache.ignite.internal.binary.BinaryRawWriterEx)

Example 47 with TransactionIsolation

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

the class AveragePersonSalaryCallable method call.

/**
 * {@inheritDoc}
 */
@Override
public Double call() {
    log.info("Job was started with parameters: [node=" + ignite.name() + ", cache=" + cacheName + ", from=" + from + ", to=" + to + ']');
    IgniteCache<Integer, Person> cache = ignite.cache(cacheName);
    if (cache == null)
        return 0D;
    double avgSalary = calculateAverageSalary(cache);
    addPersonWithAverageSalary(cache, avgSalary);
    checkAverageSalaryThroughInvoke(cache, avgSalary);
    if (isTxCache(cache)) {
        log.info("Transaction cache checks was triggered here.");
        for (TransactionIsolation isolation : TransactionIsolation.values()) {
            for (TransactionConcurrency concurrency : TransactionConcurrency.values()) {
                try (Transaction tx = ignite.transactions().txStart(concurrency, isolation)) {
                    double txAvgSalary = calculateAverageSalary(cache);
                    assert Double.compare(txAvgSalary, avgSalary) == 0;
                }
            }
        }
        for (TransactionIsolation isolation : TransactionIsolation.values()) {
            for (TransactionConcurrency concurrency : TransactionConcurrency.values()) {
                try (Transaction tx = ignite.transactions().txStart(concurrency, isolation)) {
                    addPersonWithAverageSalary(cache, avgSalary);
                    checkAverageSalaryThroughInvoke(cache, avgSalary);
                }
            }
        }
    }
    return avgSalary;
}
Also used : TransactionConcurrency(org.apache.ignite.transactions.TransactionConcurrency) Transaction(org.apache.ignite.transactions.Transaction) TransactionIsolation(org.apache.ignite.transactions.TransactionIsolation) Person(org.apache.ignite.tests.p2p.cache.Person)

Example 48 with TransactionIsolation

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

the class GridTransformSpringInjectionSelfTest method testTransformResourceInjection.

/**
 * @throws Exception If failed.
 */
@Test
public void testTransformResourceInjection() throws Exception {
    Ignite grid = grid(0);
    IgniteCache<String, Integer> cache = grid.createCache(cacheConfiguration(ATOMIC));
    try {
        doTransformResourceInjection(cache);
    } finally {
        cache.destroy();
    }
    cache = grid.createCache(cacheConfiguration(TRANSACTIONAL));
    try {
        doTransformResourceInjection(cache);
        for (TransactionConcurrency concurrency : TransactionConcurrency.values()) {
            for (TransactionIsolation isolation : TransactionIsolation.values()) {
                IgniteTransactions txs = grid.transactions();
                try (Transaction tx = txs.txStart(concurrency, isolation)) {
                    doTransformResourceInjection(cache);
                    tx.commit();
                }
            }
        }
    } finally {
        cache.destroy();
    }
}
Also used : TransactionConcurrency(org.apache.ignite.transactions.TransactionConcurrency) Transaction(org.apache.ignite.transactions.Transaction) TransactionIsolation(org.apache.ignite.transactions.TransactionIsolation) Ignite(org.apache.ignite.Ignite) IgniteTransactions(org.apache.ignite.IgniteTransactions) Test(org.junit.Test) GridCacheAbstractSelfTest(org.apache.ignite.internal.processors.cache.GridCacheAbstractSelfTest)

Example 49 with TransactionIsolation

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

the class CacheEventWithTxLabelTest method testPassTxLabelInCashEventForAllCases.

/**
 * Check all cases for passing transaction label in cash event.
 *
 * @throws Exception If failed.
 */
@Test
public void testPassTxLabelInCashEventForAllCases() throws Exception {
    Ignite[] nodes = { client(), primary(), backup1(), backup2() };
    for (int backupCnt = 0; backupCnt < SRVS; backupCnt++) {
        this.backupCnt = backupCnt;
        prepareCache(backupCnt);
        for (TransactionIsolation isolation : TransactionIsolation.values()) {
            this.isolation = isolation;
            for (TransactionConcurrency concurrency : TransactionConcurrency.values()) {
                this.concurrency = concurrency;
                if (MvccFeatureChecker.forcedMvcc() && !MvccFeatureChecker.isSupported(concurrency, isolation))
                    continue;
                for (int i = 0; i < nodes.length - 1; i++) {
                    Ignite nodeForPut = nodes[i];
                    Ignite nodeForGet = nodes[i + 1];
                    singleWriteReadRemoveTest(nodeForPut, nodeForGet);
                    multiWriteReadRemoveTest(nodeForPut, nodeForGet);
                    singleNodeBatchWriteReadRemoveTest(nodeForPut, nodeForGet);
                    multiNodeBatchWriteReadRemoveTest(nodeForPut, nodeForGet);
                    writeInvokeRemoveTest(nodeForPut, nodeForGet);
                    writeInvokeAllRemoveTest(nodeForPut, nodeForGet);
                }
            }
        }
    }
    String listOfFailedTests = String.join(",\n", errors);
    Assert.assertTrue("Have been received " + prevErrCnt + " cache events with incorrect txlabel.\n" + "Failed tests:" + listOfFailedTests, errors.isEmpty());
}
Also used : TransactionConcurrency(org.apache.ignite.transactions.TransactionConcurrency) TransactionIsolation(org.apache.ignite.transactions.TransactionIsolation) Ignite(org.apache.ignite.Ignite) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 50 with TransactionIsolation

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

the class WithKeepBinaryCacheFullApiTest method testInvokeAllTx.

/**
 * @throws Exception If failed.
 */
@Test
public void testInvokeAllTx() throws Exception {
    if (!txShouldBeUsed())
        return;
    for (TransactionConcurrency conc : TransactionConcurrency.values()) {
        for (TransactionIsolation isolation : TransactionIsolation.values()) {
            checkInvokeAllTx(conc, isolation);
            jcache().removeAll();
        }
    }
}
Also used : TransactionConcurrency(org.apache.ignite.transactions.TransactionConcurrency) TransactionIsolation(org.apache.ignite.transactions.TransactionIsolation) Test(org.junit.Test) IgniteCacheConfigVariationsAbstractTest(org.apache.ignite.testframework.junits.IgniteCacheConfigVariationsAbstractTest)

Aggregations

TransactionIsolation (org.apache.ignite.transactions.TransactionIsolation)88 TransactionConcurrency (org.apache.ignite.transactions.TransactionConcurrency)71 Test (org.junit.Test)53 Transaction (org.apache.ignite.transactions.Transaction)52 Ignite (org.apache.ignite.Ignite)33 GridCommonAbstractTest (org.apache.ignite.testframework.junits.common.GridCommonAbstractTest)27 IgniteCache (org.apache.ignite.IgniteCache)14 IgniteTransactions (org.apache.ignite.IgniteTransactions)13 CacheConfiguration (org.apache.ignite.configuration.CacheConfiguration)12 ArrayList (java.util.ArrayList)9 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)9 IgniteEx (org.apache.ignite.internal.IgniteEx)9 IgniteException (org.apache.ignite.IgniteException)8 NearCacheConfiguration (org.apache.ignite.configuration.NearCacheConfiguration)7 HashMap (java.util.HashMap)6 Map (java.util.Map)5 ThreadLocalRandom (java.util.concurrent.ThreadLocalRandom)5 TransactionTimeoutException (org.apache.ignite.transactions.TransactionTimeoutException)5 List (java.util.List)4 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)4