Search in sources :

Example 16 with BinaryObjectBuilder

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

the class BinaryObjectBuilderAdditionalSelfTest method testSimpleTypeFieldRead.

/**
     * @throws Exception If failed.
     */
public void testSimpleTypeFieldRead() throws Exception {
    GridBinaryTestClasses.TestObjectAllTypes exp = new GridBinaryTestClasses.TestObjectAllTypes();
    exp.setDefaultData();
    BinaryObjectBuilder mutPo = wrap(exp);
    for (Field field : GridBinaryTestClasses.TestObjectAllTypes.class.getDeclaredFields()) {
        Object expVal = field.get(exp);
        Object actVal = mutPo.getField(field.getName());
        switch(field.getName()) {
            case "anEnum":
                assertEquals(((BinaryBuilderEnum) actVal).getOrdinal(), ((Enum) expVal).ordinal());
                break;
            case "enumArr":
                {
                    BinaryBuilderEnum[] actArr = (BinaryBuilderEnum[]) actVal;
                    Enum[] expArr = (Enum[]) expVal;
                    assertEquals(expArr.length, actArr.length);
                    for (int i = 0; i < actArr.length; i++) assertEquals(expArr[i].ordinal(), actArr[i].getOrdinal());
                    break;
                }
        }
    }
}
Also used : BinaryBuilderEnum(org.apache.ignite.internal.binary.builder.BinaryBuilderEnum) Field(java.lang.reflect.Field) BinaryObject(org.apache.ignite.binary.BinaryObject) BinaryBuilderEnum(org.apache.ignite.internal.binary.builder.BinaryBuilderEnum) GridBinaryTestClasses(org.apache.ignite.internal.binary.mutabletest.GridBinaryTestClasses) BinaryObjectBuilder(org.apache.ignite.binary.BinaryObjectBuilder)

Example 17 with BinaryObjectBuilder

use of org.apache.ignite.binary.BinaryObjectBuilder 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 18 with BinaryObjectBuilder

use of org.apache.ignite.binary.BinaryObjectBuilder 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)

Example 19 with BinaryObjectBuilder

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

the class BinaryObjectBuilderDefaultMappersSelfTest method testBooleanArrayField.

/**
     * @throws Exception If failed.
     */
public void testBooleanArrayField() throws Exception {
    BinaryObjectBuilder builder = builder("Class");
    builder.setField("booleanArrayField", new boolean[] { true, false });
    BinaryObject po = builder.build();
    assertEquals(expectedHashCode("Class"), po.type().typeId());
    assertEquals(BinaryArrayIdentityResolver.instance().hashCode(po), po.hashCode());
    boolean[] arr = po.field("booleanArrayField");
    assertEquals(2, arr.length);
    assertTrue(arr[0]);
    assertFalse(arr[1]);
}
Also used : BinaryObject(org.apache.ignite.binary.BinaryObject) BinaryObjectBuilder(org.apache.ignite.binary.BinaryObjectBuilder)

Example 20 with BinaryObjectBuilder

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

the class BinaryObjectBuilderDefaultMappersSelfTest method testIntArrayField.

/**
     * @throws Exception If failed.
     */
public void testIntArrayField() throws Exception {
    BinaryObjectBuilder builder = builder("Class");
    builder.setField("intArrayField", new int[] { 1, 2, 3 });
    BinaryObject po = builder.build();
    assertEquals(expectedHashCode("Class"), po.type().typeId());
    assertEquals(BinaryArrayIdentityResolver.instance().hashCode(po), po.hashCode());
    assertTrue(Arrays.equals(new int[] { 1, 2, 3 }, po.<int[]>field("intArrayField")));
}
Also used : BinaryObject(org.apache.ignite.binary.BinaryObject) BinaryObjectBuilder(org.apache.ignite.binary.BinaryObjectBuilder)

Aggregations

BinaryObjectBuilder (org.apache.ignite.binary.BinaryObjectBuilder)77 BinaryObject (org.apache.ignite.binary.BinaryObject)60 Ignite (org.apache.ignite.Ignite)11 IgniteBinary (org.apache.ignite.IgniteBinary)7 GridBinaryTestClasses (org.apache.ignite.internal.binary.mutabletest.GridBinaryTestClasses)7 Date (java.util.Date)4 BinaryType (org.apache.ignite.binary.BinaryType)4 HashMap (java.util.HashMap)3 HashSet (java.util.HashSet)3 LinkedHashMap (java.util.LinkedHashMap)3 GridAbsPredicate (org.apache.ignite.internal.util.lang.GridAbsPredicate)3 Field (java.lang.reflect.Field)2 SQLException (java.sql.SQLException)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Map (java.util.Map)2 UUID (java.util.UUID)2 IgniteCache (org.apache.ignite.IgniteCache)2 BinaryObjectException (org.apache.ignite.binary.BinaryObjectException)2 CacheConfiguration (org.apache.ignite.configuration.CacheConfiguration)2