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"));
}
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();
}
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);
}
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);
}
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);
}
Aggregations