Search in sources :

Example 1 with SchemaDescriptor

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

the class RecordMarshallerTest method classWithNoDefaultConstructor.

@ParameterizedTest
@MethodSource("marshallerFactoryProvider")
public void classWithNoDefaultConstructor(MarshallerFactory factory) {
    SchemaDescriptor schema = new SchemaDescriptor(1, new Column[] { new Column("primLongCol".toUpperCase(), INT64, false) }, new Column[] { new Column("primIntCol".toUpperCase(), INT32, false) });
    final Object rec = TestObjectWithNoDefaultConstructor.randomObject(rnd);
    assertThrows(IllegalArgumentException.class, () -> factory.create(schema, rec.getClass()));
}
Also used : SchemaDescriptor(org.apache.ignite.internal.schema.SchemaDescriptor) Column(org.apache.ignite.internal.schema.Column) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 2 with SchemaDescriptor

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

the class RecordMarshallerTest method mapping.

@ParameterizedTest
@MethodSource("marshallerFactoryProvider")
public void mapping(MarshallerFactory factory) throws MarshallerException {
    SchemaDescriptor schema = new SchemaDescriptor(1, new Column[] { new Column("key".toUpperCase(), INT64, false) }, new Column[] { new Column("col1".toUpperCase(), INT32, false), new Column("col2".toUpperCase(), INT64, true), new Column("col3".toUpperCase(), STRING, false) });
    Mapper<TestObject> mapper = Mapper.builder(TestObject.class).map("id", "key").map("intCol", "col1").map("stringCol", "col3").build();
    RecordMarshaller<TestObject> marshaller = factory.create(schema, mapper);
    final TestObject rec = TestObject.randomObject(rnd);
    BinaryRow row = marshaller.marshal(rec);
    Object restoredRec = marshaller.unmarshal(new Row(schema, row));
    assertTrue(rec.getClass().isInstance(restoredRec));
    // Nullify non-mapped field.
    rec.longCol2 = null;
    assertEquals(rec, restoredRec);
}
Also used : SchemaDescriptor(org.apache.ignite.internal.schema.SchemaDescriptor) Column(org.apache.ignite.internal.schema.Column) 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 3 with SchemaDescriptor

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

the class RecordMarshallerTest method widerType.

@ParameterizedTest
@MethodSource("marshallerFactoryProvider")
public void widerType(MarshallerFactory factory) throws MarshallerException {
    SchemaDescriptor schema = new SchemaDescriptor(1, keyColumns(), new Column[] { new Column("primitiveDoubleCol".toUpperCase(), DOUBLE, false), new Column("stringCol".toUpperCase(), STRING, true) });
    RecordMarshaller<TestObjectWithAllTypes> marshaller = factory.create(schema, TestObjectWithAllTypes.class);
    final TestObjectWithAllTypes rec = TestObjectWithAllTypes.randomObject(rnd);
    BinaryRow row = marshaller.marshal(rec);
    TestObjectWithAllTypes restoredRec = marshaller.unmarshal(new Row(schema, row));
    assertTrue(rec.getClass().isInstance(restoredRec));
    TestObjectWithAllTypes expectedRec = new TestObjectWithAllTypes();
    expectedRec.setPrimitiveLongCol(rec.getPrimitiveLongCol());
    expectedRec.setIntCol(rec.getIntCol());
    expectedRec.setPrimitiveDoubleCol(rec.getPrimitiveDoubleCol());
    expectedRec.setStringCol(rec.getStringCol());
    assertEquals(expectedRec, restoredRec);
    // Check non-mapped fields has default values.
    assertNull(restoredRec.getUuidCol());
    assertEquals(0, restoredRec.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 4 with SchemaDescriptor

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

the class RecordMarshallerTest method truncatedType.

@ParameterizedTest
@MethodSource("marshallerFactoryProvider")
public void truncatedType(MarshallerFactory factory) throws MarshallerException {
    SchemaDescriptor schema = new SchemaDescriptor(1, keyColumns(), valueColumnsAllTypes());
    RecordMarshaller<TestTruncatedObject> marshaller = factory.create(schema, TestTruncatedObject.class);
    final TestTruncatedObject rec = TestTruncatedObject.randomObject(rnd);
    BinaryRow row = marshaller.marshal(rec);
    Object restoredRec = marshaller.unmarshal(new Row(schema, row));
    assertTrue(rec.getClass().isInstance(restoredRec));
    assertEquals(rec, restoredRec);
}
Also used : SchemaDescriptor(org.apache.ignite.internal.schema.SchemaDescriptor) 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 5 with SchemaDescriptor

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

the class RecordMarshallerTest method classWithIncorrectBitmaskSize.

@ParameterizedTest
@MethodSource("marshallerFactoryProvider")
public void classWithIncorrectBitmaskSize(MarshallerFactory factory) {
    SchemaDescriptor schema = new SchemaDescriptor(1, keyColumns(), new Column[] { new Column("primitiveLongCol".toUpperCase(), INT64, false), new Column("bitmaskCol".toUpperCase(), NativeTypes.bitmaskOf(9), 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=bitmaskCol]");
}
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)

Aggregations

SchemaDescriptor (org.apache.ignite.internal.schema.SchemaDescriptor)105 Column (org.apache.ignite.internal.schema.Column)78 Test (org.junit.jupiter.api.Test)48 Tuple (org.apache.ignite.table.Tuple)35 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)34 Row (org.apache.ignite.internal.schema.row.Row)32 MethodSource (org.junit.jupiter.params.provider.MethodSource)30 BinaryRow (org.apache.ignite.internal.schema.BinaryRow)22 TestObjectWithAllTypes (org.apache.ignite.internal.schema.testobjects.TestObjectWithAllTypes)11 DummySchemaManagerImpl (org.apache.ignite.internal.table.impl.DummySchemaManagerImpl)11 TupleMarshaller (org.apache.ignite.internal.schema.marshaller.TupleMarshaller)10 TupleMarshallerImpl (org.apache.ignite.internal.schema.marshaller.TupleMarshallerImpl)10 List (java.util.List)9 ArrayList (java.util.ArrayList)8 NotNull (org.jetbrains.annotations.NotNull)8 UUID (java.util.UUID)7 Collectors (java.util.stream.Collectors)7 TableImpl (org.apache.ignite.internal.table.TableImpl)7 Random (java.util.Random)6 Map (java.util.Map)5