use of io.netty.buffer.DefaultByteBufHolder in project netty by netty.
the class Http2DefaultFramesTest method testEqualOperation.
@SuppressWarnings("SimplifiableJUnitAssertion")
@Test
public void testEqualOperation() {
// in this case, 'goAwayFrame' and 'unknownFrame' will also have an EMPTY_BUFFER data
// so we want to check that 'dflt' will not consider them equal.
DefaultHttp2GoAwayFrame goAwayFrame = new DefaultHttp2GoAwayFrame(1);
DefaultHttp2UnknownFrame unknownFrame = new DefaultHttp2UnknownFrame((byte) 1, new Http2Flags((short) 1));
DefaultByteBufHolder dflt = new DefaultByteBufHolder(Unpooled.EMPTY_BUFFER);
try {
// not using 'assertNotEquals' to be explicit about which object we are calling .equals() on
assertFalse(dflt.equals(goAwayFrame));
assertFalse(dflt.equals(unknownFrame));
} finally {
goAwayFrame.release();
unknownFrame.release();
dflt.release();
}
}
use of io.netty.buffer.DefaultByteBufHolder in project netty by netty.
the class LoggingHandlerTest method shouldLogByteBufHolderDataRead.
@Test
public void shouldLogByteBufHolderDataRead() throws Exception {
ByteBufHolder msg = new DefaultByteBufHolder(Unpooled.copiedBuffer("hello", CharsetUtil.UTF_8)) {
@Override
public String toString() {
return "foobar";
}
};
EmbeddedChannel channel = new EmbeddedChannel(new LoggingHandler());
channel.writeInbound(msg);
verify(appender).doAppend(argThat(new RegexLogMatcher(".+READ: foobar, 5B$", true)));
ByteBufHolder handledMsg = channel.readInbound();
assertThat(msg, is(sameInstance(handledMsg)));
handledMsg.release();
assertThat(channel.readInbound(), is(nullValue()));
}
use of io.netty.buffer.DefaultByteBufHolder in project rskj by rsksmart.
the class RskWebSocketJsonRpcHandlerTest method handlerPassesRequestToNextHandlerOnException.
@Test
public void handlerPassesRequestToNextHandlerOnException() throws Exception {
ChannelHandlerContext ctx = mock(ChannelHandlerContext.class);
when(serializer.deserializeRequest(any())).thenThrow(new IOException());
DefaultByteBufHolder msg = new DefaultByteBufHolder(Unpooled.copiedBuffer("raw".getBytes()));
handler.channelRead(ctx, msg);
verify(ctx, never()).writeAndFlush(any());
verify(ctx, times(1)).fireChannelRead(msg);
}
use of io.netty.buffer.DefaultByteBufHolder in project netty by netty.
the class MessageAggregatorTest method testReadFlowManagement.
@SuppressWarnings("unchecked")
@Test
public void testReadFlowManagement() throws Exception {
ReadCounter counter = new ReadCounter();
ByteBufHolder first = message("first");
ByteBufHolder chunk = message("chunk");
ByteBufHolder last = message("last");
MockMessageAggregator agg = spy(MockMessageAggregator.class);
when(agg.isStartMessage(first)).thenReturn(true);
when(agg.isContentMessage(chunk)).thenReturn(true);
when(agg.isContentMessage(last)).thenReturn(true);
when(agg.isLastContentMessage(last)).thenReturn(true);
EmbeddedChannel embedded = new EmbeddedChannel(counter, agg);
embedded.config().setAutoRead(false);
assertFalse(embedded.writeInbound(first));
assertFalse(embedded.writeInbound(chunk));
assertTrue(embedded.writeInbound(last));
// 2 reads issued from MockMessageAggregator
assertEquals(3, counter.value);
// 1 read issued from EmbeddedChannel constructor
ByteBufHolder all = new DefaultByteBufHolder(Unpooled.wrappedBuffer(first.content().retain(), chunk.content().retain(), last.content().retain()));
ByteBufHolder out = embedded.readInbound();
assertEquals(all, out);
assertTrue(all.release() && out.release());
assertFalse(embedded.finish());
}
use of io.netty.buffer.DefaultByteBufHolder in project rskj by rsksmart.
the class RskWebSocketJsonRpcHandlerTest method handlerDeserializesAndHandlesRequest.
@Test
public void handlerDeserializesAndHandlesRequest() throws Exception {
String json = "{\"jsonrpc\":\"2.0\",\"id\":\"teste\",\"method\":\"eth_subscribe\",\"params\":[\"newHeads\"]}";
Channel channel = mock(Channel.class);
ChannelHandlerContext ctx = mock(ChannelHandlerContext.class);
when(ctx.channel()).thenReturn(channel);
when(emitter.visit(any(EthSubscribeNewHeadsParams.class), eq(channel))).thenReturn(SAMPLE_SUBSCRIPTION_ID_1);
DefaultByteBufHolder msg = new DefaultByteBufHolder(Unpooled.copiedBuffer(json.getBytes()));
handler.channelRead(ctx, msg);
verify(ctx, times(1)).writeAndFlush(new TextWebSocketFrame("{\"jsonrpc\":\"2.0\",\"id\":\"teste\",\"result\":\"0x3075\"}"));
verify(ctx, never()).fireChannelRead(any());
}
Aggregations