use of org.apache.ignite.internal.schema.BinaryRow 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.BinaryRow 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);
}
use of org.apache.ignite.internal.schema.BinaryRow in project ignite-3 by apache.
the class KvMarshallerTest method checkBasicType.
/**
* Generate random key-value pair of given types and check serialization and deserialization works fine.
*
* @param factory KvMarshaller factory.
* @param keyType Key type.
* @param valType Value type.
* @throws MarshallerException If (de)serialization failed.
*/
private void checkBasicType(MarshallerFactory factory, NativeType keyType, NativeType valType) throws MarshallerException {
final Object key = generateRandomValue(keyType);
final Object val = generateRandomValue(valType);
Column[] keyCols = new Column[] { new Column("key", keyType, false) };
Column[] valCols = new Column[] { new Column("val", valType, false) };
SchemaDescriptor schema = new SchemaDescriptor(1, keyCols, valCols);
KvMarshaller<Object, Object> marshaller = factory.create(schema, Mapper.of((Class<Object>) key.getClass(), "\"key\""), Mapper.of((Class<Object>) val.getClass(), "\"val\""));
BinaryRow row = marshaller.marshal(key, val);
Object key1 = marshaller.unmarshalKey(new Row(schema, row));
Object val1 = marshaller.unmarshalValue(new Row(schema, row));
assertTrue(key.getClass().isInstance(key1));
assertTrue(val.getClass().isInstance(val1));
compareObjects(keyType, key, key);
compareObjects(valType, val, val1);
}
use of org.apache.ignite.internal.schema.BinaryRow in project ignite-3 by apache.
the class RecordMarshallerTest method classLoader.
@ParameterizedTest
@MethodSource("marshallerFactoryProvider")
public void classLoader(MarshallerFactory factory) throws MarshallerException, IllegalAccessException {
final ClassLoader loader = Thread.currentThread().getContextClassLoader();
try {
Thread.currentThread().setContextClassLoader(new DynamicClassLoader(getClass().getClassLoader()));
Column[] keyCols = new Column[] { new Column("key".toUpperCase(), INT64, false) };
Column[] valCols = new Column[] { new Column("col0".toUpperCase(), INT64, false), new Column("col1".toUpperCase(), INT64, false), new Column("col2".toUpperCase(), INT64, false) };
SchemaDescriptor schema = new SchemaDescriptor(1, keyCols, valCols);
final Class<Object> recClass = (Class<Object>) createGeneratedObjectClass();
final ObjectFactory<Object> objFactory = new ObjectFactory<>(recClass);
RecordMarshaller<Object> marshaller = factory.create(schema, recClass);
Object rec = objFactory.create();
BinaryRow row = marshaller.marshal(rec);
Object restoredRec = marshaller.unmarshal(new Row(schema, row));
assertDeepEquals(recClass, rec, restoredRec);
} finally {
Thread.currentThread().setContextClassLoader(loader);
}
}
use of org.apache.ignite.internal.schema.BinaryRow 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);
}
Aggregations