Search in sources :

Example 26 with BinaryObject

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

the class BinaryObjectBuilderDefaultMappersSelfTest method testBooleanField.

/**
     * @throws Exception If failed.
     */
public void testBooleanField() throws Exception {
    BinaryObjectBuilder builder = builder("Class");
    builder.setField("booleanField", true);
    BinaryObject po = builder.build();
    assertEquals(expectedHashCode("Class"), po.type().typeId());
    assertEquals(BinaryArrayIdentityResolver.instance().hashCode(po), po.hashCode());
    assertTrue(po.<Boolean>field("booleanField"));
}
Also used : BinaryObject(org.apache.ignite.binary.BinaryObject) BinaryObjectBuilder(org.apache.ignite.binary.BinaryObjectBuilder)

Example 27 with BinaryObject

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

the class BinaryObjectBuilderAdditionalSelfTest method testBuildFromObjectWithoutSchema.

/**
     * Ensure that object w/o schema can be re-built.
     */
public void testBuildFromObjectWithoutSchema() {
    BinaryObjectBuilderImpl binBuilder = wrap(new GridBinaryTestClass2());
    BinaryObject binObj = binBuilder.build();
    BinaryObjectBuilderImpl binBuilder2 = wrap(binObj);
    binBuilder2.build();
}
Also used : BinaryObject(org.apache.ignite.binary.BinaryObject) BinaryObjectBuilderImpl(org.apache.ignite.internal.binary.builder.BinaryObjectBuilderImpl) GridBinaryTestClass2(org.apache.ignite.internal.binary.test.GridBinaryTestClass2)

Example 28 with BinaryObject

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

the class BinaryObjectBuilderDefaultMappersSelfTest method testSeveralFields.

/**
     * @throws Exception If failed.
     */
public void testSeveralFields() throws Exception {
    BinaryObjectBuilder builder = builder("Class");
    builder.setField("i", 111);
    builder.setField("f", 111.111f);
    builder.setField("iArr", new int[] { 1, 2, 3 });
    builder.setField("obj", new Key(1));
    builder.setField("col", Arrays.asList(new Value(1), new Value(2)), Collection.class);
    BinaryObject po = builder.build();
    assertEquals(expectedHashCode("Class"), po.type().typeId());
    assertEquals(BinaryArrayIdentityResolver.instance().hashCode(po), po.hashCode());
    assertEquals(111, po.<Integer>field("i").intValue());
    assertEquals(111.111f, po.<Float>field("f").floatValue(), 0);
    assertTrue(Arrays.equals(new int[] { 1, 2, 3 }, po.<int[]>field("iArr")));
    assertEquals(1, po.<BinaryObject>field("obj").<Key>deserialize().i);
    List<BinaryObject> list = po.field("col");
    assertEquals(2, list.size());
    assertEquals(1, list.get(0).<Value>deserialize().i);
    assertEquals(2, list.get(1).<Value>deserialize().i);
}
Also used : BinaryObject(org.apache.ignite.binary.BinaryObject) BinaryObjectBuilder(org.apache.ignite.binary.BinaryObjectBuilder)

Example 29 with BinaryObject

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

the class BinaryObjectBuilderDefaultMappersSelfTest method testPlainBinaryObjectCopyFrom.

/**
     *
     */
public void testPlainBinaryObjectCopyFrom() {
    GridBinaryTestClasses.TestObjectPlainBinary obj = new GridBinaryTestClasses.TestObjectPlainBinary(toBinary(new GridBinaryTestClasses.TestObjectAllTypes()));
    BinaryObjectBuilderImpl builder = builder(toBinary(obj));
    assertTrue(builder.getField("plainBinary") instanceof BinaryObject);
    GridBinaryTestClasses.TestObjectPlainBinary deserialized = builder.build().deserialize();
    assertTrue(deserialized.plainBinary != null);
}
Also used : BinaryObject(org.apache.ignite.binary.BinaryObject) BinaryObjectBuilderImpl(org.apache.ignite.internal.binary.builder.BinaryObjectBuilderImpl) GridBinaryTestClasses(org.apache.ignite.internal.binary.mutabletest.GridBinaryTestClasses)

Example 30 with BinaryObject

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

the class BinaryObjectBuilderDefaultMappersSelfTest method testMapField.

/**
     * @throws Exception If failed.
     */
public void testMapField() throws Exception {
    BinaryObjectBuilder builder = builder("Class");
    builder.setField("mapField", F.asMap(new Key(1), new Value(1), new Key(2), new Value(2)));
    builder.setField("mapField2", F.asMap(new Key(1), new Value(1), new Key(2), new Value(2)), Map.class);
    BinaryObject po = builder.build();
    assertEquals(expectedHashCode("Class"), po.type().typeId());
    assertEquals(BinaryArrayIdentityResolver.instance().hashCode(po), po.hashCode());
    // Test non-standard map.
    Map<Key, Value> map = po.field("mapField");
    assertEquals(2, map.size());
    for (Map.Entry<Key, Value> e : map.entrySet()) assertEquals(e.getKey().i, e.getValue().i);
    // Test binary map
    Map<BinaryObject, BinaryObject> map2 = po.field("mapField2");
    assertEquals(2, map2.size());
    for (Map.Entry<BinaryObject, BinaryObject> e : map2.entrySet()) assertEquals(e.getKey().<Key>deserialize().i, e.getValue().<Value>deserialize().i);
}
Also used : BinaryObject(org.apache.ignite.binary.BinaryObject) BinaryObjectBuilder(org.apache.ignite.binary.BinaryObjectBuilder) Map(java.util.Map)

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