use of org.apache.ignite.tx.Transaction in project ignite-3 by apache.
the class ItThinClientTransactionsTest method testAccessLockedKeyTimesOut.
@Test
void testAccessLockedKeyTimesOut() {
KeyValueView<Integer, String> kvView = kvView();
Transaction tx = client().transactions().begin();
kvView.put(tx, -100, "1");
IgniteClientException ex = assertThrows(IgniteClientException.class, () -> kvView.get(null, -100));
assertThat(ex.getMessage(), containsString("TimeoutException"));
tx.rollback();
}
use of org.apache.ignite.tx.Transaction in project ignite-3 by apache.
the class ItThinClientTransactionsTest method testRecordViewBinaryOperations.
@Test
void testRecordViewBinaryOperations() {
RecordView<Tuple> recordView = table().recordView();
Tuple key = key(1);
recordView.upsert(null, kv(1, "1"));
Transaction tx = client().transactions().begin();
recordView.upsert(tx, kv(1, "22"));
assertFalse(recordView.deleteExact(tx, kv(1, "1")));
assertFalse(recordView.insert(tx, kv(1, "111")));
assertEquals(kv(1, "22"), recordView.get(tx, key));
assertEquals(kv(1, "22"), recordView.getAndUpsert(tx, kv(1, "33")));
assertEquals(kv(1, "33"), recordView.getAndReplace(tx, kv(1, "44")));
assertTrue(recordView.replace(tx, kv(1, "55")));
assertEquals(kv(1, "55"), recordView.getAndDelete(tx, key));
assertFalse(recordView.delete(tx, key));
recordView.upsertAll(tx, List.of(kv(1, "6"), kv(2, "7")));
assertEquals(2, recordView.getAll(tx, List.of(key, key(2), key(3))).size());
tx.rollback();
assertEquals(kv(1, "1"), recordView.get(null, key));
}
use of org.apache.ignite.tx.Transaction in project ignite-3 by apache.
the class ItThinClientTransactionsTest method testKvViewOperations.
@Test
void testKvViewOperations() {
KeyValueView<Integer, String> kvView = kvView();
int key = 1;
kvView.put(null, key, "1");
Transaction tx = client().transactions().begin();
kvView.put(tx, key, "22");
assertTrue(kvView.contains(tx, key));
assertFalse(kvView.remove(tx, key, "1"));
assertFalse(kvView.putIfAbsent(tx, key, "111"));
assertEquals("22", kvView.get(tx, key));
assertEquals("22", kvView.getAndPut(tx, key, "33"));
assertEquals("33", kvView.getAndReplace(tx, key, "44"));
assertTrue(kvView.replace(tx, key, "55"));
assertEquals("55", kvView.getAndRemove(tx, key));
assertFalse(kvView.contains(tx, key));
assertFalse(kvView.remove(tx, key));
kvView.putAll(tx, Map.of(key, "6", 2, "7"));
assertEquals(2, kvView.getAll(tx, List.of(key, 2, 3)).size());
tx.rollback();
assertEquals("1", kvView.get(null, key));
}
use of org.apache.ignite.tx.Transaction in project ignite-3 by apache.
the class TxAbstractTest method testConcurrent.
@Test
public void testConcurrent() throws TransactionException {
Transaction tx = igniteTransactions.begin();
Transaction tx2 = igniteTransactions.begin();
Tuple key = makeKey(1);
Tuple val = makeValue(1, 100.);
accounts.recordView().upsert(null, val);
var table = accounts.recordView();
var table2 = accounts.recordView();
assertEquals(100., table.get(tx, key).doubleValue("balance"));
assertEquals(100., table2.get(tx2, key).doubleValue("balance"));
tx.commit();
tx2.commit();
}
use of org.apache.ignite.tx.Transaction in project ignite-3 by apache.
the class TxAbstractTest method testGetAllAbort.
/**
* Tests if a transaction is rolled back if one of the batch keys can't be locked.
*/
@Test
public void testGetAllAbort() throws TransactionException {
List<Tuple> keys = List.of(makeKey(1), makeKey(2));
accounts.recordView().upsertAll(null, List.of(makeValue(1, 100.), makeValue(2, 200.)));
Transaction tx = igniteTransactions.begin();
RecordView<Tuple> txAcc = accounts.recordView();
txAcc.upsert(tx, makeValue(1, 300.));
validateBalance(txAcc.getAll(tx, keys), 300., 200.);
tx.rollback();
validateBalance(accounts.recordView().getAll(null, keys), 100., 200.);
}
Aggregations