Search in sources :

Example 76 with ObjectInput

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

the class AbstractProtobufSerializationTest 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 (Exception expected) {
        expected.printStackTrace();
    }
}
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)

Example 77 with ObjectInput

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

the class AbstractProtobufSerializationTest method testPbMap.

/**
 * Special test case
 * Dubbo protocol will directly writes native map (Invocation.attachments) using protobuf.
 * this should definitely be fixed but not done yet.
 */
@Test
public void testPbMap() throws Exception {
    Map<String, Object> attachments = new HashMap<>();
    attachments.put("key", "value");
    ObjectOutput objectOutput = serialization.serialize(url, byteArrayOutputStream);
    objectOutput.writeAttachments(attachments);
    objectOutput.flushBuffer();
    ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(byteArrayOutputStream.toByteArray());
    ObjectInput objectInput = serialization.deserialize(url, byteArrayInputStream);
    Map<String, Object> derializedAttachments = objectInput.readAttachments();
    assertEquals(attachments, derializedAttachments);
}
Also used : ObjectOutput(org.apache.dubbo.common.serialize.ObjectOutput) HashMap(java.util.HashMap) ByteArrayInputStream(java.io.ByteArrayInputStream) ObjectInput(org.apache.dubbo.common.serialize.ObjectInput) Test(org.junit.jupiter.api.Test)

Example 78 with ObjectInput

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

the class AbstractProtobufSerializationTest method testPbNormal.

@Test
public void testPbNormal() throws Exception {
    ProtobufUtils.marshaller(GooglePB.PBRequestType.getDefaultInstance());
    GooglePB.PBRequestType request = buildPbMessage();
    ObjectOutput objectOutput = serialization.serialize(url, byteArrayOutputStream);
    objectOutput.writeObject(request);
    objectOutput.flushBuffer();
    ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(byteArrayOutputStream.toByteArray());
    ObjectInput objectInput = serialization.deserialize(url, byteArrayInputStream);
    GooglePB.PBRequestType derializedRequest = objectInput.readObject(GooglePB.PBRequestType.class);
    assertEquals(request, derializedRequest);
}
Also used : GooglePB(org.apache.dubbo.common.serialize.protobuf.support.model.GooglePB) ObjectOutput(org.apache.dubbo.common.serialize.ObjectOutput) ByteArrayInputStream(java.io.ByteArrayInputStream) ObjectInput(org.apache.dubbo.common.serialize.ObjectInput) Test(org.junit.jupiter.api.Test)

Example 79 with ObjectInput

use of org.apache.dubbo.common.serialize.ObjectInput 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)

Example 80 with ObjectInput

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

the class AvroSerializationTest method testObjectInput.

@Test
public void testObjectInput() throws IOException {
    ObjectInput objectInput = avroSerialization.deserialize(null, mock(InputStream.class));
    assertThat(objectInput, Matchers.<ObjectInput>instanceOf(AvroObjectInput.class));
}
Also used : InputStream(java.io.InputStream) ObjectInput(org.apache.dubbo.common.serialize.ObjectInput) Test(org.junit.jupiter.api.Test)

Aggregations

ObjectInput (org.apache.dubbo.common.serialize.ObjectInput)84 ByteArrayInputStream (java.io.ByteArrayInputStream)76 Test (org.junit.jupiter.api.Test)74 ObjectOutput (org.apache.dubbo.common.serialize.ObjectOutput)73 IOException (java.io.IOException)42 AbstractSerializationPersonFailTest (org.apache.dubbo.common.serialize.base.AbstractSerializationPersonFailTest)7 AbstractSerializationPersonOkTest (org.apache.dubbo.common.serialize.base.AbstractSerializationPersonOkTest)7 InputStream (java.io.InputStream)6 HashMap (java.util.HashMap)3 Cleanable (org.apache.dubbo.common.serialize.Cleanable)3 BigPerson (org.apache.dubbo.common.serialize.model.person.BigPerson)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 LinkedHashMap (java.util.LinkedHashMap)2 GenericObjectPoolConfig (org.apache.commons.pool2.impl.GenericObjectPoolConfig)2 URL (org.apache.dubbo.common.URL)2 Serialization (org.apache.dubbo.common.serialize.Serialization)2 BizException (org.apache.dubbo.common.serialize.model.BizException)2 BizExceptionNoDefaultConstructor (org.apache.dubbo.common.serialize.model.BizExceptionNoDefaultConstructor)2 Request (org.apache.dubbo.remoting.exchange.Request)2 Response (org.apache.dubbo.remoting.exchange.Response)2