use of com.alibaba.dubbo.common.serialize.ObjectOutput in project dubbo by alibaba.
the class FstSerializationTest method assertObjectArray.
// ================ Array Type ================
<T> void assertObjectArray(T[] data, Class<T[]> clazz) throws Exception {
ObjectOutput objectOutput = serialization.serialize(url, byteArrayOutputStream);
objectOutput.writeObject(data);
objectOutput.flushBuffer();
ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(byteArrayOutputStream.toByteArray());
ObjectInput deserialize = serialization.deserialize(url, byteArrayInputStream);
assertArrayEquals(data, clazz.cast(deserialize.readObject()));
}
use of com.alibaba.dubbo.common.serialize.ObjectOutput in project dubbo by alibaba.
the class FstSerializationTest method assertObjectWithType.
<T> void assertObjectWithType(T data, Class<T> clazz) throws Exception {
ObjectOutput objectOutput = serialization.serialize(url, byteArrayOutputStream);
objectOutput.writeObject(data);
objectOutput.flushBuffer();
ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(byteArrayOutputStream.toByteArray());
ObjectInput deserialize = serialization.deserialize(url, byteArrayInputStream);
assertEquals(data, (T) deserialize.readObject(clazz));
}
use of com.alibaba.dubbo.common.serialize.ObjectOutput in project dubbo by alibaba.
the class FstSerializationTest method test_shortArray.
@Test
public void test_shortArray() throws Exception {
short[] data = new short[] { 37, 39, 12 };
ObjectOutput objectOutput = serialization.serialize(url, byteArrayOutputStream);
objectOutput.writeObject(data);
objectOutput.flushBuffer();
ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(byteArrayOutputStream.toByteArray());
ObjectInput deserialize = serialization.deserialize(url, byteArrayInputStream);
assertArrayEquals(data, (short[]) deserialize.readObject());
try {
deserialize.readObject();
fail();
} catch (IOException expected) {
}
}
use of com.alibaba.dubbo.common.serialize.ObjectOutput in project dubbo by alibaba.
the class FstSerializationTest method assertObject.
@SuppressWarnings("unchecked")
<T> void assertObject(T data) throws Exception {
ObjectOutput objectOutput = serialization.serialize(url, byteArrayOutputStream);
objectOutput.writeObject(data);
objectOutput.flushBuffer();
ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(byteArrayOutputStream.toByteArray());
ObjectInput deserialize = serialization.deserialize(url, byteArrayInputStream);
assertEquals(data, (T) deserialize.readObject());
}
use of com.alibaba.dubbo.common.serialize.ObjectOutput in project dubbo by alibaba.
the class FstSerializationTest method test_LoopReference.
@Test(timeout = 3000)
public void test_LoopReference() throws Exception {
Map<String, Object> map = new HashMap<String, Object>();
map.put("k1", "v1");
map.put("self", map);
ObjectOutput objectOutput = serialization.serialize(url, byteArrayOutputStream);
objectOutput.writeObject(map);
objectOutput.flushBuffer();
ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(byteArrayOutputStream.toByteArray());
ObjectInput deserialize = serialization.deserialize(url, byteArrayInputStream);
@SuppressWarnings("unchecked") Map<String, Object> output = (Map<String, Object>) deserialize.readObject();
assertEquals("v1", output.get("k1"));
assertSame(output, output.get("self"));
}
Aggregations