use of com.alibaba.dubbo.common.serialize.ObjectInput in project dubbo by alibaba.
the class AbstractSerializationTest method test_intArray.
@Test
public void test_intArray() throws Exception {
int[] data = new int[] { 234, 0, -1 };
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, (int[]) deserialize.readObject());
try {
deserialize.readObject();
fail();
} catch (IOException expected) {
}
}
use of com.alibaba.dubbo.common.serialize.ObjectInput in project dubbo by alibaba.
the class AbstractSerializationTest method assertObjectArrayWithType.
<T> void assertObjectArrayWithType(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(clazz)));
try {
deserialize.readObject(clazz);
fail();
} catch (IOException expected) {
}
}
use of com.alibaba.dubbo.common.serialize.ObjectInput in project dubbo by alibaba.
the class AbstractSerializationTest method test_BizException.
@Test
public void test_BizException() 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();
assertEquals("Hello", ((BizException) read).getMessage());
}
use of com.alibaba.dubbo.common.serialize.ObjectInput 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 com.alibaba.dubbo.common.serialize.ObjectInput in project dubbo by alibaba.
the class AbstractSerializationTest method test_Float.
@Test
public void test_Float() throws Exception {
ObjectOutput objectOutput = serialization.serialize(url, byteArrayOutputStream);
objectOutput.writeFloat(1.28F);
objectOutput.flushBuffer();
ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(byteArrayOutputStream.toByteArray());
ObjectInput deserialize = serialization.deserialize(url, byteArrayInputStream);
assertTrue(1.28F == deserialize.readFloat());
try {
deserialize.readFloat();
fail();
} catch (IOException expected) {
}
}
Aggregations