Search in sources :

Example 41 with ObjectOutput

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

the class Hessian2SerializationTest method test_StringArray_withType.

@Test
public void test_StringArray_withType() throws Exception {
    String[] data = new String[] { "1", "b" };
    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, deserialize.readObject(String[].class));
    try {
        deserialize.readObject(String[].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 42 with ObjectOutput

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

the class Hessian2SerializationTest method test_boolArray_withType.

// Hessian2
@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 (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 43 with ObjectOutput

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

the class AbstractSerializationTest 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 (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 44 with ObjectOutput

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

the class AbstractSerializationTest method test_longArray.

@Test
public void test_longArray() 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();
        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 45 with ObjectOutput

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

the class AbstractSerializationTest method test_UtfString.

@Test
public void test_UtfString() throws Exception {
    ObjectOutput objectOutput = serialization.serialize(url, byteArrayOutputStream);
    objectOutput.writeUTF("123中华人民共和国");
    objectOutput.flushBuffer();
    ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(byteArrayOutputStream.toByteArray());
    ObjectInput deserialize = serialization.deserialize(url, byteArrayInputStream);
    assertEquals("123中华人民共和国", deserialize.readUTF());
    try {
        deserialize.readUTF();
        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)

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