use of org.apache.ignite.internal.schema.SchemaDescriptor in project ignite-3 by apache.
the class RecordMarshallerTest method privateClass.
@ParameterizedTest
@MethodSource("marshallerFactoryProvider")
public void privateClass(MarshallerFactory factory) throws MarshallerException {
SchemaDescriptor schema = new SchemaDescriptor(1, new Column[] { new Column("primLongCol".toUpperCase(), INT64, false) }, new Column[] { new Column("primIntCol".toUpperCase(), INT32, false) });
final ObjectFactory<PrivateTestObject> objFactory = new ObjectFactory<>(PrivateTestObject.class);
final RecordMarshaller<PrivateTestObject> marshaller = factory.create(schema, PrivateTestObject.class);
final PrivateTestObject rec = PrivateTestObject.randomObject(rnd);
BinaryRow row = marshaller.marshal(objFactory.create());
Object restoredRec = marshaller.unmarshal(new Row(schema, row));
assertTrue(rec.getClass().isInstance(restoredRec));
}
use of org.apache.ignite.internal.schema.SchemaDescriptor in project ignite-3 by apache.
the class RecordMarshallerTest method classWithPrivateConstructor.
@ParameterizedTest
@MethodSource("marshallerFactoryProvider")
public void classWithPrivateConstructor(MarshallerFactory factory) throws MarshallerException, IllegalAccessException {
SchemaDescriptor schema = new SchemaDescriptor(1, new Column[] { new Column("primLongCol".toUpperCase(), INT64, false) }, new Column[] { new Column("primIntCol".toUpperCase(), INT32, false) });
RecordMarshaller<TestObjectWithPrivateConstructor> marshaller = factory.create(schema, TestObjectWithPrivateConstructor.class);
final TestObjectWithPrivateConstructor rec = TestObjectWithPrivateConstructor.randomObject(rnd);
BinaryRow row = marshaller.marshal(rec);
TestObjectWithPrivateConstructor restoredRec = marshaller.unmarshal(new Row(schema, row));
assertDeepEquals(TestObjectWithPrivateConstructor.class, rec, restoredRec);
}
use of org.apache.ignite.internal.schema.SchemaDescriptor in project ignite-3 by apache.
the class RecordMarshallerValidationsTest method testReadOnly.
/**
* Check ability to read into truncated class, but not write it.
*/
@ParameterizedTest
@MethodSource("marshallerFactoryProvider")
public void testReadOnly(MarshallerFactory factory) throws MarshallerException {
Column[] valCols = new Column[] { new Column("fbyte1".toUpperCase(), INT32, false), new Column("fbyte2".toUpperCase(), INT32, false) };
SchemaDescriptor schema = new SchemaDescriptor(1, KEY_COLS, valCols);
final FullRecClass rec = new FullRecClass(1, 1, 2);
RecordMarshaller<FullRecClass> marshallerFull = factory.create(schema, FullRecClass.class);
BinaryRow row = marshallerFull.marshal(rec);
RecordMarshaller<TruncatedRecClass> marshaller = factory.create(schema, TruncatedRecClass.class);
TruncatedRecClass restoredRec = marshaller.unmarshal(new Row(schema, row));
assertEquals(rec.id, restoredRec.id);
assertEquals(rec.fbyte1, restoredRec.fbyte1);
assertThrows(MarshallerException.class, () -> marshaller.marshal(restoredRec));
}
use of org.apache.ignite.internal.schema.SchemaDescriptor in project ignite-3 by apache.
the class RecordMarshallerValidationsTest method testColsWithNullable.
/**
* Check nullable flag is taken into account if there is no field in specified class to marshall from.
*/
@ParameterizedTest
@MethodSource("marshallerFactoryProvider")
public void testColsWithNullable(MarshallerFactory factory) throws MarshallerException {
Column[] valCols = new Column[] { new Column("fbyte1".toUpperCase(), INT32, false), new Column("fbyte2".toUpperCase(), INT32, true) };
SchemaDescriptor schema = new SchemaDescriptor(1, KEY_COLS, valCols);
final TruncatedRecClass rec = new TruncatedRecClass(1, 1);
RecordMarshaller<TruncatedRecClass> marshaller = factory.create(schema, TruncatedRecClass.class);
BinaryRow row = marshaller.marshal(rec);
TruncatedRecClass restoredRec = marshaller.unmarshal(new Row(schema, row));
assertTrue(rec.getClass().isInstance(restoredRec));
assertEquals(rec, restoredRec);
}
use of org.apache.ignite.internal.schema.SchemaDescriptor in project ignite-3 by apache.
the class RecordMarshallerValidationsTest method testColsWithDefaultValue.
/**
* Check default value is taken into account if there is no field in specified class to marshall from.
*/
@ParameterizedTest
@MethodSource("marshallerFactoryProvider")
public void testColsWithDefaultValue(MarshallerFactory factory) throws MarshallerException {
Column[] valCols = new Column[] { new Column("fbyte1".toUpperCase(), INT32, false), new Column("fbyte2".toUpperCase(), INT32, false, () -> 0x42) };
SchemaDescriptor schema = new SchemaDescriptor(1, KEY_COLS, valCols);
final TruncatedRecClass rec = new TruncatedRecClass(1, 1);
RecordMarshaller<TruncatedRecClass> marshaller = factory.create(schema, TruncatedRecClass.class);
BinaryRow row = marshaller.marshal(rec);
TruncatedRecClass restoredRec = marshaller.unmarshal(new Row(schema, row));
assertTrue(rec.getClass().isInstance(restoredRec));
assertEquals(rec, restoredRec);
}
Aggregations