use of org.apache.ignite.table.Tuple in project ignite-3 by apache.
the class TxAbstractTest method testCommit.
@Test
public void testCommit() throws TransactionException {
InternalTransaction tx = (InternalTransaction) igniteTransactions.begin();
Tuple key = makeKey(1);
var table = accounts.recordView();
table.upsert(tx, makeValue(1, 100.));
assertEquals(100., table.get(tx, key).doubleValue("balance"));
table.upsert(tx, makeValue(1, 200.));
assertEquals(200., table.get(tx, key).doubleValue("balance"));
tx.commit();
assertEquals(200., accounts.recordView().get(null, key).doubleValue("balance"));
assertEquals(COMMITED, txManager(accounts).state(tx.timestamp()));
}
use of org.apache.ignite.table.Tuple in project ignite-3 by apache.
the class TxAbstractTest method testAbort.
@Test
public void testAbort() throws TransactionException {
InternalTransaction tx = (InternalTransaction) igniteTransactions.begin();
Tuple key = makeKey(1);
var table = accounts.recordView();
table.upsert(tx, makeValue(1, 100.));
assertEquals(100., table.get(tx, key).doubleValue("balance"));
table.upsert(tx, makeValue(1, 200.));
assertEquals(200., table.get(tx, key).doubleValue("balance"));
tx.rollback();
assertNull(accounts.recordView().get(null, key));
assertEquals(ABORTED, txManager(accounts).state(tx.timestamp()));
}
use of org.apache.ignite.table.Tuple in project ignite-3 by apache.
the class TxAbstractTest method testIncrement2.
/**
* Tests if a lost update is not happening on concurrent increment.
*/
@Test
public void testIncrement2() throws TransactionException, InterruptedException {
InternalTransaction tx = (InternalTransaction) igniteTransactions.begin();
InternalTransaction tx2 = (InternalTransaction) igniteTransactions.begin();
Tuple key = makeKey(1);
Tuple val = makeValue(1, 100.);
// Creates implicit transaction.
accounts.recordView().upsert(null, val);
var table = accounts.recordView();
var table2 = accounts.recordView();
// Read in tx
double valTx = table.get(tx, key).doubleValue("balance");
// Read in tx2
double valTx2 = table2.get(tx2, key).doubleValue("balance");
// Write in tx2 (should wait for read unlock in tx1)
CompletableFuture<Void> fut = table2.upsertAsync(tx2, makeValue(1, valTx2 + 1));
// Give some time to update lock queue TODO asch IGNITE-15928
Thread.sleep(300);
assertFalse(fut.isDone());
CompletableFuture<Void> fut2 = fut.thenCompose(ret -> tx2.commitAsync());
// Write in tx
table.upsert(tx, makeValue(1, valTx + 1));
tx.commit();
Exception err = assertThrows(Exception.class, () -> fut2.get(5, TimeUnit.SECONDS));
assertTrue(err.getMessage().contains("Failed to acquire a lock"), err.getMessage());
assertEquals(101., accounts.recordView().get(null, key).doubleValue("balance"));
}
use of org.apache.ignite.table.Tuple 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.table.Tuple in project ignite-3 by apache.
the class TxAbstractTest method testReorder.
@Test
public void testReorder() throws Exception {
accounts.recordView().upsert(null, makeValue(1, 100.));
InternalTransaction tx = (InternalTransaction) igniteTransactions.begin();
InternalTransaction tx2 = (InternalTransaction) igniteTransactions.begin();
InternalTransaction tx3 = (InternalTransaction) igniteTransactions.begin();
var table = accounts.recordView();
var table2 = accounts.recordView();
var table3 = accounts.recordView();
double v0 = table.get(tx, makeKey(1)).doubleValue("balance");
double v1 = table3.get(tx3, makeKey(1)).doubleValue("balance");
assertEquals(v0, v1);
CompletableFuture<Void> fut = table3.upsertAsync(tx3, makeValue(1, v0 + 10));
assertFalse(fut.isDone());
// Give some time to update lock queue TODO asch IGNITE-15928
Thread.sleep(300);
table.upsert(tx, makeValue(1, v0 + 20));
CompletableFuture<Tuple> fut2 = table2.getAsync(tx2, makeKey(1));
assertFalse(fut2.isDone());
tx.commit();
fut2.get();
tx2.rollback();
Exception err = assertThrows(Exception.class, () -> fut.get(5, TimeUnit.SECONDS));
assertTrue(err.getMessage().contains("Failed to acquire a lock"), err.getMessage());
}
Aggregations