Search in sources :

Example 1 with ObjectFactory

use of org.apache.ignite.internal.util.ObjectFactory 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));
}
Also used : SchemaDescriptor(org.apache.ignite.internal.schema.SchemaDescriptor) ObjectFactory(org.apache.ignite.internal.util.ObjectFactory) 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 2 with ObjectFactory

use of org.apache.ignite.internal.util.ObjectFactory in project ignite-3 by apache.

the class KvMarshallerTest method privateClass.

@ParameterizedTest
@MethodSource("marshallerFactoryProvider")
public void privateClass(MarshallerFactory factory) throws MarshallerException {
    Column[] cols = new Column[] { new Column("primLongCol".toUpperCase(), INT64, false) };
    SchemaDescriptor schema = new SchemaDescriptor(1, cols, cols);
    final ObjectFactory<PrivateTestObject> objFactory = new ObjectFactory<>(PrivateTestObject.class);
    final KvMarshaller<PrivateTestObject, PrivateTestObject> marshaller = factory.create(schema, PrivateTestObject.class, PrivateTestObject.class);
    final PrivateTestObject key = PrivateTestObject.randomObject(rnd);
    final PrivateTestObject val = PrivateTestObject.randomObject(rnd);
    BinaryRow row = marshaller.marshal(key, objFactory.create());
    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));
}
Also used : SchemaDescriptor(org.apache.ignite.internal.schema.SchemaDescriptor) ObjectFactory(org.apache.ignite.internal.util.ObjectFactory) 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 ObjectFactory

use of org.apache.ignite.internal.util.ObjectFactory in project ignite-3 by apache.

the class KvMarshallerTest method classLoader.

@ParameterizedTest
@MethodSource("marshallerFactoryProvider")
public void classLoader(MarshallerFactory factory) throws MarshallerException {
    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<?> valClass = createGeneratedObjectClass();
        final ObjectFactory<?> objFactory = new ObjectFactory<>(valClass);
        KvMarshaller<Long, Object> marshaller = factory.create(schema, Long.class, (Class<Object>) valClass);
        final Long key = rnd.nextLong();
        BinaryRow row = marshaller.marshal(key, objFactory.create());
        Long key1 = marshaller.unmarshalKey(new Row(schema, row));
        Object val1 = marshaller.unmarshalValue(new Row(schema, row));
        assertTrue(valClass.isInstance(val1));
        assertEquals(key, key1);
    } finally {
        Thread.currentThread().setContextClassLoader(loader);
    }
}
Also used : DynamicClassLoader(com.facebook.presto.bytecode.DynamicClassLoader) SchemaDescriptor(org.apache.ignite.internal.schema.SchemaDescriptor) BinaryRow(org.apache.ignite.internal.schema.BinaryRow) ObjectFactory(org.apache.ignite.internal.util.ObjectFactory) Column(org.apache.ignite.internal.schema.Column) DynamicClassLoader(com.facebook.presto.bytecode.DynamicClassLoader) 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 ObjectFactory

use of org.apache.ignite.internal.util.ObjectFactory 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);
    }
}
Also used : DynamicClassLoader(com.facebook.presto.bytecode.DynamicClassLoader) SchemaDescriptor(org.apache.ignite.internal.schema.SchemaDescriptor) BinaryRow(org.apache.ignite.internal.schema.BinaryRow) ObjectFactory(org.apache.ignite.internal.util.ObjectFactory) Column(org.apache.ignite.internal.schema.Column) DynamicClassLoader(com.facebook.presto.bytecode.DynamicClassLoader) 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

BinaryRow (org.apache.ignite.internal.schema.BinaryRow)4 Column (org.apache.ignite.internal.schema.Column)4 SchemaDescriptor (org.apache.ignite.internal.schema.SchemaDescriptor)4 Row (org.apache.ignite.internal.schema.row.Row)4 ObjectFactory (org.apache.ignite.internal.util.ObjectFactory)4 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)4 MethodSource (org.junit.jupiter.params.provider.MethodSource)4 DynamicClassLoader (com.facebook.presto.bytecode.DynamicClassLoader)2