/** * @throws Exception If failed. */ @Test public void testPrimitiveMarshalling() throws Exception { BinaryMarshaller marsh = createMarshaller(); ThreadLocalRandom rnd = ThreadLocalRandom.current(); TestObject obj = new TestObject(0); BinaryObjectImpl binObj = toBinary(obj, marsh); BinaryFieldEx[] fields = new BinaryFieldEx[] { (BinaryFieldEx)binObj.type().field("bVal"), (BinaryFieldEx)binObj.type().field("cVal"), (BinaryFieldEx)binObj.type().field("sVal"), (BinaryFieldEx)binObj.type().field("iVal"), (BinaryFieldEx)binObj.type().field("lVal"), (BinaryFieldEx)binObj.type().field("fVal"), (BinaryFieldEx)binObj.type().field("dVal") }; ByteBuffer buf = ByteBuffer.allocate(1024 * 1024); for (int i = 0; i < 100; i++) { TestObject to = new TestObject(rnd.nextLong()); BinaryObjectImpl bObj = toBinary(to, marsh); for (BinaryFieldEx field : fields) field.writeField(bObj, buf); buf.flip(); for (BinaryFieldEx field : fields) assertEquals(field.value(bObj), field.readField(buf)); buf.flip(); } }
/** * @throws Exception If failed. */ @Test public void testDecimalFieldMarshalling() throws Exception { BinaryMarshaller marsh = createMarshaller(); BigDecimal values[] = new BigDecimal[] { BigDecimal.ZERO, BigDecimal.ONE, BigDecimal.TEN, new BigDecimal("-100.5"), BigDecimal.valueOf(Long.MAX_VALUE, 0), BigDecimal.valueOf(Long.MIN_VALUE, 0), BigDecimal.valueOf(Long.MAX_VALUE, 8), BigDecimal.valueOf(Long.MIN_VALUE, 8)}; DecimalValue decVal = new DecimalValue(values[0]); BinaryObjectImpl binObj = toBinary(decVal, marsh); BinaryFieldEx field = (BinaryFieldEx)binObj.type().field("decVal"); ByteBuffer buf = ByteBuffer.allocate(64); for (BigDecimal value : values) { decVal = new DecimalValue(value); binObj = toBinary(decVal, marsh); field.writeField(binObj, buf); buf.flip(); assertEquals(field.value(binObj), field.readField(buf)); buf.clear(); } }
/** * The test must be refactored after {@link IgniteSystemProperties#IGNITE_BINARY_SORT_OBJECT_FIELDS} * is removed. * * @throws Exception If failed. */ @Test public void testFieldOrder() throws Exception { if (BinaryUtils.FIELDS_SORTED_ORDER) return; BinaryMarshaller m = binaryMarshaller(); BinaryObjectImpl binObj = marshal(simpleObject(), m); Collection<String> fieldsBin = binObj.type().fieldNames(); Field[] fields = SimpleObject.class.getDeclaredFields(); assertEquals(fields.length, fieldsBin.size()); int i = 0; for (String fieldName : fieldsBin) { assertEquals(fields[i].getName(), fieldName); ++i; } }
/** * @throws Exception If failed. */ @Test public void testTimeMarshalling() throws Exception { BinaryMarshaller marsh = createMarshaller(); TimeValue obj = new TimeValue(11111L); BinaryObjectImpl binObj = toBinary(obj, marsh); BinaryFieldEx field = (BinaryFieldEx)binObj.type().field("time"); ByteBuffer buf = ByteBuffer.allocate(16); field.writeField(binObj, buf); buf.flip(); assertEquals(field.value(binObj), field.<Time>readField(buf)); }
assertArrayEquals(obj1.valArr, (BigDecimal[])portObj.type().field("valArr").value(portObj)); assertEquals(obj1.val, portObj.type().field("val").value(portObj)); assertArrayEquals(obj2.rawValArr, portObj.<DecimalMarshalAware>deserialize().rawValArr); assertEquals(obj2.val, portObj.type().field("val").value(portObj)); assertArrayEquals(obj2.valArr, (BigDecimal[])portObj.type().field("valArr").value(portObj)); assertEquals(obj2.val, portObj.type().field("val").value(portObj));
BinaryType type = objBin.type();