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