Search in sources :

Example 26 with TestObjectWithAllTypes

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

the class KvMarshallerTest method classWithWrongFieldType.

@ParameterizedTest
@MethodSource("marshallerFactoryProvider")
public void classWithWrongFieldType(MarshallerFactory factory) {
    Column[] keyCols = new Column[] { new Column("bitmaskCol".toUpperCase(), NativeTypes.bitmaskOf(42), false), new Column("shortCol".toUpperCase(), UUID, false) };
    Column[] valCols = new Column[] { new Column("bitmaskCol".toUpperCase(), NativeTypes.bitmaskOf(42), true), new Column("shortCol".toUpperCase(), UUID, true) };
    SchemaDescriptor schema = new SchemaDescriptor(1, keyCols, valCols);
    KvMarshaller<TestObjectWithAllTypes, TestObjectWithAllTypes> marshaller = factory.create(schema, TestObjectWithAllTypes.class, TestObjectWithAllTypes.class);
    final TestObjectWithAllTypes key = TestObjectWithAllTypes.randomObject(rnd);
    final TestObjectWithAllTypes val = TestObjectWithAllTypes.randomObject(rnd);
    assertThrows(MarshallerException.class, () -> marshaller.marshal(key, val), "Failed to write field [name=shortCol]");
}
Also used : SchemaDescriptor(org.apache.ignite.internal.schema.SchemaDescriptor) Column(org.apache.ignite.internal.schema.Column) TestObjectWithAllTypes(org.apache.ignite.internal.schema.testobjects.TestObjectWithAllTypes) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 27 with TestObjectWithAllTypes

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

the class KvMarshallerTest method wideType.

@ParameterizedTest
@MethodSource("marshallerFactoryProvider")
public void wideType(MarshallerFactory factory) throws MarshallerException {
    Column[] cols = new Column[] { new Column("primitiveLongCol".toUpperCase(), INT64, false), new Column("primitiveDoubleCol".toUpperCase(), DOUBLE, false), new Column("stringCol".toUpperCase(), STRING, false) };
    SchemaDescriptor schema = new SchemaDescriptor(1, cols, cols);
    KvMarshaller<TestObjectWithAllTypes, TestObjectWithAllTypes> marshaller = factory.create(schema, TestObjectWithAllTypes.class, TestObjectWithAllTypes.class);
    final TestObjectWithAllTypes key = TestObjectWithAllTypes.randomObject(rnd);
    final TestObjectWithAllTypes val = TestObjectWithAllTypes.randomObject(rnd);
    BinaryRow row = marshaller.marshal(key, val);
    TestObjectWithAllTypes restoredVal = marshaller.unmarshalValue(new Row(schema, row));
    TestObjectWithAllTypes restoredKey = marshaller.unmarshalKey(new Row(schema, row));
    assertTrue(key.getClass().isInstance(restoredKey));
    assertTrue(val.getClass().isInstance(restoredVal));
    TestObjectWithAllTypes expectedKey = new TestObjectWithAllTypes();
    expectedKey.setPrimitiveLongCol(key.getPrimitiveLongCol());
    expectedKey.setPrimitiveDoubleCol(key.getPrimitiveDoubleCol());
    expectedKey.setStringCol(key.getStringCol());
    TestObjectWithAllTypes expectedVal = new TestObjectWithAllTypes();
    expectedVal.setPrimitiveLongCol(val.getPrimitiveLongCol());
    expectedVal.setPrimitiveDoubleCol(val.getPrimitiveDoubleCol());
    expectedVal.setStringCol(val.getStringCol());
    assertEquals(expectedKey, restoredKey);
    assertEquals(expectedVal, restoredVal);
    // Check non-mapped fields has default values.
    assertNull(restoredKey.getUuidCol());
    assertNull(restoredVal.getUuidCol());
    assertEquals(0, restoredKey.getPrimitiveIntCol());
    assertEquals(0, restoredVal.getPrimitiveIntCol());
}
Also used : SchemaDescriptor(org.apache.ignite.internal.schema.SchemaDescriptor) Column(org.apache.ignite.internal.schema.Column) TestObjectWithAllTypes(org.apache.ignite.internal.schema.testobjects.TestObjectWithAllTypes) BinaryRow(org.apache.ignite.internal.schema.BinaryRow) Row(org.apache.ignite.internal.schema.row.Row) BinaryRow(org.apache.ignite.internal.schema.BinaryRow) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 28 with TestObjectWithAllTypes

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

the class ColumnBindingTest method fieldBinding.

/**
 * All native types field binding.
 *
 * @throws Exception If failed.
 */
@Test
public void fieldBinding() throws Exception {
    Column[] cols = new Column[] { new Column("primitiveByteCol", INT8, false), new Column("primitiveShortCol", INT16, false), new Column("primitiveIntCol", INT32, false), new Column("primitiveLongCol", INT64, false), new Column("primitiveFloatCol", FLOAT, false), new Column("primitiveDoubleCol", DOUBLE, false), new Column("byteCol", INT8, false), new Column("shortCol", INT16, false), new Column("intCol", INT32, false), new Column("longCol", INT64, false), new Column("floatCol", FLOAT, false), new Column("doubleCol", DOUBLE, false), new Column("dateCol", DATE, false), new Column("timeCol", time(), false), new Column("dateTimeCol", datetime(), false), new Column("timestampCol", timestamp(), false), new Column("uuidCol", UUID, false), new Column("bitmaskCol", NativeTypes.bitmaskOf(9), false), new Column("stringCol", STRING, false), new Column("bytesCol", BYTES, false), new Column("numberCol", NativeTypes.numberOf(21), false), new Column("decimalCol", NativeTypes.decimalOf(19, 3), false) };
    final Pair<RowAssembler, Row> mocks = createMocks();
    final RowAssembler rowAssembler = mocks.getFirst();
    final Row row = mocks.getSecond();
    final TestObjectWithAllTypes obj = TestObjectWithAllTypes.randomObject(rnd);
    for (int i = 0; i < cols.length; i++) {
        ColumnBinding.createFieldBinding(cols[i].copy(i), TestObjectWithAllTypes.class, cols[i].name(), null).write(rowAssembler, obj);
    }
    final TestObjectWithAllTypes restoredObj = new TestObjectWithAllTypes();
    for (int i = 0; i < cols.length; i++) {
        ColumnBinding.createFieldBinding(cols[i].copy(i), TestObjectWithAllTypes.class, cols[i].name(), null).read(row, restoredObj);
    }
    assertEquals(obj, restoredObj);
}
Also used : Column(org.apache.ignite.internal.schema.Column) TestObjectWithAllTypes(org.apache.ignite.internal.schema.testobjects.TestObjectWithAllTypes) RowAssembler(org.apache.ignite.internal.schema.row.RowAssembler) Row(org.apache.ignite.internal.schema.row.Row) Test(org.junit.jupiter.api.Test)

Example 29 with TestObjectWithAllTypes

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

the class RecordMarshallerTest method classWithWrongFieldType.

@ParameterizedTest
@MethodSource("marshallerFactoryProvider")
public void classWithWrongFieldType(MarshallerFactory factory) {
    SchemaDescriptor schema = new SchemaDescriptor(1, keyColumns(), new Column[] { new Column("bitmaskCol".toUpperCase(), NativeTypes.bitmaskOf(42), true), new Column("shortCol".toUpperCase(), UUID, true) });
    RecordMarshaller<TestObjectWithAllTypes> marshaller = factory.create(schema, TestObjectWithAllTypes.class);
    final TestObjectWithAllTypes rec = TestObjectWithAllTypes.randomObject(rnd);
    assertThrows(MarshallerException.class, () -> marshaller.marshal(rec), "Failed to write field [name=shortCol]");
}
Also used : SchemaDescriptor(org.apache.ignite.internal.schema.SchemaDescriptor) Column(org.apache.ignite.internal.schema.Column) TestObjectWithAllTypes(org.apache.ignite.internal.schema.testobjects.TestObjectWithAllTypes) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 30 with TestObjectWithAllTypes

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

the class RecordMarshallerTest method complexType.

@ParameterizedTest
@MethodSource("marshallerFactoryProvider")
public void complexType(MarshallerFactory factory) throws MarshallerException {
    SchemaDescriptor schema = new SchemaDescriptor(1, keyColumns(), valueColumnsAllTypes());
    final TestObjectWithAllTypes rec = TestObjectWithAllTypes.randomObject(rnd);
    RecordMarshaller<TestObjectWithAllTypes> marshaller = factory.create(schema, TestObjectWithAllTypes.class);
    BinaryRow row = marshaller.marshal(rec);
    TestObjectWithAllTypes restoredRec = marshaller.unmarshal(new Row(schema, row));
    assertTrue(rec.getClass().isInstance(restoredRec));
    assertEquals(rec, restoredRec);
}
Also used : SchemaDescriptor(org.apache.ignite.internal.schema.SchemaDescriptor) TestObjectWithAllTypes(org.apache.ignite.internal.schema.testobjects.TestObjectWithAllTypes) BinaryRow(org.apache.ignite.internal.schema.BinaryRow) Row(org.apache.ignite.internal.schema.row.Row) BinaryRow(org.apache.ignite.internal.schema.BinaryRow) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Aggregations

TestObjectWithAllTypes (org.apache.ignite.internal.schema.testobjects.TestObjectWithAllTypes)30 Test (org.junit.jupiter.api.Test)20 SchemaDescriptor (org.apache.ignite.internal.schema.SchemaDescriptor)10 Column (org.apache.ignite.internal.schema.Column)9 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)8 MethodSource (org.junit.jupiter.params.provider.MethodSource)8 Row (org.apache.ignite.internal.schema.row.Row)5 BinaryRow (org.apache.ignite.internal.schema.BinaryRow)4 Arrays (java.util.Arrays)2 Collections (java.util.Collections)2 List (java.util.List)2 Random (java.util.Random)2 Set (java.util.Set)2 Collectors (java.util.stream.Collectors)2 NativeTypeSpec (org.apache.ignite.internal.schema.NativeTypeSpec)2 NativeTypes (org.apache.ignite.internal.schema.NativeTypes)2 BYTES (org.apache.ignite.internal.schema.NativeTypes.BYTES)2 DATE (org.apache.ignite.internal.schema.NativeTypes.DATE)2 DOUBLE (org.apache.ignite.internal.schema.NativeTypes.DOUBLE)2 FLOAT (org.apache.ignite.internal.schema.NativeTypes.FLOAT)2