use of org.apache.ignite.internal.schema.Column 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]");
}
use of org.apache.ignite.internal.schema.Column 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());
}
use of org.apache.ignite.internal.schema.Column in project ignite-3 by apache.
the class KvMarshallerTest method classWithoutKeyField.
/**
* Try to create marshaller for class without field for key column.
*/
@ParameterizedTest
@MethodSource("marshallerFactoryProvider")
public void classWithoutKeyField(MarshallerFactory factory) {
Column[] keyCols = new Column[] { new Column("id".toUpperCase(), INT64, false), new Column("id2".toUpperCase(), INT64, false) };
Column[] valCols = new Column[] { new Column("primitiveDoubleCol", DOUBLE, false) };
SchemaDescriptor schema = new SchemaDescriptor(1, keyCols, valCols);
assertThrows(IllegalArgumentException.class, () -> factory.create(schema, TestKeyObject.class, TestObjectWithAllTypes.class), "No field found for column id2");
}
use of org.apache.ignite.internal.schema.Column in project ignite-3 by apache.
the class KvMarshallerTest method classWithNoDefaultConstructor.
@ParameterizedTest
@MethodSource("marshallerFactoryProvider")
public void classWithNoDefaultConstructor(MarshallerFactory factory) {
Column[] cols = new Column[] { new Column("primLongCol", INT64, false) };
SchemaDescriptor schema = new SchemaDescriptor(1, cols, cols);
final Object key = TestObjectWithNoDefaultConstructor.randomObject(rnd);
final Object val = TestObjectWithNoDefaultConstructor.randomObject(rnd);
assertThrows(IllegalArgumentException.class, () -> factory.create(schema, key.getClass(), val.getClass()));
}
use of org.apache.ignite.internal.schema.Column in project ignite-3 by apache.
the class KvMarshallerTest method narrowType.
@ParameterizedTest
@MethodSource("marshallerFactoryProvider")
public void narrowType(MarshallerFactory factory) throws MarshallerException {
Assumptions.assumeFalse(factory instanceof AsmMarshallerGenerator, "Generated marshaller doesn't support truncated values, yet.");
Column[] cols = new Column[] { new Column("primitiveIntCol".toUpperCase(), INT32, false), new Column("primitiveLongCol".toUpperCase(), INT64, false), new Column("primitiveFloatCol".toUpperCase(), FLOAT, false), new Column("primitiveDoubleCol".toUpperCase(), DOUBLE, false), new Column("stringCol".toUpperCase(), STRING, false), new Column("uuidCol".toUpperCase(), UUID, false) };
SchemaDescriptor schema = new SchemaDescriptor(1, cols, columnsAllTypes(true));
KvMarshaller<TestTruncatedObject, TestTruncatedObject> marshaller = factory.create(schema, TestTruncatedObject.class, TestTruncatedObject.class);
final TestTruncatedObject key = TestTruncatedObject.randomObject(rnd);
final TestTruncatedObject val = TestTruncatedObject.randomObject(rnd);
BinaryRow row = marshaller.marshal(key, val);
Object restoredVal = marshaller.unmarshalValue(new Row(schema, row));
Object restoredKey = marshaller.unmarshalKey(new Row(schema, row));
assertTrue(key.getClass().isInstance(restoredKey));
assertTrue(val.getClass().isInstance(restoredVal));
assertEquals(key, restoredKey);
assertEquals(val, restoredVal);
}
Aggregations