Search in sources :

Example 21 with InternalTransaction

use of org.apache.ignite.internal.tx.InternalTransaction in project ignite-3 by apache.

the class TxAbstractTest method testCrossTableKeyValueView.

@Test
public void testCrossTableKeyValueView() throws TransactionException {
    customers.recordView().upsert(null, makeValue(1L, "test"));
    accounts.recordView().upsert(null, makeValue(1L, 100.));
    assertEquals("test", customers.recordView().get(null, makeKey(1)).stringValue("name"));
    assertEquals(100., accounts.recordView().get(null, makeKey(1)).doubleValue("balance"));
    InternalTransaction tx = (InternalTransaction) igniteTransactions.begin();
    InternalTransaction tx2 = (InternalTransaction) igniteTransactions.begin();
    var txCust = customers.keyValueView();
    var txAcc = accounts.keyValueView();
    txCust.put(tx, makeKey(1), makeValue("test2"));
    txAcc.put(tx, makeKey(1), makeValue(200.));
    Tuple txValCust = txCust.get(tx, makeKey(1));
    assertEquals("test2", txValCust.stringValue("name"));
    txValCust.set("accountNumber", 2L);
    txValCust.set("name", "test3");
    Tuple txValAcc = txAcc.get(tx, makeKey(1));
    assertEquals(200., txValAcc.doubleValue("balance"));
    txValAcc.set("accountNumber", 2L);
    txValAcc.set("balance", 300.);
    tx.commit();
    tx2.commit();
    assertEquals("test2", customers.recordView().get(null, makeKey(1)).stringValue("name"));
    assertEquals(200., accounts.recordView().get(null, makeKey(1)).doubleValue("balance"));
    assertTrue(lockManager(accounts).isEmpty());
}
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 22 with InternalTransaction

use of org.apache.ignite.internal.tx.InternalTransaction in project ignite-3 by apache.

the class TxAbstractTest method testRollbackUpgradedLock.

@Test
@Disabled("https://issues.apache.org/jira/browse/IGNITE-15939")
public void testRollbackUpgradedLock() throws Exception {
    // TODO asch IGNITE-15939
    accounts.recordView().upsert(null, makeValue(1, 100.));
    InternalTransaction tx = (InternalTransaction) igniteTransactions.begin();
    InternalTransaction tx2 = (InternalTransaction) igniteTransactions.begin();
    var table = accounts.recordView();
    var table2 = accounts.recordView();
    double v0 = table.get(tx, makeKey(1)).doubleValue("balance");
    double v1 = table2.get(tx2, makeKey(1)).doubleValue("balance");
    assertEquals(v0, v1);
    // Try to upgrade a lock.
    table2.upsertAsync(tx2, makeValue(1, v0 + 10));
    // Give some time to update lock queue TODO asch IGNITE-15928
    Thread.sleep(300);
    tx2.rollback();
}
Also used : InternalTransaction(org.apache.ignite.internal.tx.InternalTransaction) Test(org.junit.jupiter.api.Test) IgniteAbstractTest(org.apache.ignite.internal.testframework.IgniteAbstractTest) Disabled(org.junit.jupiter.api.Disabled)

Example 23 with InternalTransaction

use of org.apache.ignite.internal.tx.InternalTransaction in project ignite-3 by apache.

the class TxAbstractTest method testCrossTable.

@Test
public void testCrossTable() throws TransactionException {
    customers.recordView().upsert(null, makeValue(1, "test"));
    accounts.recordView().upsert(null, makeValue(1, 100.));
    assertEquals("test", customers.recordView().get(null, makeKey(1)).stringValue("name"));
    assertEquals(100., accounts.recordView().get(null, makeKey(1)).doubleValue("balance"));
    InternalTransaction tx = (InternalTransaction) igniteTransactions.begin();
    var txCust = customers.recordView();
    var txAcc = accounts.recordView();
    txCust.upsert(tx, makeValue(1, "test2"));
    txAcc.upsert(tx, makeValue(1, 200.));
    Tuple txValCust = txCust.get(tx, makeKey(1));
    assertEquals("test2", txValCust.stringValue("name"));
    txValCust.set("accountNumber", 2L);
    txValCust.set("name", "test3");
    Tuple txValAcc = txAcc.get(tx, makeKey(1));
    assertEquals(200., txValAcc.doubleValue("balance"));
    txValAcc.set("accountNumber", 2L);
    txValAcc.set("balance", 300.);
    tx.commit();
    assertEquals("test2", customers.recordView().get(null, makeKey(1)).stringValue("name"));
    assertEquals(200., accounts.recordView().get(null, makeKey(1)).doubleValue("balance"));
    assertTrue(lockManager(accounts).isEmpty());
    assertTrue(lockManager(customers).isEmpty());
}
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 24 with InternalTransaction

use of org.apache.ignite.internal.tx.InternalTransaction in project ignite-3 by apache.

the class KeyValueBinaryViewImpl method getAllAsync.

/**
 * {@inheritDoc}
 */
@Override
@NotNull
public CompletableFuture<Map<Tuple, Tuple>> getAllAsync(@Nullable Transaction tx, @NotNull Collection<Tuple> keys) {
    Objects.requireNonNull(keys);
    List<BinaryRow> keyRows = new ArrayList<>(keys.size());
    for (Tuple keyRec : keys) {
        final Row keyRow = marshal(keyRec, null);
        keyRows.add(keyRow);
    }
    return tbl.getAll(keyRows, (InternalTransaction) tx).thenApply(ts -> ts.stream().filter(Objects::nonNull).filter(BinaryRow::hasValue).map(this::wrap).collect(Collectors.toMap(TableRow::keyTuple, TableRow::valueTuple)));
}
Also used : ArrayList(java.util.ArrayList) Objects(java.util.Objects) BinaryRow(org.apache.ignite.internal.schema.BinaryRow) BinaryRow(org.apache.ignite.internal.schema.BinaryRow) Row(org.apache.ignite.internal.schema.row.Row) InternalTransaction(org.apache.ignite.internal.tx.InternalTransaction) Tuple(org.apache.ignite.table.Tuple) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

InternalTransaction (org.apache.ignite.internal.tx.InternalTransaction)24 IgniteAbstractTest (org.apache.ignite.internal.testframework.IgniteAbstractTest)14 Test (org.junit.jupiter.api.Test)14 Tuple (org.apache.ignite.table.Tuple)12 BinaryRow (org.apache.ignite.internal.schema.BinaryRow)8 NotNull (org.jetbrains.annotations.NotNull)8 Row (org.apache.ignite.internal.schema.row.Row)6 ArrayList (java.util.ArrayList)4 IgniteException (org.apache.ignite.lang.IgniteException)4 TransactionException (org.apache.ignite.tx.TransactionException)4 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)3 Int2ObjectMap (it.unimi.dsi.fastutil.ints.Int2ObjectMap)2 Int2ObjectOpenHashMap (it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap)2 Collection (java.util.Collection)2 Comparator (java.util.Comparator)2 List (java.util.List)2 Map (java.util.Map)2 UUID (java.util.UUID)2 CompletableFuture (java.util.concurrent.CompletableFuture)2 CompletableFuture.completedFuture (java.util.concurrent.CompletableFuture.completedFuture)2