Search in sources :

Example 1 with TestObjectWithAllTypes

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

the class RecordMarshallerTest method widerType.

@ParameterizedTest
@MethodSource("marshallerFactoryProvider")
public void widerType(MarshallerFactory factory) throws MarshallerException {
    SchemaDescriptor schema = new SchemaDescriptor(1, keyColumns(), new Column[] { new Column("primitiveDoubleCol".toUpperCase(), DOUBLE, false), new Column("stringCol".toUpperCase(), STRING, true) });
    RecordMarshaller<TestObjectWithAllTypes> marshaller = factory.create(schema, TestObjectWithAllTypes.class);
    final TestObjectWithAllTypes rec = TestObjectWithAllTypes.randomObject(rnd);
    BinaryRow row = marshaller.marshal(rec);
    TestObjectWithAllTypes restoredRec = marshaller.unmarshal(new Row(schema, row));
    assertTrue(rec.getClass().isInstance(restoredRec));
    TestObjectWithAllTypes expectedRec = new TestObjectWithAllTypes();
    expectedRec.setPrimitiveLongCol(rec.getPrimitiveLongCol());
    expectedRec.setIntCol(rec.getIntCol());
    expectedRec.setPrimitiveDoubleCol(rec.getPrimitiveDoubleCol());
    expectedRec.setStringCol(rec.getStringCol());
    assertEquals(expectedRec, restoredRec);
    // Check non-mapped fields has default values.
    assertNull(restoredRec.getUuidCol());
    assertEquals(0, restoredRec.getPrimitiveIntCol());
}
Also used : SchemaDescriptor(org.apache.ignite.internal.schema.SchemaDescriptor) Column(org.apache.ignite.internal.schema.Column) 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 2 with TestObjectWithAllTypes

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

the class RecordMarshallerTest method classWithIncorrectBitmaskSize.

@ParameterizedTest
@MethodSource("marshallerFactoryProvider")
public void classWithIncorrectBitmaskSize(MarshallerFactory factory) {
    SchemaDescriptor schema = new SchemaDescriptor(1, keyColumns(), new Column[] { new Column("primitiveLongCol".toUpperCase(), INT64, false), new Column("bitmaskCol".toUpperCase(), NativeTypes.bitmaskOf(9), true) });
    RecordMarshaller<TestObjectWithAllTypes> marshaller = factory.create(schema, TestObjectWithAllTypes.class);
    final TestObjectWithAllTypes rec = TestObjectWithAllTypes.randomObject(rnd);
    assertThrows(MarshallerException.class, () -> marshaller.marshal(rec), "Failed to write field [name=bitmaskCol]");
}
Also used : SchemaDescriptor(org.apache.ignite.internal.schema.SchemaDescriptor) Column(org.apache.ignite.internal.schema.Column) TestObjectWithAllTypes(org.apache.ignite.internal.schema.testobjects.TestObjectWithAllTypes) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 3 with TestObjectWithAllTypes

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

the class KvMarshallerTest method classWithIncorrectBitmaskSize.

@ParameterizedTest
@MethodSource("marshallerFactoryProvider")
public void classWithIncorrectBitmaskSize(MarshallerFactory factory) {
    Column[] cols = new Column[] { new Column("primitiveLongCol".toUpperCase(), INT64, false), new Column("bitmaskCol".toUpperCase(), NativeTypes.bitmaskOf(9), 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);
    assertThrows(MarshallerException.class, () -> marshaller.marshal(key, val), "Failed to write field [name=bitmaskCol]");
}
Also used : SchemaDescriptor(org.apache.ignite.internal.schema.SchemaDescriptor) Column(org.apache.ignite.internal.schema.Column) TestObjectWithAllTypes(org.apache.ignite.internal.schema.testobjects.TestObjectWithAllTypes) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 4 with TestObjectWithAllTypes

use of org.apache.ignite.internal.schema.testobjects.TestObjectWithAllTypes 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 5 with TestObjectWithAllTypes

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

the class RecordViewOperationsTest method removeExact.

@Test
public void removeExact() {
    final TestObjectWithAllTypes key = key(rnd);
    final TestObjectWithAllTypes obj = randomObject(rnd, key);
    final TestObjectWithAllTypes obj2 = randomObject(rnd, key);
    RecordView<TestObjectWithAllTypes> tbl = recordView();
    // Insert a new row.
    tbl.upsert(null, obj);
    assertEquals(obj, tbl.get(null, key));
    // Fails to delete row with unexpected value.
    assertFalse(tbl.deleteExact(null, obj2));
    assertEquals(obj, tbl.get(null, key));
    // Delete row with expected value.
    assertTrue(tbl.deleteExact(null, obj));
    assertNull(tbl.get(null, key));
    // Try to remove non-existed key.
    assertFalse(tbl.deleteExact(null, obj));
    assertNull(tbl.get(null, key));
    // Insert a new row.
    tbl.upsert(null, obj2);
    assertEquals(obj2, tbl.get(null, key));
    // Delete row with expected value.
    assertTrue(tbl.delete(null, obj2));
    assertNull(tbl.get(null, key));
    assertFalse(tbl.delete(null, obj2));
    assertNull(tbl.get(null, obj2));
}
Also used : TestObjectWithAllTypes(org.apache.ignite.internal.schema.testobjects.TestObjectWithAllTypes) Test(org.junit.jupiter.api.Test)

Aggregations

TestObjectWithAllTypes (org.apache.ignite.internal.schema.testobjects.TestObjectWithAllTypes)30 Test (org.junit.jupiter.api.Test)20 SchemaDescriptor (org.apache.ignite.internal.schema.SchemaDescriptor)10 Column (org.apache.ignite.internal.schema.Column)9 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)8 MethodSource (org.junit.jupiter.params.provider.MethodSource)8 Row (org.apache.ignite.internal.schema.row.Row)5 BinaryRow (org.apache.ignite.internal.schema.BinaryRow)4 Arrays (java.util.Arrays)2 Collections (java.util.Collections)2 List (java.util.List)2 Random (java.util.Random)2 Set (java.util.Set)2 Collectors (java.util.stream.Collectors)2 NativeTypeSpec (org.apache.ignite.internal.schema.NativeTypeSpec)2 NativeTypes (org.apache.ignite.internal.schema.NativeTypes)2 BYTES (org.apache.ignite.internal.schema.NativeTypes.BYTES)2 DATE (org.apache.ignite.internal.schema.NativeTypes.DATE)2 DOUBLE (org.apache.ignite.internal.schema.NativeTypes.DOUBLE)2 FLOAT (org.apache.ignite.internal.schema.NativeTypes.FLOAT)2