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