use of org.apache.dubbo.common.serialize.ObjectOutput in project dubbo by alibaba.
the class Hessian2SerializationTest method test_longArray_withType.
@Test
public void test_longArray_withType() throws Exception {
long[] data = new long[] { 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, (long[]) deserialize.readObject());
try {
deserialize.readObject(long[].class);
fail();
} catch (ArrayIndexOutOfBoundsException e) {
}
// NOTE: Hessian2 throws ArrayIndexOutOfBoundsException instead of IOException, let's live with this.
}
use of org.apache.dubbo.common.serialize.ObjectOutput in project dubbo by alibaba.
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());
}
use of org.apache.dubbo.common.serialize.ObjectOutput in project dubbo by alibaba.
the class AbstractSerializationTest method test_boolArray_withType.
@Test
public void test_boolArray_withType() throws Exception {
boolean[] data = new boolean[] { true, false, true };
ObjectOutput objectOutput = serialization.serialize(url, byteArrayOutputStream);
objectOutput.writeObject(data);
objectOutput.flushBuffer();
ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(byteArrayOutputStream.toByteArray());
ObjectInput deserialize = serialization.deserialize(url, byteArrayInputStream);
assertTrue(Arrays.equals(data, (boolean[]) deserialize.readObject(boolean[].class)));
try {
deserialize.readObject(boolean[].class);
fail();
} catch (IOException expected) {
}
}
use of org.apache.dubbo.common.serialize.ObjectOutput in project dubbo by alibaba.
the class AbstractSerializationTest method test_MediaContent_badStream.
// abnormal case
@Test
public void test_MediaContent_badStream() throws Exception {
ObjectOutput objectOutput = serialization.serialize(url, byteArrayOutputStream);
objectOutput.writeObject(mediaContent);
objectOutput.flushBuffer();
byte[] byteArray = byteArrayOutputStream.toByteArray();
for (int i = 0; i < byteArray.length; i++) {
if (i % 3 == 0) {
byteArray[i] = (byte) ~byteArray[i];
}
}
ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(byteArray);
try {
ObjectInput deserialize = serialization.deserialize(url, byteArrayInputStream);
// local variable, convenient for debug
@SuppressWarnings("unused") Object read = deserialize.readObject();
fail();
} catch (IOException expected) {
System.out.println(expected);
}
}
use of org.apache.dubbo.common.serialize.ObjectOutput 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) {
}
}
Aggregations