@Test public void testMessageReceivedDelimiterFrame() throws Exception { final ChannelBuffer buf = ChannelBuffers.copiedBuffer("<45>", Charsets.UTF_8); when(event.getMessage()).thenReturn(buf); handler.handleUpstream(context, event); handler.handleUpstream(context, event); handler.handleUpstream(context, event); // Only add the decoder once! verify(pipeline, times(1)) .addAfter(eq("current"), eq("framer-delimiter"), any(DelimiterBasedFrameDecoder.class)); verify(context, times(3)).sendUpstream(event); // Make sure the buffer does not get mutated. assertEquals(buf.toString(Charsets.UTF_8), "<45>"); }
@Test public void testMessageReceivedWithEmptyBuffer() throws Exception { final ChannelBuffer buf = ChannelBuffers.copiedBuffer("", Charsets.UTF_8); when(event.getMessage()).thenReturn(buf); handler.handleUpstream(context, event); verify(pipeline, never()) .addAfter(eq("current"), eq("framer-octet"), any(SyslogOctetCountFrameDecoder.class)); verify(pipeline, never()) .addAfter(eq("current"), eq("framer-delimiter"), any(DelimiterBasedFrameDecoder.class)); verify(context, never()).sendUpstream(event); }