MessagePack Jackson Data Size 测试源代码
This commit is contained in:
parent
7883336039
commit
12f7f49b8f
|
@ -0,0 +1,56 @@
|
|||
package com.insight.demo.serialize;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.fasterxml.jackson.core.JsonParser;
|
||||
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.insight.demo.serialize.model.msgpack.MessageData;
|
||||
import com.insight.demo.utils.MockDataUtils;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.junit.Test;
|
||||
import org.msgpack.jackson.dataformat.JsonArrayFormat;
|
||||
import org.msgpack.jackson.dataformat.MessagePackFactory;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.xerial.snappy.Snappy;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class MessagePackDataTest {
|
||||
|
||||
final Logger logger = LoggerFactory.getLogger(MessagePackDataTest.class);
|
||||
|
||||
@Test
|
||||
public void testDataSize() {
|
||||
logger.debug("Test Data Size");
|
||||
|
||||
byte[] raw;
|
||||
byte[] rawJsonArray;
|
||||
|
||||
List<MessageData> dataList = MockDataUtils.getMessageDataList(600000);
|
||||
|
||||
try {
|
||||
ObjectMapper objectMapper = new ObjectMapper(new MessagePackFactory());
|
||||
raw = objectMapper.writeValueAsBytes(dataList);
|
||||
|
||||
FileUtils.byteCountToDisplaySize(raw.length);
|
||||
logger.debug("Raw Size: [{}]", FileUtils.byteCountToDisplaySize(raw.length));
|
||||
|
||||
|
||||
objectMapper = new ObjectMapper(new MessagePackFactory());
|
||||
objectMapper.configure(JsonParser.Feature.ALLOW_SINGLE_QUOTES, true);
|
||||
objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
|
||||
objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
|
||||
objectMapper.setAnnotationIntrospector(new JsonArrayFormat());
|
||||
|
||||
rawJsonArray = objectMapper.writeValueAsBytes(dataList);
|
||||
logger.debug("rawJsonArray Size: [{}]", FileUtils.byteCountToDisplaySize(rawJsonArray.length));
|
||||
|
||||
logger.debug("RawrawJsonArray Snappy Size: [{}]", FileUtils.byteCountToDisplaySize(Snappy.compress(rawJsonArray).length));
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue