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