Search in sources :

Example 31 with ObjectOutput

use of org.apache.dubbo.common.serialize.ObjectOutput in project dubbo by alibaba.

the class AbstractSerializationTest method test_Double.

// ================== Util methods ==================
@Test
public void test_Double() throws Exception {
    ObjectOutput objectOutput = serialization.serialize(url, byteArrayOutputStream);
    objectOutput.writeDouble(1.28);
    objectOutput.flushBuffer();
    ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(byteArrayOutputStream.toByteArray());
    ObjectInput deserialize = serialization.deserialize(url, byteArrayInputStream);
    assertEquals(1.28, deserialize.readDouble());
    try {
        deserialize.readDouble();
        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) Test(org.junit.jupiter.api.Test)

Example 32 with ObjectOutput

use of org.apache.dubbo.common.serialize.ObjectOutput 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 33 with ObjectOutput

use of org.apache.dubbo.common.serialize.ObjectOutput in project dubbo by alibaba.

the class AbstractSerializationPersonFailTest method test_IntPersonMap.

@Test
public void test_IntPersonMap() throws Exception {
    Map<Integer, Person> args = new HashMap<Integer, Person>();
    args.put(1, new Person());
    try {
        ObjectOutput objectOutput = serialization.serialize(url, byteArrayOutputStream);
        objectOutput.writeObject(args);
        fail();
    } catch (NotSerializableException expected) {
    } catch (IllegalStateException expected) {
        assertThat(expected.getMessage(), containsString(FAIL_STRING));
    }
}
Also used : NotSerializableException(java.io.NotSerializableException) ObjectOutput(org.apache.dubbo.common.serialize.ObjectOutput) HashMap(java.util.HashMap) Person(org.apache.dubbo.common.serialize.model.Person) Test(org.junit.jupiter.api.Test)

Example 34 with ObjectOutput

use of org.apache.dubbo.common.serialize.ObjectOutput in project dubbo by alibaba.

the class AbstractSerializationPersonFailTest method test_PersonList.

@Test
public void test_PersonList() throws Exception {
    List<Person> args = new ArrayList<Person>();
    args.add(new Person());
    try {
        ObjectOutput objectOutput = serialization.serialize(url, byteArrayOutputStream);
        objectOutput.writeObject(args);
        fail();
    } catch (NotSerializableException expected) {
    } catch (IllegalStateException expected) {
        assertThat(expected.getMessage(), containsString(FAIL_STRING));
    }
}
Also used : NotSerializableException(java.io.NotSerializableException) ObjectOutput(org.apache.dubbo.common.serialize.ObjectOutput) ArrayList(java.util.ArrayList) Person(org.apache.dubbo.common.serialize.model.Person) Test(org.junit.jupiter.api.Test)

Example 35 with ObjectOutput

use of org.apache.dubbo.common.serialize.ObjectOutput in project dubbo by alibaba.

the class AbstractSerializationPersonFailTest method test_StringPersonMap.

@Test
public void test_StringPersonMap() throws Exception {
    Map<String, Person> args = new HashMap<String, Person>();
    args.put("1", new Person());
    try {
        ObjectOutput objectOutput = serialization.serialize(url, byteArrayOutputStream);
        objectOutput.writeObject(args);
        fail();
    } catch (NotSerializableException expected) {
    } catch (IllegalStateException expected) {
        assertThat(expected.getMessage(), containsString(FAIL_STRING));
    }
}
Also used : NotSerializableException(java.io.NotSerializableException) ObjectOutput(org.apache.dubbo.common.serialize.ObjectOutput) HashMap(java.util.HashMap) Matchers.containsString(org.hamcrest.Matchers.containsString) Person(org.apache.dubbo.common.serialize.model.Person) Test(org.junit.jupiter.api.Test)

Aggregations

ObjectOutput (org.apache.dubbo.common.serialize.ObjectOutput)256 Test (org.junit.jupiter.api.Test)224 ByteArrayInputStream (java.io.ByteArrayInputStream)203 ObjectInput (org.apache.dubbo.common.serialize.ObjectInput)203 IOException (java.io.IOException)122 NotSerializableException (java.io.NotSerializableException)21 Person (org.apache.dubbo.common.serialize.model.Person)21 OutputStream (java.io.OutputStream)16 HashMap (java.util.HashMap)14 AbstractSerializationPersonFailTest (org.apache.dubbo.common.serialize.base.AbstractSerializationPersonFailTest)14 AbstractSerializationPersonOkTest (org.apache.dubbo.common.serialize.base.AbstractSerializationPersonOkTest)14 Serialization (org.apache.dubbo.common.serialize.Serialization)10 ByteArrayOutputStream (java.io.ByteArrayOutputStream)8 UnsafeByteArrayOutputStream (org.apache.dubbo.common.io.UnsafeByteArrayOutputStream)8 BigPerson (org.apache.dubbo.common.serialize.model.person.BigPerson)8 ArrayList (java.util.ArrayList)6 Cleanable (org.apache.dubbo.common.serialize.Cleanable)6 BizException (org.apache.dubbo.common.serialize.model.BizException)6 BizExceptionNoDefaultConstructor (org.apache.dubbo.common.serialize.model.BizExceptionNoDefaultConstructor)6 ChannelBufferOutputStream (org.apache.dubbo.remoting.buffer.ChannelBufferOutputStream)6