use of org.apache.ignite.table.Tuple in project ignite-3 by apache.
the class MutableRowTupleAdapterTest method testSerialization.
@Test
public void testSerialization() throws Exception {
Random rnd = new Random();
Tuple tup1 = Tuple.create().set("valByteCol", (byte) 1).set("valShortCol", (short) 2).set("valIntCol", 3).set("valLongCol", 4L).set("valFloatCol", 0.055f).set("valDoubleCol", 0.066d).set("keyUuidCol", UUID.randomUUID()).set("valDateCol", LocalDate.now()).set("valDateTimeCol", truncatedLocalDateTimeNow()).set("valTimeCol", truncatedLocalTimeNow()).set("valTimeStampCol", truncatedInstantNow()).set("valBitmask1Col", randomBitSet(rnd, 12)).set("valBytesCol", IgniteTestUtils.randomBytes(rnd, 13)).set("valStringCol", IgniteTestUtils.randomString(rnd, 14)).set("valNumberCol", BigInteger.valueOf(rnd.nextLong())).set("valDecimalCol", BigDecimal.valueOf(rnd.nextLong(), 5));
TupleMarshaller marshaller = new TupleMarshallerImpl(new DummySchemaManagerImpl(fullSchema));
Row row = new Row(fullSchema, new ByteBufferRow(marshaller.marshal(tup1).bytes()));
Tuple tup2 = deserializeTuple(serializeTuple(TableRow.tuple(row)));
assertEquals(tup1, tup2);
assertEquals(tup2, tup1);
}
use of org.apache.ignite.table.Tuple in project ignite-3 by apache.
the class RecordBinaryViewOperationsTest method insert.
// TODO: IGNITE-16468 Extend test coverage.
@Test
public void insert() {
SchemaDescriptor schema = new SchemaDescriptor(1, new Column[] { new Column("id".toUpperCase(), NativeTypes.INT64, false) }, new Column[] { new Column("val".toUpperCase(), NativeTypes.INT64, false) });
RecordView<Tuple> tbl = createTableImpl(schema).recordView();
final Tuple tuple = Tuple.create().set("id", 1L).set("val", 11L);
final Tuple newTuple = Tuple.create().set("id", 1L).set("val", 22L);
final Tuple nonExistedTuple = Tuple.create().set("id", 2L);
assertNull(tbl.get(null, Tuple.create().set("id", 1L)));
// Insert new tuple.
assertTrue(tbl.insert(null, tuple));
assertEqualsRows(schema, tuple, tbl.get(null, Tuple.create().set("id", 1L)));
// Ignore insert operation for exited row.
assertFalse(tbl.insert(null, newTuple));
assertEqualsRows(schema, tuple, tbl.get(null, Tuple.create().set("id", 1L)));
assertNull(tbl.get(null, nonExistedTuple));
}
use of org.apache.ignite.table.Tuple 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.);
}
use of org.apache.ignite.table.Tuple in project ignite-3 by apache.
the class TxAbstractTest method testReorder2.
@Test
public void testReorder2() 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");
table.upsertAsync(tx, makeValue(1, v0 + 10));
CompletableFuture<Tuple> fut = table2.getAsync(tx2, makeKey(1));
assertFalse(fut.isDone());
CompletableFuture<Tuple> fut2 = table3.getAsync(tx3, makeKey(1));
assertFalse(fut2.isDone());
}
use of org.apache.ignite.table.Tuple in project ignite-3 by apache.
the class TxAbstractTest method testLockOrdering.
@Test
public void testLockOrdering() throws InterruptedException {
accounts.recordView().upsert(null, makeValue(1, 50.));
InternalTransaction tx = (InternalTransaction) igniteTransactions.begin();
InternalTransaction tx2 = (InternalTransaction) igniteTransactions.begin();
InternalTransaction tx3 = (InternalTransaction) igniteTransactions.begin();
InternalTransaction tx4 = (InternalTransaction) igniteTransactions.begin();
assertTrue(tx2.timestamp().compareTo(tx.timestamp()) > 0);
assertTrue(tx3.timestamp().compareTo(tx2.timestamp()) > 0);
assertTrue(tx4.timestamp().compareTo(tx3.timestamp()) > 0);
RecordView<Tuple> acc0 = accounts.recordView();
RecordView<Tuple> acc2 = accounts.recordView();
RecordView<Tuple> acc3 = accounts.recordView();
RecordView<Tuple> acc4 = accounts.recordView();
acc0.upsert(tx, makeValue(1, 100.));
CompletableFuture<Void> fut = acc3.upsertAsync(tx3, makeValue(1, 300.));
Thread.sleep(100);
assertFalse(fut.isDone());
CompletableFuture<Void> fut2 = acc4.upsertAsync(tx3, makeValue(1, 400.));
Thread.sleep(100);
assertFalse(fut2.isDone());
CompletableFuture<Void> fut3 = acc2.upsertAsync(tx2, makeValue(1, 200.));
assertFalse(fut3.isDone());
}
Aggregations