Search in sources :

Example 21 with Response

use of com.alibaba.dubbo.remoting.exchange.Response in project dubbo by alibaba.

the class ExchangeCodecTest method test_Header_Response_Heartbeat.

@Test
public void test_Header_Response_Heartbeat() throws IOException {
    // 00000010-response/oneway/hearbeat=true |20-stats=ok|id=0|length=0
    byte[] header = new byte[] { MAGIC_HIGH, MAGIC_LOW, 0x02, 20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
    Person person = new Person();
    byte[] request = getRequestBytes(person, header);
    Response obj = (Response) decode(request);
    Assert.assertEquals(20, obj.getStatus());
    Assert.assertEquals(person, obj.getResult());
    System.out.println(obj);
}
Also used : Response(com.alibaba.dubbo.remoting.exchange.Response) Test(org.junit.Test)

Example 22 with Response

use of com.alibaba.dubbo.remoting.exchange.Response in project dubbo by alibaba.

the class ExchangeCodecTest method test_Encode_Response.

@Test
public void test_Encode_Response() throws IOException {
    ChannelBuffer encodeBuffer = ChannelBuffers.dynamicBuffer(1024);
    Channel channel = getCliendSideChannel(url);
    Response response = new Response();
    response.setHeartbeat(true);
    response.setId(1001l);
    response.setStatus((byte) 20);
    response.setVersion("11");
    Person person = new Person();
    response.setResult(person);
    codec.encode(channel, encodeBuffer, response);
    byte[] data = new byte[encodeBuffer.writerIndex()];
    encodeBuffer.readBytes(data);
    // encode resault check need decode
    ChannelBuffer decodeBuffer = ChannelBuffers.wrappedBuffer(data);
    Response obj = (Response) codec.decode(channel, decodeBuffer);
    Assert.assertEquals(response.getId(), obj.getId());
    Assert.assertEquals(response.getStatus(), obj.getStatus());
    Assert.assertEquals(response.isHeartbeat(), obj.isHeartbeat());
    Assert.assertEquals(person, obj.getResult());
// encode response verson ??
// Assert.assertEquals(response.getVersion(), obj.getVersion());
}
Also used : Response(com.alibaba.dubbo.remoting.exchange.Response) Channel(com.alibaba.dubbo.remoting.Channel) ChannelBuffer(com.alibaba.dubbo.remoting.buffer.ChannelBuffer) Test(org.junit.Test)

Example 23 with Response

use of com.alibaba.dubbo.remoting.exchange.Response in project dubbo by alibaba.

the class ExchangeCodecTest method test_Header_Response_NoSerializationFlag.

@Test
public void test_Header_Response_NoSerializationFlag() throws IOException {
    // 00000010-response/oneway/hearbeat=false/noset |20-stats=ok|id=0|length=0
    byte[] header = new byte[] { MAGIC_HIGH, MAGIC_LOW, (byte) 0x02, 20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
    Person person = new Person();
    byte[] request = getRequestBytes(person, header);
    Response obj = (Response) decode(request);
    Assert.assertEquals(20, obj.getStatus());
    Assert.assertEquals(person, obj.getResult());
    System.out.println(obj);
}
Also used : Response(com.alibaba.dubbo.remoting.exchange.Response) Test(org.junit.Test)

Example 24 with Response

use of com.alibaba.dubbo.remoting.exchange.Response in project dubbo by alibaba.

the class ExchangeCodecTest method test_Decode_Return_Response_Person.

@Test
public void test_Decode_Return_Response_Person() throws IOException {
    // 00000010-response/oneway/hearbeat=false/hessian |20-stats=ok|id=0|length=0
    byte[] header = new byte[] { MAGIC_HIGH, MAGIC_LOW, 2, 20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
    Person person = new Person();
    byte[] request = getRequestBytes(person, header);
    Response obj = (Response) decode(request);
    Assert.assertEquals(20, obj.getStatus());
    Assert.assertEquals(person, obj.getResult());
    System.out.println(obj);
}
Also used : Response(com.alibaba.dubbo.remoting.exchange.Response) Test(org.junit.Test)

Example 25 with Response

use of com.alibaba.dubbo.remoting.exchange.Response in project dubbo by alibaba.

the class ExchangeCodecTest method test_Decode_Error_Length.

@Test
public void test_Decode_Error_Length() throws IOException {
    byte[] header = new byte[] { MAGIC_HIGH, MAGIC_LOW, 0x02, 20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
    Person person = new Person();
    byte[] request = getRequestBytes(person, header);
    Channel channel = getServerSideChannel(url);
    byte[] baddata = new byte[] { 1, 2 };
    ChannelBuffer buffer = ChannelBuffers.wrappedBuffer(join(request, baddata));
    Response obj = (Response) codec.decode(channel, buffer);
    Assert.assertEquals(person, obj.getResult());
    // only decode necessary bytes
    Assert.assertEquals(request.length, buffer.readerIndex());
}
Also used : Response(com.alibaba.dubbo.remoting.exchange.Response) Channel(com.alibaba.dubbo.remoting.Channel) ChannelBuffer(com.alibaba.dubbo.remoting.buffer.ChannelBuffer) Test(org.junit.Test)

Aggregations

Response (com.alibaba.dubbo.remoting.exchange.Response)31 Request (com.alibaba.dubbo.remoting.exchange.Request)18 Test (org.junit.Test)17 Channel (com.alibaba.dubbo.remoting.Channel)10 ChannelBuffer (com.alibaba.dubbo.remoting.buffer.ChannelBuffer)8 RemotingException (com.alibaba.dubbo.remoting.RemotingException)6 Serialization (com.alibaba.dubbo.common.serialize.Serialization)5 ExchangeChannel (com.alibaba.dubbo.remoting.exchange.ExchangeChannel)5 RpcResult (com.alibaba.dubbo.rpc.RpcResult)5 TMessage (org.apache.thrift.protocol.TMessage)5 URL (com.alibaba.dubbo.common.URL)4 Demo (com.alibaba.dubbo.rpc.gen.thrift.Demo)4 IOException (java.io.IOException)4 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)4 TBinaryProtocol (org.apache.thrift.protocol.TBinaryProtocol)4 TIOStreamTransport (org.apache.thrift.transport.TIOStreamTransport)4 HeaderExchangeHandler (com.alibaba.dubbo.remoting.exchange.support.header.HeaderExchangeHandler)3 TApplicationException (org.apache.thrift.TApplicationException)3 ObjectInput (com.alibaba.dubbo.common.serialize.ObjectInput)2 ObjectOutput (com.alibaba.dubbo.common.serialize.ObjectOutput)2