Search in sources :

Example 6 with BinaryObjectBuilder

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

the class BinaryObjectBuilderDefaultMappersSelfTest method testCharArrayField.

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

Example 7 with BinaryObjectBuilder

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

the class BinaryObjectBuilderDefaultMappersSelfTest method testDoubleField.

/**
     * @throws Exception If failed.
     */
public void testDoubleField() throws Exception {
    BinaryObjectBuilder builder = builder("Class");
    builder.setField("doubleField", 1.0d);
    BinaryObject po = builder.build();
    assertEquals(expectedHashCode("Class"), po.type().typeId());
    assertEquals(BinaryArrayIdentityResolver.instance().hashCode(po), po.hashCode());
    assertEquals(1.0d, po.<Double>field("doubleField").doubleValue(), 0);
}
Also used : BinaryObject(org.apache.ignite.binary.BinaryObject) BinaryObjectBuilder(org.apache.ignite.binary.BinaryObjectBuilder)

Example 8 with BinaryObjectBuilder

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

the class BinaryObjectBuilderDefaultMappersSelfTest method testShortField.

/**
     * @throws Exception If failed.
     */
public void testShortField() throws Exception {
    BinaryObjectBuilder builder = builder("Class");
    builder.setField("shortField", (short) 1);
    BinaryObject po = builder.build();
    assertEquals(expectedHashCode("Class"), po.type().typeId());
    assertEquals(BinaryArrayIdentityResolver.instance().hashCode(po), po.hashCode());
    assertEquals((short) 1, po.<Short>field("shortField").shortValue());
}
Also used : BinaryObject(org.apache.ignite.binary.BinaryObject) BinaryObjectBuilder(org.apache.ignite.binary.BinaryObjectBuilder)

Example 9 with BinaryObjectBuilder

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

the class BinaryObjectBuilderDefaultMappersSelfTest method testBuildAndDeserialize.

/**
     * @throws Exception If failed.
     */
public void testBuildAndDeserialize() throws Exception {
    BinaryObjectBuilder builder = builder(Value.class.getName());
    builder.setField("i", 1);
    BinaryObject bo = builder.build();
    assertEquals(expectedHashCode(Value.class.getName()), bo.type().typeId());
    assertEquals(BinaryArrayIdentityResolver.instance().hashCode(bo), bo.hashCode());
    assertEquals(1, bo.<Value>deserialize().i);
}
Also used : BinaryObject(org.apache.ignite.binary.BinaryObject) BinaryObjectBuilder(org.apache.ignite.binary.BinaryObjectBuilder)

Example 10 with BinaryObjectBuilder

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

the class BinaryObjectBuilderDefaultMappersSelfTest method testCollectionField.

/**
     * @throws Exception If failed.
     */
public void testCollectionField() throws Exception {
    BinaryObjectBuilder builder = builder("Class");
    builder.setField("collectionField", Arrays.asList(new Value(1), new Value(2)));
    builder.setField("collectionField2", 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());
    List<Value> list = po.field("collectionField");
    assertEquals(2, list.size());
    assertEquals(1, list.get(0).i);
    assertEquals(2, list.get(1).i);
    List<BinaryObject> list2 = po.field("collectionField2");
    assertEquals(2, list2.size());
    assertEquals(1, list2.get(0).<Value>deserialize().i);
    assertEquals(2, list2.get(1).<Value>deserialize().i);
}
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