Search in sources :

Example 71 with EmbeddedChannel

use of org.apache.flink.shaded.netty4.io.netty.channel.embedded.EmbeddedChannel in project jocean-http by isdom.

the class DefaultHttpTradeTestCase method testTradeForFullRequestSourceAndDumpFullRequests.

@Test
public final void testTradeForFullRequestSourceAndDumpFullRequests() throws IOException {
    final DefaultFullHttpRequest request = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.POST, "/", Nettys4Test.buildByteBuf(REQ_CONTENT));
    final EmbeddedChannel channel = new EmbeddedChannel();
    final HttpTrade trade = new DefaultHttpTrade(channel);
    writeToInboundAndFlush(channel, request);
    // expected refCnt, request -- 1 + HttpMessageHolder -- 1, total refcnt is 2
    // TODO, why 4 & 5 refCnt ?
    callByteBufHolderBuilderOnceAndAssertDumpContentAndRefCnt(trade.inbound().compose(RxNettys.message2fullreq(trade)).toBlocking().single().unwrap(), REQ_CONTENT.getBytes(Charsets.UTF_8), 4);
    callByteBufHolderBuilderOnceAndAssertDumpContentAndRefCnt(trade.inbound().compose(RxNettys.message2fullreq(trade)).toBlocking().single().unwrap(), REQ_CONTENT.getBytes(Charsets.UTF_8), 5);
}
Also used : HttpTrade(org.jocean.http.server.HttpServerBuilder.HttpTrade) DefaultFullHttpRequest(io.netty.handler.codec.http.DefaultFullHttpRequest) EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel) Nettys4Test(org.jocean.http.util.Nettys4Test) Test(org.junit.Test)

Example 72 with EmbeddedChannel

use of org.apache.flink.shaded.netty4.io.netty.channel.embedded.EmbeddedChannel in project jocean-http by isdom.

the class DefaultHttpTradeTestCase method testTradeForRequestAndLastContentSourceAndDumpFullRequests.

@Test
public final void testTradeForRequestAndLastContentSourceAndDumpFullRequests() throws IOException {
    final DefaultHttpRequest request = new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.POST, "/");
    final LastHttpContent lastcontent = new DefaultLastHttpContent(Nettys4Test.buildByteBuf(REQ_CONTENT));
    final EmbeddedChannel channel = new EmbeddedChannel();
    final HttpTrade trade = new DefaultHttpTrade(channel);
    writeToInboundAndFlush(channel, request);
    writeToInboundAndFlush(channel, lastcontent);
    // final Func0<FullHttpRequest> fullRequestBuilder =
    // trade.inboundHolder().fullOf(RxNettys.BUILD_FULL_REQUEST);
    // expected refCnt, request -- 1 + HttpMessageHolder -- 1, total refcnt is 2
    // TODO, why 4 & 5 refCnt ?
    callByteBufHolderBuilderOnceAndAssertDumpContentAndRefCnt(trade.inbound().compose(RxNettys.message2fullreq(trade)).toBlocking().single().unwrap(), REQ_CONTENT.getBytes(Charsets.UTF_8), 4);
    callByteBufHolderBuilderOnceAndAssertDumpContentAndRefCnt(trade.inbound().compose(RxNettys.message2fullreq(trade)).toBlocking().single().unwrap(), REQ_CONTENT.getBytes(Charsets.UTF_8), 5);
}
Also used : HttpTrade(org.jocean.http.server.HttpServerBuilder.HttpTrade) DefaultLastHttpContent(io.netty.handler.codec.http.DefaultLastHttpContent) DefaultHttpRequest(io.netty.handler.codec.http.DefaultHttpRequest) EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel) LastHttpContent(io.netty.handler.codec.http.LastHttpContent) DefaultLastHttpContent(io.netty.handler.codec.http.DefaultLastHttpContent) Nettys4Test(org.jocean.http.util.Nettys4Test) Test(org.junit.Test)

Example 73 with EmbeddedChannel

use of org.apache.flink.shaded.netty4.io.netty.channel.embedded.EmbeddedChannel in project alliance by codice.

the class RawUdpDataToMTSPacketDecoderTest method testCorruptedData.

@SuppressWarnings("unchecked")
@Test
public void testCorruptedData() throws Exception {
    RawUdpDataToMTSPacketDecoder.MTSParser mtsParser = mock(RawUdpDataToMTSPacketDecoder.MTSParser.class);
    ResettableMTSSource resettable = mock(ResettableMTSSource.class);
    Mockito.when(mtsParser.parse(Mockito.any())).thenReturn(resettable);
    MTSPacket mtsPacket = mock(MTSPacket.class);
    Mockito.when(resettable.nextPacket()).thenThrow(RuntimeException.class).thenReturn(mtsPacket);
    int packetCount = 2;
    List<DatagramPacket> datagramPackets = toDatagrams(flatten(createTsPackets(packetCount)));
    PacketBuffer packetBuffer = mock(PacketBuffer.class);
    RawUdpDataToMTSPacketDecoder rawUdpDataToMTSPacketDecoder = new RawUdpDataToMTSPacketDecoder(packetBuffer, mock(UdpStreamProcessor.class));
    rawUdpDataToMTSPacketDecoder.setMtsParser(mtsParser);
    EmbeddedChannel channel = new EmbeddedChannel(rawUdpDataToMTSPacketDecoder);
    datagramPackets.forEach(channel::writeInbound);
    List<Object> outputList = NettyUtility.read(channel);
    assertThat(outputList, hasSize(packetCount - 1));
}
Also used : EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel) MTSPacket(org.taktik.mpegts.MTSPacket) DatagramPacket(io.netty.channel.socket.DatagramPacket) ResettableMTSSource(org.taktik.mpegts.sources.ResettableMTSSource) Test(org.junit.Test)

Example 74 with EmbeddedChannel

use of org.apache.flink.shaded.netty4.io.netty.channel.embedded.EmbeddedChannel in project alliance by codice.

the class RawUdpDataToMTSPacketDecoderTest method test.

@Test
public void test() throws Exception {
    int packetCount = 100;
    List<DatagramPacket> datagramPackets = toDatagrams(flatten(createTsPackets(packetCount)));
    PacketBuffer packetBuffer = mock(PacketBuffer.class);
    EmbeddedChannel channel = new EmbeddedChannel(new RawUdpDataToMTSPacketDecoder(packetBuffer, mock(UdpStreamProcessor.class)));
    datagramPackets.forEach(channel::writeInbound);
    List<Object> outputList = NettyUtility.read(channel);
    assertThat(outputList, hasSize(packetCount));
}
Also used : DatagramPacket(io.netty.channel.socket.DatagramPacket) EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel) Test(org.junit.Test)

Example 75 with EmbeddedChannel

use of org.apache.flink.shaded.netty4.io.netty.channel.embedded.EmbeddedChannel in project sidewinder by srotya.

the class TestGraphiteDecoder method testHandler.

@Test
public void testHandler() throws IOException {
    EmbeddedChannel ch = new EmbeddedChannel(new StringDecoder(), new GraphiteDecoder("test", engine, null));
    ch.writeInbound(Unpooled.copiedBuffer("app1.server1.jvm.heap.max 233123 1497720452", Charset.defaultCharset()));
    ch.readInbound();
    verify(engine, times(1)).writeDataPoint("test", "heap", "max", Arrays.asList("app1", "server1", "jvm"), ((long) 1497720452) * 1000, 233123);
    ch.close();
}
Also used : EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel) StringDecoder(io.netty.handler.codec.string.StringDecoder) Test(org.junit.Test)

Aggregations

EmbeddedChannel (io.netty.channel.embedded.EmbeddedChannel)1027 Test (org.junit.jupiter.api.Test)515 ByteBuf (io.netty.buffer.ByteBuf)356 Test (org.junit.Test)342 ChannelHandlerContext (io.netty.channel.ChannelHandlerContext)85 HttpResponse (io.netty.handler.codec.http.HttpResponse)73 HttpRequest (io.netty.handler.codec.http.HttpRequest)69 DefaultFullHttpRequest (io.netty.handler.codec.http.DefaultFullHttpRequest)64 FullHttpResponse (io.netty.handler.codec.http.FullHttpResponse)60 DefaultLastHttpContent (io.netty.handler.codec.http.DefaultLastHttpContent)55 LastHttpContent (io.netty.handler.codec.http.LastHttpContent)50 FullHttpRequest (io.netty.handler.codec.http.FullHttpRequest)49 DefaultFullHttpResponse (io.netty.handler.codec.http.DefaultFullHttpResponse)46 EmbeddedChannel (org.apache.flink.shaded.netty4.io.netty.channel.embedded.EmbeddedChannel)42 IOException (java.io.IOException)38 InetSocketAddress (java.net.InetSocketAddress)38 Executable (org.junit.jupiter.api.function.Executable)36 ArrayList (java.util.ArrayList)35 Before (org.junit.Before)32 ChannelHandler (io.netty.channel.ChannelHandler)27