Search in sources :

Example 71 with BinaryObject

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());
}
Also used : BinaryObject(org.apache.ignite.binary.BinaryObject) BinaryTypeConfiguration(org.apache.ignite.binary.BinaryTypeConfiguration)

Example 72 with BinaryObject

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);
}
Also used : BinaryObject(org.apache.ignite.binary.BinaryObject) BinaryTypeConfiguration(org.apache.ignite.binary.BinaryTypeConfiguration)

Example 73 with BinaryObject

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);
}
Also used : BigInteger(java.math.BigInteger) BinaryObject(org.apache.ignite.binary.BinaryObject) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) BinaryTypeConfiguration(org.apache.ignite.binary.BinaryTypeConfiguration) BinaryObject(org.apache.ignite.binary.BinaryObject)

Example 74 with BinaryObject

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"));
}
Also used : LinkedHashSet(java.util.LinkedHashSet) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) LinkedHashMap(java.util.LinkedHashMap) BigInteger(java.math.BigInteger) BinaryObject(org.apache.ignite.binary.BinaryObject) BinaryObjectBuilder(org.apache.ignite.binary.BinaryObjectBuilder) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Example 75 with BinaryObject

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);
}
Also used : ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) ArrayList(java.util.ArrayList) BinaryObject(org.apache.ignite.binary.BinaryObject) BinaryTypeConfiguration(org.apache.ignite.binary.BinaryTypeConfiguration) BinaryObject(org.apache.ignite.binary.BinaryObject) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) TreeMap(java.util.TreeMap)

Aggregations

BinaryObject (org.apache.ignite.binary.BinaryObject)173 BinaryObjectBuilder (org.apache.ignite.binary.BinaryObjectBuilder)54 BinaryTypeConfiguration (org.apache.ignite.binary.BinaryTypeConfiguration)24 IgniteCache (org.apache.ignite.IgniteCache)21 Ignite (org.apache.ignite.Ignite)19 HashMap (java.util.HashMap)14 Map (java.util.Map)14 LinkedHashMap (java.util.LinkedHashMap)13 ArrayList (java.util.ArrayList)12 Cache (javax.cache.Cache)12 BinaryObjectBuilderImpl (org.apache.ignite.internal.binary.builder.BinaryObjectBuilderImpl)10 GridBinaryTestClasses (org.apache.ignite.internal.binary.mutabletest.GridBinaryTestClasses)9 List (java.util.List)8 UUID (java.util.UUID)8 BinaryObjectException (org.apache.ignite.binary.BinaryObjectException)8 BigInteger (java.math.BigInteger)7 Date (java.util.Date)6 BinaryType (org.apache.ignite.binary.BinaryType)6 IgniteEx (org.apache.ignite.internal.IgniteEx)6 Transaction (org.apache.ignite.transactions.Transaction)6