use of org.apache.ignite.binary.BinaryObject in project ignite by apache.
the class BinaryMarshallerSelfTest method testBinaryObject.
/**
* @throws Exception If failed.
*/
public void testBinaryObject() throws Exception {
BinaryMarshaller marsh = binaryMarshaller(Arrays.asList(new BinaryTypeConfiguration(SimpleObject.class.getName())));
SimpleObject obj = simpleObject();
BinaryObject po = marshal(obj, marsh);
BinaryObject po0 = marshalUnmarshal(po, marsh);
assertTrue(po.hasField("b"));
assertTrue(po.hasField("s"));
assertTrue(po.hasField("i"));
assertTrue(po.hasField("l"));
assertTrue(po.hasField("f"));
assertTrue(po.hasField("d"));
assertTrue(po.hasField("c"));
assertTrue(po.hasField("bool"));
assertFalse(po.hasField("no_such_field"));
assertEquals(obj, po.deserialize());
assertEquals(obj, po0.deserialize());
}
use of org.apache.ignite.binary.BinaryObject in project ignite by apache.
the class BinaryMarshallerSelfTest method testBinaryCopyLongArray.
/**
* @throws Exception If failed.
*/
public void testBinaryCopyLongArray() 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("lArr", new long[] { 1, 2, 3 }));
assertArrayEquals(new long[] { 1, 2, 3 }, copy.<long[]>field("lArr"));
SimpleObject obj0 = copy.deserialize();
assertArrayEquals(new long[] { 1, 2, 3 }, obj0.lArr);
}
use of org.apache.ignite.binary.BinaryObject in project ignite by apache.
the class BinaryMarshallerSelfTest method testBinaryCopyMixed.
/**
* @throws Exception If failed.
*/
public void testBinaryCopyMixed() throws Exception {
BinaryMarshaller marsh = binaryMarshaller(Arrays.asList(new BinaryTypeConfiguration(SimpleObject.class.getName())));
SimpleObject obj = simpleObject();
BinaryObject po = marshal(obj, marsh);
Map<String, Object> map = new HashMap<>(3, 1.0f);
SimpleObject newObj = new SimpleObject();
newObj.i = 12345;
newObj.fArr = new float[] { 5, 8, 0 };
newObj.str = "newStr";
map.put("i", 1234);
map.put("str", "str555");
map.put("inner", newObj);
map.put("s", (short) 2323);
map.put("bArr", new byte[] { 6, 7, 9 });
map.put("b", (byte) 111);
BinaryObject copy = copy(po, map);
assertEquals(1234, copy.<Integer>field("i").intValue());
assertEquals("str555", copy.<String>field("str"));
assertEquals(newObj, copy.<BinaryObject>field("inner").deserialize());
assertEquals((short) 2323, copy.<Short>field("s").shortValue());
assertArrayEquals(new byte[] { 6, 7, 9 }, copy.<byte[]>field("bArr"));
assertEquals((byte) 111, copy.<Byte>field("b").byteValue());
SimpleObject obj0 = copy.deserialize();
assertEquals(1234, obj0.i);
assertEquals("str555", obj0.str);
assertEquals(newObj, obj0.inner);
assertEquals((short) 2323, obj0.s);
assertArrayEquals(new byte[] { 6, 7, 9 }, obj0.bArr);
assertEquals((byte) 111, obj0.b);
}
use of org.apache.ignite.binary.BinaryObject in project ignite by apache.
the class BinaryObjectBuilderAdditionalSelfTest method testCollectionsSerialization.
/**
* Check that correct type is stored in binary object.
*/
public void testCollectionsSerialization() {
final BinaryObjectBuilder root = newWrapper(BigInteger.class);
final List<Integer> arrList = new ArrayList<>();
arrList.add(Integer.MAX_VALUE);
final List<Integer> linkedList = new LinkedList<>();
linkedList.add(Integer.MAX_VALUE);
final Set<Integer> hashSet = new HashSet<>();
hashSet.add(Integer.MAX_VALUE);
final Set<Integer> linkedHashSet = new LinkedHashSet<>();
linkedHashSet.add(Integer.MAX_VALUE);
final Map<String, String> hashMap = new HashMap<>();
hashMap.put("key", "val");
final Map<String, String> linkedHashMap = new LinkedHashMap<>();
linkedHashMap.put("key", "val");
// collections
root.setField("arrayList", arrList);
root.setField("linkedList", linkedList);
root.setField("hashSet", hashSet);
root.setField("linkedHashSet", linkedHashSet);
root.setField("singletonList", Collections.singletonList(Integer.MAX_VALUE), Collection.class);
root.setField("singletonSet", Collections.singleton(Integer.MAX_VALUE), Collection.class);
// maps
root.setField("hashMap", hashMap);
root.setField("linkedHashMap", linkedHashMap);
root.setField("singletonMap", Collections.singletonMap("key", "val"), Map.class);
// objects
root.setField("asList", Collections.singletonList(Integer.MAX_VALUE));
root.setField("asSet", Collections.singleton(Integer.MAX_VALUE));
root.setField("asMap", Collections.singletonMap("key", "val"));
root.setField("asListHint", Collections.singletonList(Integer.MAX_VALUE), List.class);
root.setField("asSetHint", Collections.singleton(Integer.MAX_VALUE), Set.class);
root.setField("asMapHint", (AbstractMap) Collections.singletonMap("key", "val"), AbstractMap.class);
BinaryObject binaryObj = root.build();
final String COL = "Collection";
final String MAP = "Map";
final String OBJ = "Object";
assert COL.equals(binaryObj.type().fieldTypeName("arrayList"));
assert COL.equals(binaryObj.type().fieldTypeName("linkedList"));
assert COL.equals(binaryObj.type().fieldTypeName("hashSet"));
assert COL.equals(binaryObj.type().fieldTypeName("linkedHashSet"));
assert COL.equals(binaryObj.type().fieldTypeName("linkedHashSet"));
assert COL.equals(binaryObj.type().fieldTypeName("linkedHashSet"));
assert COL.equals(binaryObj.type().fieldTypeName("singletonList"));
assert COL.equals(binaryObj.type().fieldTypeName("singletonSet"));
assert MAP.equals(binaryObj.type().fieldTypeName("singletonMap"));
assert OBJ.equals(binaryObj.type().fieldTypeName("asList"));
assert OBJ.equals(binaryObj.type().fieldTypeName("asSet"));
assert OBJ.equals(binaryObj.type().fieldTypeName("asMap"));
assert OBJ.equals(binaryObj.type().fieldTypeName("asListHint"));
assert OBJ.equals(binaryObj.type().fieldTypeName("asSetHint"));
assert OBJ.equals(binaryObj.type().fieldTypeName("asMapHint"));
}
use of org.apache.ignite.binary.BinaryObject in project ignite by apache.
the class BinaryMarshallerSelfTest method testCollectionFields.
/**
* @throws Exception If failed.
*/
public void testCollectionFields() throws Exception {
BinaryMarshaller marsh = binaryMarshaller(Arrays.asList(new BinaryTypeConfiguration(CollectionFieldsObject.class.getName()), new BinaryTypeConfiguration(Key.class.getName()), new BinaryTypeConfiguration(Value.class.getName())));
Object[] arr = new Object[] { new Value(1), new Value(2), new Value(3) };
Collection<Value> col = new ArrayList<>(Arrays.asList(new Value(4), new Value(5), new Value(6)));
Map<Key, Value> map = new HashMap<>(F.asMap(new Key(10), new Value(10), new Key(20), new Value(20), new Key(30), new Value(30)));
CollectionFieldsObject obj = new CollectionFieldsObject(arr, col, map);
BinaryObject po = marshal(obj, marsh);
Object[] arr0 = po.field("arr");
assertEquals(3, arr0.length);
int i = 1;
for (Object valPo : arr0) assertEquals(i++, ((BinaryObject) valPo).<Value>deserialize().val);
Collection<BinaryObject> col0 = po.field("col");
i = 4;
for (BinaryObject valPo : col0) assertEquals(i++, valPo.<Value>deserialize().val);
Map<BinaryObject, BinaryObject> map0 = po.field("map");
for (Map.Entry<BinaryObject, BinaryObject> e : map0.entrySet()) assertEquals(e.getKey().<Key>deserialize().key, e.getValue().<Value>deserialize().val);
}
Aggregations