Search in sources :

Example 1 with TestSimpleObject

use of org.apache.ignite.internal.schema.testobjects.TestSimpleObject in project ignite-3 by apache.

the class ColumnBindingTest method nullableFieldsBinding.

/**
 * Nullable fields binding.
 *
 * @throws Exception If failed.
 */
@Test
public void nullableFieldsBinding() throws Exception {
    Column[] cols = new Column[] { new Column("intCol", INT32, true), new Column("longCol", INT64, true), new Column("stringCol", STRING, true), new Column("bytesCol", BYTES, true) };
    final Pair<RowAssembler, Row> mocks = createMocks();
    final RowAssembler rowAssembler = mocks.getFirst();
    final Row row = mocks.getSecond();
    final TestSimpleObject obj = TestSimpleObject.randomObject(rnd);
    for (int i = 0; i < cols.length; i++) {
        ColumnBinding.createFieldBinding(cols[i].copy(i), TestSimpleObject.class, cols[i].name(), null).write(rowAssembler, obj);
    }
    final TestSimpleObject restoredObj = new TestSimpleObject();
    for (int i = 0; i < cols.length; i++) {
        ColumnBinding.createFieldBinding(cols[i].copy(i), TestSimpleObject.class, cols[i].name(), null).read(row, restoredObj);
    }
    assertEquals(obj, restoredObj);
}
Also used : TestSimpleObject(org.apache.ignite.internal.schema.testobjects.TestSimpleObject) Column(org.apache.ignite.internal.schema.Column) RowAssembler(org.apache.ignite.internal.schema.row.RowAssembler) Row(org.apache.ignite.internal.schema.row.Row) Test(org.junit.jupiter.api.Test)

Example 2 with TestSimpleObject

use of org.apache.ignite.internal.schema.testobjects.TestSimpleObject in project ignite-3 by apache.

the class ColumnBindingTest method identityBindingWithConverter.

/**
 * Identity binding with converter.
 *
 * @throws Exception If failed.
 */
@Test
public void identityBindingWithConverter() throws Exception {
    final ColumnBinding binding = ColumnBinding.createIdentityBinding(new Column("val", BYTES, true).copy(0), TestSimpleObject.class, new SerializingConverter());
    final Pair<RowAssembler, Row> mocks = createMocks();
    final RowAssembler rowAssembler = mocks.getFirst();
    final Row row = mocks.getSecond();
    final TestSimpleObject obj = TestSimpleObject.randomObject(rnd);
    binding.write(rowAssembler, obj);
    Object restoredObj = binding.columnValue(row);
    assertEquals(obj, restoredObj);
}
Also used : TestSimpleObject(org.apache.ignite.internal.schema.testobjects.TestSimpleObject) Column(org.apache.ignite.internal.schema.Column) RowAssembler(org.apache.ignite.internal.schema.row.RowAssembler) TestSimpleObject(org.apache.ignite.internal.schema.testobjects.TestSimpleObject) Row(org.apache.ignite.internal.schema.row.Row) Test(org.junit.jupiter.api.Test)

Aggregations

Column (org.apache.ignite.internal.schema.Column)2 Row (org.apache.ignite.internal.schema.row.Row)2 RowAssembler (org.apache.ignite.internal.schema.row.RowAssembler)2 TestSimpleObject (org.apache.ignite.internal.schema.testobjects.TestSimpleObject)2 Test (org.junit.jupiter.api.Test)2