Search in sources :

Example 51 with ObjectOutput

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

the class SerializationTest method testObjectOutput.

@Test
public void testObjectOutput() throws IOException {
    ObjectOutput objectOutput = mySerialization.serialize(null, mock(OutputStream.class));
    assertThat(objectOutput, Matchers.<ObjectOutput>instanceOf(MyObjectOutput.class));
}
Also used : ObjectOutput(org.apache.dubbo.common.serialize.ObjectOutput) OutputStream(java.io.OutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Test(org.junit.jupiter.api.Test)

Example 52 with ObjectOutput

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

the class FastJsonSerializationTest method testObjectOutput.

@Test
public void testObjectOutput() throws IOException {
    ObjectOutput objectOutput = fastJsonSerialization.serialize(null, mock(OutputStream.class));
    assertThat(objectOutput, Matchers.<ObjectOutput>instanceOf(FastJsonObjectOutput.class));
}
Also used : ObjectOutput(org.apache.dubbo.common.serialize.ObjectOutput) OutputStream(java.io.OutputStream) Test(org.junit.jupiter.api.Test)

Example 53 with ObjectOutput

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

the class Hessian2SerializationTest method test_shortArray_withType.

@Test
public void test_shortArray_withType() throws Exception {
    short[] data = new short[] { 37, 39, 12 };
    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, (short[]) deserialize.readObject(short[].class));
    try {
        deserialize.readObject(short[].class);
        fail();
    } catch (ArrayIndexOutOfBoundsException e) {
    }
// NOTE: Hessian2 throws ArrayIndexOutOfBoundsException instead of IOException, let's live with this.
}
Also used : ObjectOutput(org.apache.dubbo.common.serialize.ObjectOutput) ByteArrayInputStream(java.io.ByteArrayInputStream) ObjectInput(org.apache.dubbo.common.serialize.ObjectInput) Test(org.junit.jupiter.api.Test) AbstractSerializationPersonFailTest(org.apache.dubbo.common.serialize.base.AbstractSerializationPersonFailTest)

Example 54 with ObjectOutput

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

the class Hessian2SerializationTest method test_floatArray_withType.

@Test
public void test_floatArray_withType() throws Exception {
    float[] data = new float[] { 37F, -3.14F, 123456.7F };
    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, (float[]) deserialize.readObject(), 0.0001F);
    try {
        deserialize.readObject(float[].class);
        fail();
    } catch (ArrayIndexOutOfBoundsException e) {
    }
// NOTE: Hessian2 throws ArrayIndexOutOfBoundsException instead of IOException, let's live with this.
}
Also used : ObjectOutput(org.apache.dubbo.common.serialize.ObjectOutput) ByteArrayInputStream(java.io.ByteArrayInputStream) ObjectInput(org.apache.dubbo.common.serialize.ObjectInput) Test(org.junit.jupiter.api.Test) AbstractSerializationPersonFailTest(org.apache.dubbo.common.serialize.base.AbstractSerializationPersonFailTest)

Example 55 with ObjectOutput

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

the class Hessian2SerializationTest method test_doubleArray_withType.

@Test
public void test_doubleArray_withType() throws Exception {
    double[] data = new double[] { 37D, -3.14D, 123456.7D };
    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, (double[]) deserialize.readObject(double[].class), 0.0001);
    try {
        deserialize.readObject(double[].class);
        fail();
    } catch (ArrayIndexOutOfBoundsException e) {
    }
// NOTE: Hessian2 throws ArrayIndexOutOfBoundsException instead of IOException, let's live with this.
}
Also used : ObjectOutput(org.apache.dubbo.common.serialize.ObjectOutput) ByteArrayInputStream(java.io.ByteArrayInputStream) ObjectInput(org.apache.dubbo.common.serialize.ObjectInput) Test(org.junit.jupiter.api.Test) AbstractSerializationPersonFailTest(org.apache.dubbo.common.serialize.base.AbstractSerializationPersonFailTest)

Aggregations

ObjectOutput (org.apache.dubbo.common.serialize.ObjectOutput)94 Test (org.junit.jupiter.api.Test)80 ByteArrayInputStream (java.io.ByteArrayInputStream)73 ObjectInput (org.apache.dubbo.common.serialize.ObjectInput)73 IOException (java.io.IOException)42 NotSerializableException (java.io.NotSerializableException)7 AbstractSerializationPersonFailTest (org.apache.dubbo.common.serialize.base.AbstractSerializationPersonFailTest)7 AbstractSerializationPersonOkTest (org.apache.dubbo.common.serialize.base.AbstractSerializationPersonOkTest)7 Person (org.apache.dubbo.common.serialize.model.Person)7 OutputStream (java.io.OutputStream)6 HashMap (java.util.HashMap)6 Serialization (org.apache.dubbo.common.serialize.Serialization)5 ByteArrayOutputStream (java.io.ByteArrayOutputStream)4 UnsafeByteArrayOutputStream (org.apache.dubbo.common.io.UnsafeByteArrayOutputStream)4 ArrayList (java.util.ArrayList)3 Cleanable (org.apache.dubbo.common.serialize.Cleanable)3 BigPerson (org.apache.dubbo.common.serialize.model.person.BigPerson)3 ChannelBufferOutputStream (org.apache.dubbo.remoting.buffer.ChannelBufferOutputStream)3 LinkedHashMap (java.util.LinkedHashMap)2 List (java.util.List)2