use of org.apache.dubbo.common.serialize.ObjectOutput in project dubbo-spi-extensions by apache.
the class AbstractSerializationTest method test_Byte.
@Test
public void test_Byte() throws Exception {
ObjectOutput objectOutput = serialization.serialize(url, byteArrayOutputStream);
objectOutput.writeByte((byte) 123);
objectOutput.flushBuffer();
ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(byteArrayOutputStream.toByteArray());
ObjectInput deserialize = serialization.deserialize(url, byteArrayInputStream);
assertEquals((byte) 123, deserialize.readByte());
try {
deserialize.readByte();
fail();
} catch (IOException expected) {
}
}
use of org.apache.dubbo.common.serialize.ObjectOutput in project dubbo-spi-extensions by apache.
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-spi-extensions by apache.
the class AbstractSerializationTest method test_Bool.
@Test
public void test_Bool() throws Exception {
ObjectOutput objectOutput = serialization.serialize(url, byteArrayOutputStream);
objectOutput.writeBool(false);
objectOutput.flushBuffer();
ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(byteArrayOutputStream.toByteArray());
ObjectInput deserialize = serialization.deserialize(url, byteArrayInputStream);
assertFalse(deserialize.readBool());
try {
deserialize.readBool();
fail();
} catch (IOException expected) {
}
}
use of org.apache.dubbo.common.serialize.ObjectOutput in project dubbo-spi-extensions by apache.
the class AbstractSerializationTest method test_Integer.
@Test
public void test_Integer() throws Exception {
ObjectOutput objectOutput = serialization.serialize(url, byteArrayOutputStream);
objectOutput.writeInt(1);
objectOutput.flushBuffer();
ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(byteArrayOutputStream.toByteArray());
ObjectInput deserialize = serialization.deserialize(url, byteArrayInputStream);
int i = deserialize.readInt();
assertEquals(1, i);
try {
deserialize.readInt();
fail();
} catch (IOException expected) {
}
}
use of org.apache.dubbo.common.serialize.ObjectOutput in project dubbo-spi-extensions by apache.
the class AbstractSerializationTest method test_BizException_WithType.
@Test
public void test_BizException_WithType() throws Exception {
BizException e = new BizException("Hello");
ObjectOutput objectOutput = serialization.serialize(url, byteArrayOutputStream);
objectOutput.writeObject(e);
objectOutput.flushBuffer();
ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(byteArrayOutputStream.toByteArray());
ObjectInput deserialize = serialization.deserialize(url, byteArrayInputStream);
Object read = deserialize.readObject(BizException.class);
assertEquals("Hello", ((BizException) read).getMessage());
}
Aggregations