Search in sources :

Example 1 with BigPerson

use of org.apache.dubbo.common.serialize.model.person.BigPerson 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) {
    }
}
Also used : ObjectOutput(org.apache.dubbo.common.serialize.ObjectOutput) ByteArrayInputStream(java.io.ByteArrayInputStream) MediaContent(org.apache.dubbo.common.serialize.model.media.MediaContent) ObjectInput(org.apache.dubbo.common.serialize.ObjectInput) IOException(java.io.IOException) BigPerson(org.apache.dubbo.common.serialize.model.person.BigPerson) Test(org.junit.jupiter.api.Test)

Example 2 with BigPerson

use of org.apache.dubbo.common.serialize.model.person.BigPerson in project dubbo by alibaba.

the class KryoSerialization2Test method testObjectWithAttachments.

@Test
public void testObjectWithAttachments() throws IOException, ClassNotFoundException {
    ObjectOutput objectOutput = serialization.serialize(url, byteArrayOutputStream);
    objectOutput.writeObject(bigPerson);
    Map<String, Object> attachments = new HashMap<>();
    attachments.put("attachments", "attachments");
    objectOutput.writeObject(attachments);
    objectOutput.flushBuffer();
    ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(byteArrayOutputStream.toByteArray());
    ObjectInput deserialize = serialization.deserialize(url, byteArrayInputStream);
    assertEquals(bigPerson, BigPerson.class.cast(deserialize.readObject(BigPerson.class)));
    assertEquals(attachments, deserialize.readAttachments());
    try {
        deserialize.readObject(BigPerson.class);
        fail();
    } catch (IOException expected) {
    }
}
Also used : ObjectOutput(org.apache.dubbo.common.serialize.ObjectOutput) HashMap(java.util.HashMap) ByteArrayInputStream(java.io.ByteArrayInputStream) ObjectInput(org.apache.dubbo.common.serialize.ObjectInput) IOException(java.io.IOException) BigPerson(org.apache.dubbo.common.serialize.model.person.BigPerson) Test(org.junit.jupiter.api.Test)

Example 3 with BigPerson

use of org.apache.dubbo.common.serialize.model.person.BigPerson in project dubbo by alibaba.

the class KryoSerialization2Test method testObject.

@Test
public void testObject() throws IOException, ClassNotFoundException {
    ObjectOutput objectOutput = serialization.serialize(url, byteArrayOutputStream);
    objectOutput.writeObject(bigPerson);
    objectOutput.flushBuffer();
    ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(byteArrayOutputStream.toByteArray());
    ObjectInput deserialize = serialization.deserialize(url, byteArrayInputStream);
    assertEquals(bigPerson, BigPerson.class.cast(deserialize.readObject(BigPerson.class)));
    try {
        deserialize.readObject(BigPerson.class);
        fail();
    } catch (IOException expected) {
    }
}
Also used : ObjectOutput(org.apache.dubbo.common.serialize.ObjectOutput) ByteArrayInputStream(java.io.ByteArrayInputStream) ObjectInput(org.apache.dubbo.common.serialize.ObjectInput) IOException(java.io.IOException) BigPerson(org.apache.dubbo.common.serialize.model.person.BigPerson) Test(org.junit.jupiter.api.Test)

Aggregations

ByteArrayInputStream (java.io.ByteArrayInputStream)3 IOException (java.io.IOException)3 ObjectInput (org.apache.dubbo.common.serialize.ObjectInput)3 ObjectOutput (org.apache.dubbo.common.serialize.ObjectOutput)3 BigPerson (org.apache.dubbo.common.serialize.model.person.BigPerson)3 Test (org.junit.jupiter.api.Test)3 HashMap (java.util.HashMap)1 MediaContent (org.apache.dubbo.common.serialize.model.media.MediaContent)1