use of org.apache.dubbo.common.serialize.ObjectOutput in project dubbo by alibaba.
the class AbstractSerializationTest method test_LinkedHashMap.
@Test
public void test_LinkedHashMap() throws Exception {
LinkedHashMap<String, String> data = new LinkedHashMap<String, String>();
data.put("1", "a");
data.put("2", "b");
ObjectOutput objectOutput = serialization.serialize(url, byteArrayOutputStream);
objectOutput.writeObject(data);
objectOutput.flushBuffer();
ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(byteArrayOutputStream.toByteArray());
ObjectInput deserialize = serialization.deserialize(url, byteArrayInputStream);
Object read = deserialize.readObject();
assertTrue(read instanceof LinkedHashMap);
@SuppressWarnings("unchecked") String key1 = ((LinkedHashMap<String, String>) read).entrySet().iterator().next().getKey();
assertEquals("1", key1);
assertEquals(data, read);
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_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 by alibaba.
the class AbstractSerializationTest method test_MediaContent_WithType_badStream.
@Test
public void test_MediaContent_WithType_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(MediaContent.class);
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_MultiObject.
@Test
public void test_MultiObject() 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());
assertEquals((byte) 23, deserialize.readByte());
assertEquals(mediaContent, deserialize.readObject());
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_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) {
}
}
Aggregations