Search in sources :

Example 6 with BinaryRow

use of org.apache.ignite.internal.schema.BinaryRow 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));
}
Also used : SchemaDescriptor(org.apache.ignite.internal.schema.SchemaDescriptor) Column(org.apache.ignite.internal.schema.Column) BinaryRow(org.apache.ignite.internal.schema.BinaryRow) BinaryRow(org.apache.ignite.internal.schema.BinaryRow) Row(org.apache.ignite.internal.schema.row.Row) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 7 with BinaryRow

use of org.apache.ignite.internal.schema.BinaryRow 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);
}
Also used : SchemaDescriptor(org.apache.ignite.internal.schema.SchemaDescriptor) Column(org.apache.ignite.internal.schema.Column) BinaryRow(org.apache.ignite.internal.schema.BinaryRow) BinaryRow(org.apache.ignite.internal.schema.BinaryRow) Row(org.apache.ignite.internal.schema.row.Row) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 8 with BinaryRow

use of org.apache.ignite.internal.schema.BinaryRow 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);
}
Also used : SchemaDescriptor(org.apache.ignite.internal.schema.SchemaDescriptor) Column(org.apache.ignite.internal.schema.Column) BinaryRow(org.apache.ignite.internal.schema.BinaryRow) BinaryRow(org.apache.ignite.internal.schema.BinaryRow) Row(org.apache.ignite.internal.schema.row.Row) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 9 with BinaryRow

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

the class KvMarshallerTest method pojoWithFieldsOfAllTypes.

@ParameterizedTest
@MethodSource("marshallerFactoryProvider")
public void pojoWithFieldsOfAllTypes(MarshallerFactory factory) throws MarshallerException {
    SchemaDescriptor schema = new SchemaDescriptor(1, columnsAllTypes(false), columnsAllTypes(true));
    final TestObjectWithAllTypes key = TestObjectWithAllTypes.randomKey(rnd);
    final TestObjectWithAllTypes val = TestObjectWithAllTypes.randomObject(rnd);
    KvMarshaller<TestObjectWithAllTypes, TestObjectWithAllTypes> marshaller = factory.create(schema, TestObjectWithAllTypes.class, TestObjectWithAllTypes.class);
    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));
    assertEquals(key, restoredKey);
    assertEquals(val, restoredVal);
}
Also used : SchemaDescriptor(org.apache.ignite.internal.schema.SchemaDescriptor) 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 10 with BinaryRow

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

the class KvMarshallerTest method columnNameMapping.

@ParameterizedTest
@MethodSource("marshallerFactoryProvider")
public void columnNameMapping(MarshallerFactory factory) throws MarshallerException {
    Assumptions.assumeFalse(factory instanceof AsmMarshallerGenerator, "Generated marshaller doesn't support column mapping, yet.");
    SchemaDescriptor schema = new SchemaDescriptor(1, new Column[] { new Column("key".toUpperCase(), INT64, false) }, new Column[] { new Column("col1".toUpperCase(), INT64, false), new Column("col2".toUpperCase(), INT64, true), new Column("col3".toUpperCase(), STRING, false) });
    Mapper<TestKeyObject> keyMapper = Mapper.builder(TestKeyObject.class).map("id", "key").build();
    Mapper<TestObject> valMapper = Mapper.builder(TestObject.class).map("longCol", "col1").map("stringCol", "col3").build();
    KvMarshaller<TestKeyObject, TestObject> marshaller = factory.create(schema, keyMapper, valMapper);
    final TestKeyObject key = TestKeyObject.randomObject(rnd);
    final TestObject val = TestObject.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));
    val.longCol2 = null;
    assertEquals(key, restoredKey);
    assertEquals(val, restoredVal);
}
Also used : SchemaDescriptor(org.apache.ignite.internal.schema.SchemaDescriptor) Column(org.apache.ignite.internal.schema.Column) AsmMarshallerGenerator(org.apache.ignite.internal.schema.marshaller.asm.AsmMarshallerGenerator) 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)

Aggregations

BinaryRow (org.apache.ignite.internal.schema.BinaryRow)57 Row (org.apache.ignite.internal.schema.row.Row)34 SchemaDescriptor (org.apache.ignite.internal.schema.SchemaDescriptor)22 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)19 MethodSource (org.junit.jupiter.params.provider.MethodSource)19 Column (org.apache.ignite.internal.schema.Column)18 ArrayList (java.util.ArrayList)13 NotNull (org.jetbrains.annotations.NotNull)11 IgniteException (org.apache.ignite.lang.IgniteException)10 MarshallerException (org.apache.ignite.internal.schema.marshaller.MarshallerException)9 CountDownLatch (java.util.concurrent.CountDownLatch)6 Subscription (java.util.concurrent.Flow.Subscription)6 Test (org.junit.jupiter.api.Test)5 Map (java.util.Map)4 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)4 TestObjectWithAllTypes (org.apache.ignite.internal.schema.testobjects.TestObjectWithAllTypes)4 HashMap (java.util.HashMap)3 UUID (java.util.UUID)3 Flow (java.util.concurrent.Flow)3 AtomicReference (java.util.concurrent.atomic.AtomicReference)3