use of org.apache.dubbo.common.serialize.ObjectOutput in project dubbo by alibaba.
the class AbstractSerializationTest method test_Byte_Multi.
@Test
public void test_Byte_Multi() throws Exception {
byte[] array = new byte[100];
random.nextBytes(array);
ObjectOutput objectOutput = serialization.serialize(url, byteArrayOutputStream);
for (byte b : array) {
objectOutput.writeByte(b);
}
objectOutput.flushBuffer();
ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(byteArrayOutputStream.toByteArray());
ObjectInput deserialize = serialization.deserialize(url, byteArrayInputStream);
for (byte b : array) {
assertEquals(b, deserialize.readByte());
}
try {
deserialize.readByte();
fail();
} catch (IOException expected) {
}
}
use of org.apache.dubbo.common.serialize.ObjectOutput in project dubbo by alibaba.
the class AbstractSerializationTest method test_LoopReference.
@Test
public void test_LoopReference() throws Exception {
assertTimeout(ofMillis(3000), () -> {
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"));
});
}
use of org.apache.dubbo.common.serialize.ObjectOutput in project dubbo by alibaba.
the class AbstractSerializationTest method test_MultiObject_WithType.
@Test
public void test_MultiObject_WithType() throws Exception {
ObjectOutput objectOutput = serialization.serialize(url, byteArrayOutputStream);
objectOutput.writeBool(false);
objectOutput.writeObject(bigPerson);
objectOutput.writeByte((byte) 23);
objectOutput.writeObject(mediaContent);
objectOutput.writeInt(-23);
objectOutput.flushBuffer();
ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(byteArrayOutputStream.toByteArray());
ObjectInput deserialize = serialization.deserialize(url, byteArrayInputStream);
assertFalse(deserialize.readBool());
assertEquals(bigPerson, deserialize.readObject(BigPerson.class));
assertEquals((byte) 23, deserialize.readByte());
assertEquals(mediaContent, deserialize.readObject(MediaContent.class));
assertEquals(-23, deserialize.readInt());
try {
deserialize.readObject();
fail();
} catch (IOException expected) {
}
}
use of org.apache.dubbo.common.serialize.ObjectOutput in project dubbo by alibaba.
the class AbstractSerializationTest method test_Bytes.
@Test
public void test_Bytes() throws Exception {
ObjectOutput objectOutput = serialization.serialize(url, byteArrayOutputStream);
objectOutput.writeBytes("123中华人民共和国".getBytes());
objectOutput.flushBuffer();
ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(byteArrayOutputStream.toByteArray());
ObjectInput deserialize = serialization.deserialize(url, byteArrayInputStream);
assertArrayEquals("123中华人民共和国".getBytes(), deserialize.readBytes());
try {
deserialize.readBytes();
fail();
} catch (IOException expected) {
}
}
use of org.apache.dubbo.common.serialize.ObjectOutput in project dubbo by alibaba.
the class AbstractSerializationTest method test_charArray.
@Test
public void test_charArray() throws Exception {
char[] data = new char[] { 'a', '中', '无' };
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, (char[]) deserialize.readObject());
try {
deserialize.readObject();
fail();
} catch (IOException expected) {
}
}
Aggregations