Search in sources :

Example 26 with Tuple

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()));
}
Also used : InternalTransaction(org.apache.ignite.internal.tx.InternalTransaction) Tuple(org.apache.ignite.table.Tuple) Test(org.junit.jupiter.api.Test) IgniteAbstractTest(org.apache.ignite.internal.testframework.IgniteAbstractTest)

Example 27 with Tuple

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()));
}
Also used : InternalTransaction(org.apache.ignite.internal.tx.InternalTransaction) Tuple(org.apache.ignite.table.Tuple) Test(org.junit.jupiter.api.Test) IgniteAbstractTest(org.apache.ignite.internal.testframework.IgniteAbstractTest)

Example 28 with Tuple

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"));
}
Also used : InternalTransaction(org.apache.ignite.internal.tx.InternalTransaction) Tuple(org.apache.ignite.table.Tuple) TransactionException(org.apache.ignite.tx.TransactionException) IgniteException(org.apache.ignite.lang.IgniteException) Test(org.junit.jupiter.api.Test) IgniteAbstractTest(org.apache.ignite.internal.testframework.IgniteAbstractTest)

Example 29 with Tuple

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();
}
Also used : InternalTransaction(org.apache.ignite.internal.tx.InternalTransaction) Transaction(org.apache.ignite.tx.Transaction) Tuple(org.apache.ignite.table.Tuple) Test(org.junit.jupiter.api.Test) IgniteAbstractTest(org.apache.ignite.internal.testframework.IgniteAbstractTest)

Example 30 with Tuple

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());
}
Also used : InternalTransaction(org.apache.ignite.internal.tx.InternalTransaction) Tuple(org.apache.ignite.table.Tuple) TransactionException(org.apache.ignite.tx.TransactionException) IgniteException(org.apache.ignite.lang.IgniteException) Test(org.junit.jupiter.api.Test) IgniteAbstractTest(org.apache.ignite.internal.testframework.IgniteAbstractTest)

Aggregations

Tuple (org.apache.ignite.table.Tuple)130 Test (org.junit.jupiter.api.Test)101 SchemaDescriptor (org.apache.ignite.internal.schema.SchemaDescriptor)33 Table (org.apache.ignite.table.Table)27 Column (org.apache.ignite.internal.schema.Column)25 Row (org.apache.ignite.internal.schema.row.Row)21 IgniteAbstractTest (org.apache.ignite.internal.testframework.IgniteAbstractTest)19 Ignite (org.apache.ignite.Ignite)17 TupleMarshaller (org.apache.ignite.internal.schema.marshaller.TupleMarshaller)17 TupleMarshallerImpl (org.apache.ignite.internal.schema.marshaller.TupleMarshallerImpl)17 DummySchemaManagerImpl (org.apache.ignite.internal.table.impl.DummySchemaManagerImpl)17 InternalTransaction (org.apache.ignite.internal.tx.InternalTransaction)15 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)11 ByteBufferRow (org.apache.ignite.internal.schema.ByteBufferRow)10 TableDefinition (org.apache.ignite.schema.definition.TableDefinition)9 ArrayList (java.util.ArrayList)8 Disabled (org.junit.jupiter.api.Disabled)7 MethodSource (org.junit.jupiter.params.provider.MethodSource)7 BigDecimal (java.math.BigDecimal)6 Transaction (org.apache.ignite.tx.Transaction)6