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());
}
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]");
}
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]");
}
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);
}
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));
}
Aggregations