Search in sources :

Example 16 with UnsafeByteArrayOutputStream

use of com.alibaba.dubbo.common.io.UnsafeByteArrayOutputStream in project dubbo by alibaba.

the class BuilderTest method testEnumBuilder.

@Test
public void testEnumBuilder() throws Exception {
    Builder<Type> builder = Builder.register(Type.class);
    UnsafeByteArrayOutputStream os = new UnsafeByteArrayOutputStream();
    Type v = Type.High;
    builder.writeTo(v, os);
    byte[] b = os.toByteArray();
    System.out.println(b.length + ":" + Bytes.bytes2hex(b));
    v = builder.parseFrom(b);
}
Also used : UnsafeByteArrayOutputStream(com.alibaba.dubbo.common.io.UnsafeByteArrayOutputStream) Test(org.junit.Test)

Example 17 with UnsafeByteArrayOutputStream

use of com.alibaba.dubbo.common.io.UnsafeByteArrayOutputStream in project dubbo by alibaba.

the class BuilderTest method testSerializableBean.

@Test
@SuppressWarnings("unchecked")
public void testSerializableBean() throws Exception {
    System.out.println("testSerializableBean");
    UnsafeByteArrayOutputStream os = new UnsafeByteArrayOutputStream();
    SerializableBean sb = new SerializableBean();
    Builder<SerializableBean> sbb = Builder.register(SerializableBean.class);
    sbb.writeTo(sb, os);
    byte[] b = os.toByteArray();
    System.out.println(b.length + ":" + Bytes.bytes2hex(b));
    assertEquals(sbb.parseFrom(os.toByteArray()), sb);
}
Also used : UnsafeByteArrayOutputStream(com.alibaba.dubbo.common.io.UnsafeByteArrayOutputStream) Test(org.junit.Test)

Example 18 with UnsafeByteArrayOutputStream

use of com.alibaba.dubbo.common.io.UnsafeByteArrayOutputStream in project dubbo by alibaba.

the class BuilderTest method testThrowableBuilder.

@Test
public void testThrowableBuilder() throws Exception {
    Builder<Throwable> builder = Builder.register(Throwable.class);
    Throwable th = new Throwable();
    UnsafeByteArrayOutputStream os = new UnsafeByteArrayOutputStream();
    builder.writeTo(th, os);
    byte[] b = os.toByteArray();
    System.out.println(b.length + ":" + Bytes.bytes2hex(b));
    th = builder.parseFrom(b);
}
Also used : UnsafeByteArrayOutputStream(com.alibaba.dubbo.common.io.UnsafeByteArrayOutputStream) Test(org.junit.Test)

Example 19 with UnsafeByteArrayOutputStream

use of com.alibaba.dubbo.common.io.UnsafeByteArrayOutputStream in project dubbo by alibaba.

the class BuilderTest method testInterfaceBuilder.

@Test
public void testInterfaceBuilder() throws Exception {
    UnsafeByteArrayOutputStream os = new UnsafeByteArrayOutputStream();
    Builder<TestDO> builder = Builder.register(TestDO.class);
    TestDO d = new TestDOImpl();
    builder.writeTo(d, os);
    byte[] b = os.toByteArray();
    d = builder.parseFrom(b);
    assertTrue(TestDO.class.isAssignableFrom(d.getClass()));
    assertEquals("name", d.getName());
    assertEquals(28, d.getArg());
    assertEquals(Type.High, d.getType());
}
Also used : UnsafeByteArrayOutputStream(com.alibaba.dubbo.common.io.UnsafeByteArrayOutputStream) Test(org.junit.Test)

Aggregations

UnsafeByteArrayOutputStream (com.alibaba.dubbo.common.io.UnsafeByteArrayOutputStream)19 Test (org.junit.Test)13 ObjectOutput (com.alibaba.dubbo.common.serialize.ObjectOutput)3 Serialization (com.alibaba.dubbo.common.serialize.Serialization)3 UnsafeByteArrayInputStream (com.alibaba.dubbo.common.io.UnsafeByteArrayInputStream)2 IOException (java.io.IOException)2 JavaBeanDescriptor (com.alibaba.dubbo.common.beanutil.JavaBeanDescriptor)1 DataInput (com.alibaba.dubbo.common.serialize.DataInput)1 DataOutput (com.alibaba.dubbo.common.serialize.DataOutput)1 GenericDataInput (com.alibaba.dubbo.common.serialize.support.dubbo.GenericDataInput)1 GenericDataOutput (com.alibaba.dubbo.common.serialize.support.dubbo.GenericDataOutput)1 RemotingException (com.alibaba.dubbo.remoting.RemotingException)1 Response (com.alibaba.dubbo.remoting.exchange.Response)1 Result (com.alibaba.dubbo.rpc.Result)1 RpcException (com.alibaba.dubbo.rpc.RpcException)1 RpcInvocation (com.alibaba.dubbo.rpc.RpcInvocation)1 RpcResult (com.alibaba.dubbo.rpc.RpcResult)1 GenericException (com.alibaba.dubbo.rpc.service.GenericException)1 Method (java.lang.reflect.Method)1 HashMap (java.util.HashMap)1