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;
}
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;
}
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();
}
}
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());
}
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();
}
}
}
Aggregations