Search in sources :

Example 21 with Tuple

use of org.apache.ignite.table.Tuple in project ignite-3 by apache.

the class SchemaValidationTest method bytesTypeMatch.

@Test
public void bytesTypeMatch() {
    SchemaDescriptor schema = new SchemaDescriptor(1, new Column[] { new Column("id", NativeTypes.INT64, false) }, new Column[] { new Column("valUnlimited", NativeTypes.BYTES, true), new Column("valLimited", NativeTypes.blobOf(2), true) });
    RecordView<Tuple> tbl = createTableImpl(schema).recordView();
    Tuple tuple = Tuple.create().set("id", 1L);
    tbl.insert(null, tuple.set("valUnlimited", null));
    tbl.insert(null, tuple.set("valLimited", null));
    tbl.insert(null, tuple.set("valUnlimited", new byte[2]));
    tbl.insert(null, tuple.set("valLimited", new byte[2]));
    tbl.insert(null, tuple.set("valUnlimited", new byte[3]));
    assertThrowsWithCause(InvalidTypeException.class, () -> tbl.insert(null, tuple.set("valLimited", new byte[3])));
}
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 22 with Tuple

use of org.apache.ignite.table.Tuple in project ignite-3 by apache.

the class SchemaValidationTest method columnNotExist.

@Test
public void columnNotExist() {
    SchemaDescriptor schema = new SchemaDescriptor(1, new Column[] { new Column("id", NativeTypes.INT64, false) }, new Column[] { new Column("val", NativeTypes.INT64, true) });
    RecordView<Tuple> recView = createTableImpl(schema).recordView();
    assertThrowsWithCause(SchemaMismatchException.class, () -> recView.insert(null, Tuple.create().set("id", 0L).set("invalidCol", 0)));
}
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 23 with Tuple

use of org.apache.ignite.table.Tuple in project ignite-3 by apache.

the class SchemaValidationTest method typeMismatch.

@Test
public void typeMismatch() {
    SchemaDescriptor schema = new SchemaDescriptor(1, new Column[] { new Column("id", NativeTypes.INT64, false) }, new Column[] { new Column("valString", NativeTypes.stringOf(3), true), new Column("valBytes", NativeTypes.blobOf(3), true) });
    RecordView<Tuple> tbl = createTableImpl(schema).recordView();
    // Check not-nullable column.
    assertThrowsWithCause(IllegalArgumentException.class, () -> tbl.insert(null, Tuple.create().set("id", null)));
    // Check length of the string column
    assertThrowsWithCause(InvalidTypeException.class, () -> tbl.insert(null, Tuple.create().set("id", 0L).set("valString", "qweqwe")));
    // Check length of the string column
    assertThrowsWithCause(InvalidTypeException.class, () -> tbl.insert(null, Tuple.create().set("id", 0L).set("valBytes", new byte[] { 0, 1, 2, 3 })));
}
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 24 with Tuple

use of org.apache.ignite.table.Tuple in project ignite-3 by apache.

the class TxAbstractTest method testDelete.

@Test
public void testDelete() throws TransactionException {
    Tuple key = makeKey(1);
    assertFalse(accounts.recordView().delete(null, key));
    assertNull(accounts.recordView().get(null, key));
    accounts.recordView().upsert(null, makeValue(1, 100.));
    igniteTransactions.runInTransaction(tx -> {
        assertNotNull(accounts.recordView().get(tx, key));
        assertTrue(accounts.recordView().delete(tx, key));
        assertNull(accounts.recordView().get(tx, key));
    });
    assertNull(accounts.recordView().get(null, key));
    accounts.recordView().upsert(null, makeValue(1, 100.));
    assertNotNull(accounts.recordView().get(null, key));
    Tuple key2 = makeKey(2);
    accounts.recordView().upsert(null, makeValue(2, 100.));
    assertThrows(RuntimeException.class, () -> igniteTransactions.runInTransaction((Consumer<Transaction>) tx -> {
        assertNotNull(accounts.recordView().get(tx, key2));
        assertTrue(accounts.recordView().delete(tx, key2));
        assertNull(accounts.recordView().get(tx, key2));
        throw new RuntimeException();
    }));
    assertNotNull(accounts.recordView().get(null, key2));
    assertTrue(accounts.recordView().delete(null, key2));
    assertNull(accounts.recordView().get(null, key2));
}
Also used : Consumer(java.util.function.Consumer) Tuple(org.apache.ignite.table.Tuple) Test(org.junit.jupiter.api.Test) IgniteAbstractTest(org.apache.ignite.internal.testframework.IgniteAbstractTest)

Example 25 with Tuple

use of org.apache.ignite.table.Tuple in project ignite-3 by apache.

the class TxAbstractTest method testGetAllConflict.

/**
 * Tests if a transaction is rolled back if one of the batch keys can't be locked.
 */
@Test
public void testGetAllConflict() throws Exception {
    accounts.recordView().upsertAll(null, List.of(makeValue(1, 100.), makeValue(2, 200.)));
    InternalTransaction tx = (InternalTransaction) igniteTransactions.begin();
    InternalTransaction tx2 = (InternalTransaction) igniteTransactions.begin();
    RecordView<Tuple> txAcc = accounts.recordView();
    RecordView<Tuple> txAcc2 = accounts.recordView();
    txAcc2.upsert(tx2, makeValue(1, 300.));
    txAcc.upsert(tx, makeValue(2, 400.));
    Exception err = assertThrows(Exception.class, () -> txAcc.getAll(tx, List.of(makeKey(2), makeKey(1))));
    assertTrue(err.getMessage().contains("Failed to acquire a lock"), err.getMessage());
    validateBalance(txAcc2.getAll(tx2, List.of(makeKey(2), makeKey(1))), 200., 300.);
    validateBalance(txAcc2.getAll(tx2, List.of(makeKey(1), makeKey(2))), 300., 200.);
    assertTrue(IgniteTestUtils.waitForCondition(() -> TxState.ABORTED == tx.state(), 5_000), tx.state().toString());
    tx2.commit();
    validateBalance(accounts.recordView().getAll(null, List.of(makeKey(2), makeKey(1))), 200., 300.);
}
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