Search in sources :

Example 46 with Tuple

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);
}
Also used : Random(java.util.Random) TupleMarshaller(org.apache.ignite.internal.schema.marshaller.TupleMarshaller) ByteBufferRow(org.apache.ignite.internal.schema.ByteBufferRow) TupleMarshallerImpl(org.apache.ignite.internal.schema.marshaller.TupleMarshallerImpl) Row(org.apache.ignite.internal.schema.row.Row) ByteBufferRow(org.apache.ignite.internal.schema.ByteBufferRow) Tuple(org.apache.ignite.table.Tuple) DummySchemaManagerImpl(org.apache.ignite.internal.table.impl.DummySchemaManagerImpl) Test(org.junit.jupiter.api.Test)

Example 47 with Tuple

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));
}
Also used : SchemaDescriptor(org.apache.ignite.internal.schema.SchemaDescriptor) Column(org.apache.ignite.internal.schema.Column) Tuple(org.apache.ignite.table.Tuple) Test(org.junit.jupiter.api.Test)

Example 48 with Tuple

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.);
}
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 49 with Tuple

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());
}
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 50 with Tuple

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

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