use of org.apache.dubbo.remoting.Channel in project dubbo by alibaba.
the class TelnetCodecTest method testEecode_assertEquals.
protected void testEecode_assertEquals(Object request, byte[] ret, boolean isServerside) throws IOException {
// init channel
Channel channel = isServerside ? getServerSideChannel(url) : getCliendSideChannel(url);
ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(1024);
codec.encode(channel, buffer, request);
byte[] data = new byte[buffer.readableBytes()];
buffer.readBytes(data);
Assertions.assertEquals(ret.length, data.length);
for (int i = 0; i < ret.length; i++) {
if (ret[i] != data[i]) {
Assertions.fail();
}
}
}
use of org.apache.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) {
Assertions.assertEquals(Codec2.DecodeResult.NEED_MORE_INPUT, obj);
} else {
Assertions.assertTrue(obj instanceof String, "return must string ");
}
}
use of org.apache.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);
Assertions.assertEquals(ret, obj);
}
use of org.apache.dubbo.remoting.Channel in project dubbo by alibaba.
the class ExchangeCodecTest method test_Encode_Error_Response.
@Test
public void test_Encode_Error_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) 10);
response.setVersion("11");
String badString = "bad";
response.setErrorMessage(badString);
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);
Assertions.assertEquals(response.getId(), obj.getId());
Assertions.assertEquals(response.getStatus(), obj.getStatus());
Assertions.assertEquals(response.isHeartbeat(), obj.isHeartbeat());
Assertions.assertEquals(badString, obj.getErrorMessage());
Assertions.assertNull(obj.getResult());
// Assertions.assertEquals(response.getProtocolVersion(), obj.getVersion());
}
use of org.apache.dubbo.remoting.Channel in project dubbo by alibaba.
the class HeaderExchangeHandlerTest method test_received_request_oneway.
@Test
public void test_received_request_oneway() throws RemotingException {
final Channel mchannel = new MockedChannel();
final Person requestdata = new Person("charles");
Request request = new Request();
request.setTwoWay(false);
request.setData(requestdata);
ExchangeHandler exhandler = new MockedExchangeHandler() {
@Override
public void received(Channel channel, Object message) throws RemotingException {
Assertions.assertEquals(requestdata, message);
}
};
HeaderExchangeHandler hexhandler = new HeaderExchangeHandler(exhandler);
hexhandler.received(mchannel, request);
}
Aggregations