/** * @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(); } }
/** * @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)); }
/** * @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(); } }