Search in sources :

Example 81 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)

Example 82 with BinaryObject

use of org.apache.ignite.binary.BinaryObject in project ignite by apache.

the class BinaryMarshallerSelfTest method testWriteReplacePrivate.

/**
 * @throws Exception If failed.
 */
public void testWriteReplacePrivate() throws Exception {
    BinaryMarshaller marsh = binaryMarshaller(Collections.singleton(new BinaryTypeConfiguration(TestObject.class.getName())));
    TestObject obj = new TestObject();
    BinaryObject po = marshal(obj, marsh);
    assertEquals(obj, po.deserialize());
    assertEquals(obj.val, ((BinaryObject) po.field("val")).deserialize());
}
Also used : BinaryObject(org.apache.ignite.binary.BinaryObject) BinaryTypeConfiguration(org.apache.ignite.binary.BinaryTypeConfiguration)

Example 83 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 84 with BinaryObject

use of org.apache.ignite.binary.BinaryObject in project ignite by apache.

the class BinaryMarshallerSelfTest method testBinaryCopyUuid.

/**
 * @throws Exception If failed.
 */
public void testBinaryCopyUuid() throws Exception {
    BinaryMarshaller marsh = binaryMarshaller(Arrays.asList(new BinaryTypeConfiguration(SimpleObject.class.getName())));
    SimpleObject obj = simpleObject();
    BinaryObject po = marshal(obj, marsh);
    UUID uuid = UUID.randomUUID();
    BinaryObject copy = copy(po, F.<String, Object>asMap("uuid", uuid));
    assertEquals(uuid, copy.<UUID>field("uuid"));
    SimpleObject obj0 = copy.deserialize();
    assertEquals(uuid, obj0.uuid);
}
Also used : BinaryObject(org.apache.ignite.binary.BinaryObject) BinaryTypeConfiguration(org.apache.ignite.binary.BinaryTypeConfiguration) UUID(java.util.UUID)

Example 85 with BinaryObject

use of org.apache.ignite.binary.BinaryObject in project ignite by apache.

the class BinaryMarshallerSelfTest method testBinaryCopyCharArray.

/**
 * @throws Exception If failed.
 */
public void testBinaryCopyCharArray() 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("cArr", new char[] { 1, 2, 3 }));
    assertArrayEquals(new char[] { 1, 2, 3 }, copy.<char[]>field("cArr"));
    SimpleObject obj0 = copy.deserialize();
    assertArrayEquals(new char[] { 1, 2, 3 }, obj0.cArr);
}
Also used : BinaryObject(org.apache.ignite.binary.BinaryObject) BinaryTypeConfiguration(org.apache.ignite.binary.BinaryTypeConfiguration)

Aggregations

BinaryObject (org.apache.ignite.binary.BinaryObject)200 BinaryObjectBuilder (org.apache.ignite.binary.BinaryObjectBuilder)55 Ignite (org.apache.ignite.Ignite)28 BinaryTypeConfiguration (org.apache.ignite.binary.BinaryTypeConfiguration)26 IgniteCache (org.apache.ignite.IgniteCache)25 HashMap (java.util.HashMap)16 Cache (javax.cache.Cache)15 ArrayList (java.util.ArrayList)13 Map (java.util.Map)13 LinkedHashMap (java.util.LinkedHashMap)12 List (java.util.List)10 BinaryObjectException (org.apache.ignite.binary.BinaryObjectException)10 IgniteEx (org.apache.ignite.internal.IgniteEx)10 BinaryObjectBuilderImpl (org.apache.ignite.internal.binary.builder.BinaryObjectBuilderImpl)10 IgniteException (org.apache.ignite.IgniteException)9 GridBinaryTestClasses (org.apache.ignite.internal.binary.mutabletest.GridBinaryTestClasses)9 UUID (java.util.UUID)8 BigInteger (java.math.BigInteger)7 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)7 BinaryType (org.apache.ignite.binary.BinaryType)7