Search in sources :

Example 21 with ObjectInput

use of com.alibaba.dubbo.common.serialize.ObjectInput in project dubbo by alibaba.

the class FstSerializationTest 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) {
    }
}
Also used : ObjectOutput(com.alibaba.dubbo.common.serialize.ObjectOutput) ByteArrayInputStream(java.io.ByteArrayInputStream) ObjectInput(com.alibaba.dubbo.common.serialize.ObjectInput) IOException(java.io.IOException) LinkedHashMap(java.util.LinkedHashMap) Test(org.junit.Test)

Example 22 with ObjectInput

use of com.alibaba.dubbo.common.serialize.ObjectInput in project dubbo by alibaba.

the class FstSerializationTest method test_longArray_withType.

@Test
public void test_longArray_withType() 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(long[].class));
    try {
        deserialize.readObject(long[].class);
        fail();
    } catch (IOException expected) {
    }
}
Also used : ObjectOutput(com.alibaba.dubbo.common.serialize.ObjectOutput) ByteArrayInputStream(java.io.ByteArrayInputStream) ObjectInput(com.alibaba.dubbo.common.serialize.ObjectInput) IOException(java.io.IOException) Test(org.junit.Test)

Example 23 with ObjectInput

use of com.alibaba.dubbo.common.serialize.ObjectInput in project dubbo by alibaba.

the class FstSerializationTest method test_doubleArray.

@Test
public void test_doubleArray() 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(), 0.0001);
    try {
        deserialize.readObject();
        fail();
    } catch (IOException expected) {
    }
}
Also used : ObjectOutput(com.alibaba.dubbo.common.serialize.ObjectOutput) ByteArrayInputStream(java.io.ByteArrayInputStream) ObjectInput(com.alibaba.dubbo.common.serialize.ObjectInput) IOException(java.io.IOException) Test(org.junit.Test)

Example 24 with ObjectInput

use of com.alibaba.dubbo.common.serialize.ObjectInput in project dubbo by alibaba.

the class FstSerializationTest method test_BizException.

@Test
public void test_BizException() throws Exception {
    BizException e = new BizException("Hello");
    ObjectOutput objectOutput = serialization.serialize(url, byteArrayOutputStream);
    objectOutput.writeObject(e);
    objectOutput.flushBuffer();
    ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(byteArrayOutputStream.toByteArray());
    ObjectInput deserialize = serialization.deserialize(url, byteArrayInputStream);
    Object read = deserialize.readObject();
    assertEquals("Hello", ((BizException) read).getMessage());
}
Also used : ObjectOutput(com.alibaba.dubbo.common.serialize.ObjectOutput) ByteArrayInputStream(java.io.ByteArrayInputStream) BizException(com.alibaba.dubbo.common.model.BizException) ObjectInput(com.alibaba.dubbo.common.serialize.ObjectInput) Test(org.junit.Test)

Example 25 with ObjectInput

use of com.alibaba.dubbo.common.serialize.ObjectInput in project dubbo by alibaba.

the class FstSerializationTest method test_BizExceptionNoDefaultConstructor.

@Test
public void test_BizExceptionNoDefaultConstructor() throws Exception {
    BizExceptionNoDefaultConstructor e = new BizExceptionNoDefaultConstructor("Hello");
    ObjectOutput objectOutput = serialization.serialize(url, byteArrayOutputStream);
    objectOutput.writeObject(e);
    objectOutput.flushBuffer();
    ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(byteArrayOutputStream.toByteArray());
    ObjectInput deserialize = serialization.deserialize(url, byteArrayInputStream);
    Object read = deserialize.readObject();
    assertEquals("Hello", ((BizExceptionNoDefaultConstructor) read).getMessage());
}
Also used : ObjectOutput(com.alibaba.dubbo.common.serialize.ObjectOutput) ByteArrayInputStream(java.io.ByteArrayInputStream) ObjectInput(com.alibaba.dubbo.common.serialize.ObjectInput) BizExceptionNoDefaultConstructor(com.alibaba.dubbo.common.model.BizExceptionNoDefaultConstructor) Test(org.junit.Test)

Aggregations

ObjectInput (com.alibaba.dubbo.common.serialize.ObjectInput)97 ObjectOutput (com.alibaba.dubbo.common.serialize.ObjectOutput)92 ByteArrayInputStream (java.io.ByteArrayInputStream)92 Test (org.junit.Test)83 IOException (java.io.IOException)59 BizException (com.alibaba.dubbo.common.model.BizException)4 BizExceptionNoDefaultConstructor (com.alibaba.dubbo.common.model.BizExceptionNoDefaultConstructor)4 LinkedHashMap (java.util.LinkedHashMap)4 Cleanable (com.alibaba.dubbo.common.serialize.Cleanable)3 HashMap (java.util.HashMap)3 Map (java.util.Map)3 URL (com.alibaba.dubbo.common.URL)2 MediaContent (com.alibaba.dubbo.common.model.media.MediaContent)2 BigPerson (com.alibaba.dubbo.common.model.person.BigPerson)2 Serialization (com.alibaba.dubbo.common.serialize.Serialization)2 Request (com.alibaba.dubbo.remoting.exchange.Request)2 Response (com.alibaba.dubbo.remoting.exchange.Response)2 JSONException (com.alibaba.fastjson.JSONException)2 ChannelBufferInputStream (com.alibaba.dubbo.remoting.buffer.ChannelBufferInputStream)1 Invocation (com.alibaba.dubbo.rpc.Invocation)1