use of com.alibaba.dubbo.remoting.buffer.ChannelBuffer 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);
Assert.assertEquals(ret.length, data.length);
for (int i = 0; i < ret.length; i++) {
if (ret[i] != data[i]) {
Assert.fail();
}
}
}
use of com.alibaba.dubbo.remoting.buffer.ChannelBuffer in project dubbo by alibaba.
the class GrizzlyCodecAdapter method handleWrite.
@Override
public NextAction handleWrite(FilterChainContext context) throws IOException {
Connection<?> connection = context.getConnection();
GrizzlyChannel channel = GrizzlyChannel.getOrAddChannel(connection, url, handler);
try {
// Do not need to close
ChannelBuffer channelBuffer = ChannelBuffers.dynamicBuffer(1024);
Object msg = context.getMessage();
codec.encode(channel, channelBuffer, msg);
GrizzlyChannel.removeChannelIfDisconnectd(connection);
Buffer buffer = connection.getTransport().getMemoryManager().allocate(channelBuffer.readableBytes());
buffer.put(channelBuffer.toByteBuffer());
buffer.flip();
buffer.allowBufferDispose(true);
context.setMessage(buffer);
} finally {
GrizzlyChannel.removeChannelIfDisconnectd(connection);
}
return context.getInvokeAction();
}
use of com.alibaba.dubbo.remoting.buffer.ChannelBuffer in project dubbo by alibaba.
the class ExchangeCodecTest method decode.
private Object decode(byte[] request) throws IOException {
ChannelBuffer buffer = ChannelBuffers.wrappedBuffer(request);
AbstractMockChannel channel = getServerSideChannel(url);
// decode
Object obj = codec.decode(channel, buffer);
return obj;
}
use of com.alibaba.dubbo.remoting.buffer.ChannelBuffer 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());
}
use of com.alibaba.dubbo.remoting.buffer.ChannelBuffer in project dubbo by alibaba.
the class ExchangeCodecTest method test_Decode_MigicCodec_Contain_ExchangeHeader.
@Test
public void test_Decode_MigicCodec_Contain_ExchangeHeader() throws IOException {
byte[] header = new byte[] { 0, 0, MAGIC_HIGH, MAGIC_LOW, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
Channel channel = getServerSideChannel(url);
ChannelBuffer buffer = ChannelBuffers.wrappedBuffer(header);
Object obj = codec.decode(channel, buffer);
Assert.assertEquals(TelnetCodec.DecodeResult.NEED_MORE_INPUT, obj);
// If the telnet data and request data are in the same data packet, we should guarantee that the receipt of request data won't be affected by the factor that telnet does not have an end characters.
Assert.assertEquals(2, buffer.readerIndex());
}
Aggregations