use of com.alibaba.dubbo.remoting.Channel in project dubbo by alibaba.
the class ExchangeCodecTest method test_Encode_Request.
@Test
public void test_Encode_Request() throws IOException {
ChannelBuffer encodeBuffer = ChannelBuffers.dynamicBuffer(2014);
Channel channel = getCliendSideChannel(url);
Request request = new Request();
Person person = new Person();
request.setData(person);
codec.encode(channel, encodeBuffer, request);
// encode resault check need decode
byte[] data = new byte[encodeBuffer.writerIndex()];
encodeBuffer.readBytes(data);
ChannelBuffer decodeBuffer = ChannelBuffers.wrappedBuffer(data);
Request obj = (Request) codec.decode(channel, decodeBuffer);
Assert.assertEquals(request.isBroken(), obj.isBroken());
Assert.assertEquals(request.isHeartbeat(), obj.isHeartbeat());
Assert.assertEquals(request.isTwoWay(), obj.isTwoWay());
Assert.assertEquals(person, obj.getData());
}
use of com.alibaba.dubbo.remoting.Channel in project dubbo by alibaba.
the class TelnetCodecTest method testDecode_WithExitByte.
private void testDecode_WithExitByte(byte[] exitbytes, boolean isChannelClose) throws IOException {
// init channel
Channel channel = getServerSideChannel(url);
ChannelBuffer buffer = ChannelBuffers.wrappedBuffer(exitbytes);
// decode
codec.decode(channel, buffer);
Assert.assertEquals(isChannelClose, channel.isClosed());
}
use of com.alibaba.dubbo.remoting.Channel in project dubbo by alibaba.
the class TelnetCodecTest method testDecode_PersonWithEnterByte.
private void testDecode_PersonWithEnterByte(byte[] enterbytes, boolean isNeedmore) throws IOException {
// init channel
Channel channel = getServerSideChannel(url);
// init request string
Person request = new Person();
byte[] newbuf = join(objectToByte(request), enterbytes);
ChannelBuffer buffer = ChannelBuffers.wrappedBuffer(newbuf);
// decode
Object obj = codec.decode(channel, buffer);
if (isNeedmore) {
Assert.assertEquals(Codec2.DecodeResult.NEED_MORE_INPUT, obj);
} else {
Assert.assertTrue("return must string ", obj instanceof String);
}
}
use of com.alibaba.dubbo.remoting.Channel in project dubbo by alibaba.
the class TelnetCodecTest method testDecode_assertEquals.
protected void testDecode_assertEquals(byte[] request, Object ret, boolean isServerside) throws IOException {
// init channel
Channel channel = isServerside ? getServerSideChannel(url) : getCliendSideChannel(url);
// init request string
ChannelBuffer buffer = ChannelBuffers.wrappedBuffer(request);
// decode
Object obj = codec.decode(channel, buffer);
Assert.assertEquals(ret, obj);
}
use of com.alibaba.dubbo.remoting.Channel in project dubbo by alibaba.
the class HeaderExchangeHandlerTest method test_received_request_twoway_error_reply.
@Test
public void test_received_request_twoway_error_reply() throws RemotingException {
final Person requestdata = new Person("charles");
final Request request = new Request();
request.setTwoWay(true);
request.setData(requestdata);
final AtomicInteger count = new AtomicInteger(0);
final Channel mchannel = new MockedChannel() {
@Override
public void send(Object message) throws RemotingException {
Response res = (Response) message;
Assert.assertEquals(request.getId(), res.getId());
Assert.assertEquals(request.getVersion(), res.getVersion());
Assert.assertEquals(Response.SERVICE_ERROR, res.getStatus());
Assert.assertNull(res.getResult());
Assert.assertTrue(res.getErrorMessage().contains(BizException.class.getName()));
count.incrementAndGet();
}
};
ExchangeHandler exhandler = new MockedExchangeHandler() {
@Override
public Object reply(ExchangeChannel channel, Object request) throws RemotingException {
throw new BizException();
}
};
HeaderExchangeHandler hexhandler = new HeaderExchangeHandler(exhandler);
hexhandler.received(mchannel, request);
Assert.assertEquals(1, count.get());
}
Aggregations