use of org.apache.ignite.binary.BinaryTypeConfiguration in project ignite by apache.
the class BinaryMarshallerSelfTest method testDetached.
/**
* @throws Exception If failed.
*/
public void testDetached() throws Exception {
BinaryMarshaller marsh = binaryMarshaller(Arrays.asList(new BinaryTypeConfiguration(DetachedTestObject.class.getName()), new BinaryTypeConfiguration(DetachedInnerTestObject.class.getName())));
UUID id = UUID.randomUUID();
DetachedTestObject obj = marshal(new DetachedTestObject(new DetachedInnerTestObject(null, id)), marsh).deserialize();
assertEquals(id, obj.inner1.id);
assertEquals(id, obj.inner4.id);
assert obj.inner1 == obj.inner4;
BinaryObjectImpl innerPo = (BinaryObjectImpl) obj.inner2;
assert innerPo.detached();
DetachedInnerTestObject inner = innerPo.deserialize();
assertEquals(id, inner.id);
BinaryObjectImpl detachedPo = (BinaryObjectImpl) innerPo.detach();
assert detachedPo.detached();
inner = detachedPo.deserialize();
assertEquals(id, inner.id);
innerPo = (BinaryObjectImpl) obj.inner3;
assert innerPo.detached();
inner = innerPo.deserialize();
assertEquals(id, inner.id);
assertNotNull(inner.inner);
detachedPo = (BinaryObjectImpl) innerPo.detach();
assert detachedPo.detached();
inner = innerPo.deserialize();
assertEquals(id, inner.id);
assertNotNull(inner.inner);
}
use of org.apache.ignite.binary.BinaryTypeConfiguration in project ignite by apache.
the class BinaryMarshallerSelfTest method testCustomSerializer.
/**
* @throws Exception If failed.
*/
public void testCustomSerializer() throws Exception {
BinaryTypeConfiguration type = new BinaryTypeConfiguration(CustomSerializedObject1.class.getName());
type.setSerializer(new CustomSerializer1());
BinaryMarshaller marsh = binaryMarshaller(Arrays.asList(type));
CustomSerializedObject1 obj1 = new CustomSerializedObject1(10);
BinaryObject po1 = marshal(obj1, marsh);
assertEquals(20, po1.<CustomSerializedObject1>deserialize().val);
}
use of org.apache.ignite.binary.BinaryTypeConfiguration in project ignite by apache.
the class BinaryMarshallerSelfTest method testBinary.
/**
* @throws Exception If failed.
*/
public void testBinary() throws Exception {
BinaryMarshaller marsh = binaryMarshaller(Arrays.asList(new BinaryTypeConfiguration(SimpleObject.class.getName()), new BinaryTypeConfiguration(TestBinary.class.getName())));
TestBinary obj = binaryObject();
BinaryObject po = marshal(obj, marsh);
assertEquals(obj, po.deserialize());
assertEquals(obj.b, (byte) po.field("_b"));
assertEquals(obj.s, (short) po.field("_s"));
assertEquals(obj.i, (int) po.field("_i"));
assertEquals(obj.l, (long) po.field("_l"));
assertEquals(obj.f, (float) po.field("_f"), 0);
assertEquals(obj.d, (double) po.field("_d"), 0);
assertEquals(obj.c, (char) po.field("_c"));
assertEquals(obj.bool, (boolean) po.field("_bool"));
assertEquals(obj.str, po.field("_str"));
assertEquals(obj.uuid, po.field("_uuid"));
assertEquals(obj.date, po.field("_date"));
assertEquals(obj.ts, po.field("_ts"));
assertArrayEquals(obj.bArr, (byte[]) po.field("_bArr"));
assertArrayEquals(obj.sArr, (short[]) po.field("_sArr"));
assertArrayEquals(obj.iArr, (int[]) po.field("_iArr"));
assertArrayEquals(obj.lArr, (long[]) po.field("_lArr"));
assertArrayEquals(obj.fArr, (float[]) po.field("_fArr"), 0);
assertArrayEquals(obj.dArr, (double[]) po.field("_dArr"), 0);
assertArrayEquals(obj.cArr, (char[]) po.field("_cArr"));
assertBooleanArrayEquals(obj.boolArr, (boolean[]) po.field("_boolArr"));
assertArrayEquals(obj.strArr, (String[]) po.field("_strArr"));
assertArrayEquals(obj.uuidArr, (UUID[]) po.field("_uuidArr"));
assertArrayEquals(obj.dateArr, (Date[]) po.field("_dateArr"));
assertArrayEquals(obj.objArr, (Object[]) po.field("_objArr"));
assertEquals(obj.col, po.field("_col"));
assertEquals(obj.map, po.field("_map"));
assertEquals(new Integer(obj.enumVal.ordinal()), new Integer(((BinaryObject) po.field("_enumVal")).enumOrdinal()));
assertArrayEquals(ordinals(obj.enumArr), ordinals((BinaryObject[]) po.field("_enumArr")));
assertNull(po.field("unknown"));
BinaryObject simplePo = po.field("_simple");
assertEquals(obj.simple, simplePo.deserialize());
assertEquals(obj.simple.b, (byte) simplePo.field("b"));
assertEquals(obj.simple.s, (short) simplePo.field("s"));
assertEquals(obj.simple.i, (int) simplePo.field("i"));
assertEquals(obj.simple.l, (long) simplePo.field("l"));
assertEquals(obj.simple.f, (float) simplePo.field("f"), 0);
assertEquals(obj.simple.d, (double) simplePo.field("d"), 0);
assertEquals(obj.simple.c, (char) simplePo.field("c"));
assertEquals(obj.simple.bool, (boolean) simplePo.field("bool"));
assertEquals(obj.simple.str, simplePo.field("str"));
assertEquals(obj.simple.uuid, simplePo.field("uuid"));
assertEquals(obj.simple.date, simplePo.field("date"));
assertEquals(Date.class, obj.simple.date.getClass());
assertEquals(obj.simple.ts, simplePo.field("ts"));
assertArrayEquals(obj.simple.bArr, (byte[]) simplePo.field("bArr"));
assertArrayEquals(obj.simple.sArr, (short[]) simplePo.field("sArr"));
assertArrayEquals(obj.simple.iArr, (int[]) simplePo.field("iArr"));
assertArrayEquals(obj.simple.lArr, (long[]) simplePo.field("lArr"));
assertArrayEquals(obj.simple.fArr, (float[]) simplePo.field("fArr"), 0);
assertArrayEquals(obj.simple.dArr, (double[]) simplePo.field("dArr"), 0);
assertArrayEquals(obj.simple.cArr, (char[]) simplePo.field("cArr"));
assertBooleanArrayEquals(obj.simple.boolArr, (boolean[]) simplePo.field("boolArr"));
assertArrayEquals(obj.simple.strArr, (String[]) simplePo.field("strArr"));
assertArrayEquals(obj.simple.uuidArr, (UUID[]) simplePo.field("uuidArr"));
assertArrayEquals(obj.simple.dateArr, (Date[]) simplePo.field("dateArr"));
assertArrayEquals(obj.simple.objArr, (Object[]) simplePo.field("objArr"));
assertEquals(obj.simple.col, simplePo.field("col"));
assertEquals(obj.simple.map, simplePo.field("map"));
assertEquals(new Integer(obj.simple.enumVal.ordinal()), new Integer(((BinaryObject) simplePo.field("enumVal")).enumOrdinal()));
assertArrayEquals(ordinals(obj.simple.enumArr), ordinals((BinaryObject[]) simplePo.field("enumArr")));
assertNull(simplePo.field("simple"));
assertNull(simplePo.field("binary"));
assertNull(simplePo.field("unknown"));
BinaryObject binaryPo = po.field("_binary");
assertEquals(obj.binary, binaryPo.deserialize());
assertEquals(obj.binary.b, (byte) binaryPo.field("_b"));
assertEquals(obj.binary.s, (short) binaryPo.field("_s"));
assertEquals(obj.binary.i, (int) binaryPo.field("_i"));
assertEquals(obj.binary.l, (long) binaryPo.field("_l"));
assertEquals(obj.binary.f, (float) binaryPo.field("_f"), 0);
assertEquals(obj.binary.d, (double) binaryPo.field("_d"), 0);
assertEquals(obj.binary.c, (char) binaryPo.field("_c"));
assertEquals(obj.binary.bool, (boolean) binaryPo.field("_bool"));
assertEquals(obj.binary.str, binaryPo.field("_str"));
assertEquals(obj.binary.uuid, binaryPo.field("_uuid"));
assertEquals(obj.binary.date, binaryPo.field("_date"));
assertEquals(obj.binary.ts, binaryPo.field("_ts"));
assertArrayEquals(obj.binary.bArr, (byte[]) binaryPo.field("_bArr"));
assertArrayEquals(obj.binary.sArr, (short[]) binaryPo.field("_sArr"));
assertArrayEquals(obj.binary.iArr, (int[]) binaryPo.field("_iArr"));
assertArrayEquals(obj.binary.lArr, (long[]) binaryPo.field("_lArr"));
assertArrayEquals(obj.binary.fArr, (float[]) binaryPo.field("_fArr"), 0);
assertArrayEquals(obj.binary.dArr, (double[]) binaryPo.field("_dArr"), 0);
assertArrayEquals(obj.binary.cArr, (char[]) binaryPo.field("_cArr"));
assertBooleanArrayEquals(obj.binary.boolArr, (boolean[]) binaryPo.field("_boolArr"));
assertArrayEquals(obj.binary.strArr, (String[]) binaryPo.field("_strArr"));
assertArrayEquals(obj.binary.uuidArr, (UUID[]) binaryPo.field("_uuidArr"));
assertArrayEquals(obj.binary.dateArr, (Date[]) binaryPo.field("_dateArr"));
assertArrayEquals(obj.binary.objArr, (Object[]) binaryPo.field("_objArr"));
assertEquals(obj.binary.col, binaryPo.field("_col"));
assertEquals(obj.binary.map, binaryPo.field("_map"));
assertEquals(new Integer(obj.binary.enumVal.ordinal()), new Integer(((BinaryObject) binaryPo.field("_enumVal")).enumOrdinal()));
assertArrayEquals(ordinals(obj.binary.enumArr), ordinals((BinaryObject[]) binaryPo.field("_enumArr")));
assertNull(binaryPo.field("_simple"));
assertNull(binaryPo.field("_binary"));
assertNull(binaryPo.field("unknown"));
}
use of org.apache.ignite.binary.BinaryTypeConfiguration in project ignite by apache.
the class BinaryMarshallerSelfTest method testSimpleObject.
/**
* @throws Exception If failed.
*/
public void testSimpleObject() throws Exception {
BinaryMarshaller marsh = binaryMarshaller(Arrays.asList(new BinaryTypeConfiguration(SimpleObject.class.getName())));
SimpleObject obj = simpleObject();
BinaryObject po = marshal(obj, marsh);
assertEquals(obj, po.deserialize());
assertEquals(obj.b, (byte) po.field("b"));
assertEquals(obj.s, (short) po.field("s"));
assertEquals(obj.i, (int) po.field("i"));
assertEquals(obj.l, (long) po.field("l"));
assertEquals(obj.f, (float) po.field("f"), 0);
assertEquals(obj.d, (double) po.field("d"), 0);
assertEquals(obj.c, (char) po.field("c"));
assertEquals(obj.bool, (boolean) po.field("bool"));
assertEquals(obj.str, po.field("str"));
assertEquals(obj.uuid, po.field("uuid"));
assertEquals(obj.date, po.field("date"));
assertEquals(Date.class, obj.date.getClass());
assertEquals(obj.ts, po.field("ts"));
assertArrayEquals(obj.bArr, (byte[]) po.field("bArr"));
assertArrayEquals(obj.sArr, (short[]) po.field("sArr"));
assertArrayEquals(obj.iArr, (int[]) po.field("iArr"));
assertArrayEquals(obj.lArr, (long[]) po.field("lArr"));
assertArrayEquals(obj.fArr, (float[]) po.field("fArr"), 0);
assertArrayEquals(obj.dArr, (double[]) po.field("dArr"), 0);
assertArrayEquals(obj.cArr, (char[]) po.field("cArr"));
assertBooleanArrayEquals(obj.boolArr, (boolean[]) po.field("boolArr"));
assertArrayEquals(obj.strArr, (String[]) po.field("strArr"));
assertArrayEquals(obj.uuidArr, (UUID[]) po.field("uuidArr"));
assertArrayEquals(obj.dateArr, (Date[]) po.field("dateArr"));
assertArrayEquals(obj.objArr, (Object[]) po.field("objArr"));
assertEquals(obj.col, po.field("col"));
assertEquals(obj.map, po.field("map"));
assertEquals(new Integer(obj.enumVal.ordinal()), new Integer(((BinaryObject) po.field("enumVal")).enumOrdinal()));
assertArrayEquals(ordinals(obj.enumArr), ordinals((BinaryObject[]) po.field("enumArr")));
assertNull(po.field("unknown"));
BinaryObject innerPo = po.field("inner");
assertEquals(obj.inner, innerPo.deserialize());
assertEquals(obj.inner.b, (byte) innerPo.field("b"));
assertEquals(obj.inner.s, (short) innerPo.field("s"));
assertEquals(obj.inner.i, (int) innerPo.field("i"));
assertEquals(obj.inner.l, (long) innerPo.field("l"));
assertEquals(obj.inner.f, (float) innerPo.field("f"), 0);
assertEquals(obj.inner.d, (double) innerPo.field("d"), 0);
assertEquals(obj.inner.c, (char) innerPo.field("c"));
assertEquals(obj.inner.bool, (boolean) innerPo.field("bool"));
assertEquals(obj.inner.str, innerPo.field("str"));
assertEquals(obj.inner.uuid, innerPo.field("uuid"));
assertEquals(obj.inner.date, innerPo.field("date"));
assertEquals(Date.class, obj.inner.date.getClass());
assertEquals(obj.inner.ts, innerPo.field("ts"));
assertArrayEquals(obj.inner.bArr, (byte[]) innerPo.field("bArr"));
assertArrayEquals(obj.inner.sArr, (short[]) innerPo.field("sArr"));
assertArrayEquals(obj.inner.iArr, (int[]) innerPo.field("iArr"));
assertArrayEquals(obj.inner.lArr, (long[]) innerPo.field("lArr"));
assertArrayEquals(obj.inner.fArr, (float[]) innerPo.field("fArr"), 0);
assertArrayEquals(obj.inner.dArr, (double[]) innerPo.field("dArr"), 0);
assertArrayEquals(obj.inner.cArr, (char[]) innerPo.field("cArr"));
assertBooleanArrayEquals(obj.inner.boolArr, (boolean[]) innerPo.field("boolArr"));
assertArrayEquals(obj.inner.strArr, (String[]) innerPo.field("strArr"));
assertArrayEquals(obj.inner.uuidArr, (UUID[]) innerPo.field("uuidArr"));
assertArrayEquals(obj.inner.dateArr, (Date[]) innerPo.field("dateArr"));
assertArrayEquals(obj.inner.objArr, (Object[]) innerPo.field("objArr"));
assertEquals(obj.inner.col, innerPo.field("col"));
assertEquals(obj.inner.map, innerPo.field("map"));
assertEquals(new Integer(obj.inner.enumVal.ordinal()), new Integer(((BinaryObject) innerPo.field("enumVal")).enumOrdinal()));
assertArrayEquals(ordinals(obj.inner.enumArr), ordinals((BinaryObject[]) innerPo.field("enumArr")));
assertNull(innerPo.field("inner"));
assertNull(innerPo.field("unknown"));
}
use of org.apache.ignite.binary.BinaryTypeConfiguration in project ignite by apache.
the class BinaryMarshallerSelfTest method testBinaryCopyFloatArray.
/**
* @throws Exception If failed.
*/
public void testBinaryCopyFloatArray() throws Exception {
BinaryMarshaller marsh = binaryMarshaller(Arrays.asList(new BinaryTypeConfiguration(SimpleObject.class.getName())));
SimpleObject obj = simpleObject();
BinaryObject po = marshal(obj, marsh);
BinaryObject copy = copy(po, F.<String, Object>asMap("fArr", new float[] { 1, 2, 3 }));
assertArrayEquals(new float[] { 1, 2, 3 }, copy.<float[]>field("fArr"), 0);
SimpleObject obj0 = copy.deserialize();
assertArrayEquals(new float[] { 1, 2, 3 }, obj0.fArr, 0);
}
Aggregations