Search in sources :

Example 56 with EmbeddedChannel

use of org.apache.flink.shaded.netty4.io.netty.channel.embedded.EmbeddedChannel in project jackrabbit-oak by apache.

the class ResponseDecoderTest method shouldDropGetReferencesResponsesWithoutDelimiter.

@Test
public void shouldDropGetReferencesResponsesWithoutDelimiter() throws Exception {
    byte[] data = "a".getBytes(Charsets.UTF_8);
    ByteBuf buf = Unpooled.buffer();
    buf.writeInt(data.length + 1);
    buf.writeByte(Messages.HEADER_REFERENCES);
    buf.writeBytes(data);
    EmbeddedChannel channel = new EmbeddedChannel(new ResponseDecoder(folder.newFolder()));
    channel.writeInbound(buf);
    assertNull(channel.readInbound());
}
Also used : EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel) ByteBuf(io.netty.buffer.ByteBuf) Test(org.junit.Test)

Example 57 with EmbeddedChannel

use of org.apache.flink.shaded.netty4.io.netty.channel.embedded.EmbeddedChannel in project jackrabbit-oak by apache.

the class ResponseDecoderTest method shouldDropInvalidGetSegmentResponses.

@Test
public void shouldDropInvalidGetSegmentResponses() throws Exception {
    UUID uuid = new UUID(1, 2);
    byte[] data = new byte[] { 3, 4, 5 };
    ByteBuf buf = Unpooled.buffer();
    buf.writeInt(data.length + 25);
    buf.writeByte(Messages.HEADER_SEGMENT);
    buf.writeLong(uuid.getMostSignificantBits());
    buf.writeLong(uuid.getLeastSignificantBits());
    buf.writeLong(hash(data) + 1);
    buf.writeBytes(data);
    EmbeddedChannel channel = new EmbeddedChannel(new ResponseDecoder(folder.newFolder()));
    channel.writeInbound(buf);
    assertNull(channel.readInbound());
}
Also used : EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel) UUID(java.util.UUID) ByteBuf(io.netty.buffer.ByteBuf) Test(org.junit.Test)

Example 58 with EmbeddedChannel

use of org.apache.flink.shaded.netty4.io.netty.channel.embedded.EmbeddedChannel in project jackrabbit-oak by apache.

the class ResponseDecoderTest method shouldDecodeValidSingleElementGetReferencesResponses.

@Test
public void shouldDecodeValidSingleElementGetReferencesResponses() throws Exception {
    byte[] data = "a:b".getBytes(Charsets.UTF_8);
    ByteBuf buf = Unpooled.buffer();
    buf.writeInt(data.length + 1);
    buf.writeByte(Messages.HEADER_REFERENCES);
    buf.writeBytes(data);
    EmbeddedChannel channel = new EmbeddedChannel(new ResponseDecoder(folder.newFolder()));
    channel.writeInbound(buf);
    GetReferencesResponse response = (GetReferencesResponse) channel.readInbound();
    assertEquals("a", response.getSegmentId());
    assertTrue(elementsEqual(newArrayList("b"), response.getReferences()));
}
Also used : EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel) ByteBuf(io.netty.buffer.ByteBuf) Test(org.junit.Test)

Example 59 with EmbeddedChannel

use of org.apache.flink.shaded.netty4.io.netty.channel.embedded.EmbeddedChannel in project jackrabbit-oak by apache.

the class ResponseDecoderTest method unrecognizedMessagesShouldBeDropped.

@Test
public void unrecognizedMessagesShouldBeDropped() throws Exception {
    ByteBuf buf = Unpooled.buffer();
    buf.writeInt(1);
    buf.writeByte(-1);
    EmbeddedChannel channel = new EmbeddedChannel(new ResponseDecoder(folder.newFolder()));
    channel.writeInbound(buf);
    assertNull(channel.readInbound());
}
Also used : EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel) ByteBuf(io.netty.buffer.ByteBuf) Test(org.junit.Test)

Example 60 with EmbeddedChannel

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

the class DefaultHttpTradeTestCase method testTradeForCallAbortBeforeRequestPublish.

// TODO: fix
@Test
public final void testTradeForCallAbortBeforeRequestPublish() {
    final DefaultFullHttpRequest request = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.POST, "/", Nettys4Test.buildByteBuf("testcontent"));
    final EmbeddedChannel channel = new EmbeddedChannel();
    final HttpTrade trade = new DefaultHttpTrade(channel);
    final TestSubscriber<DisposableWrapper<HttpObject>> reqSubscriber = new TestSubscriber<>();
    trade.inbound().subscribe(reqSubscriber);
    trade.close();
    assertTrue(!trade.isActive());
    reqSubscriber.assertTerminalEvent();
    reqSubscriber.assertError(Exception.class);
    writeToInboundAndFlush(channel, request);
    reqSubscriber.assertValueCount(0);
}
Also used : HttpTrade(org.jocean.http.server.HttpServerBuilder.HttpTrade) DefaultFullHttpRequest(io.netty.handler.codec.http.DefaultFullHttpRequest) DisposableWrapper(org.jocean.idiom.DisposableWrapper) EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel) TestSubscriber(rx.observers.TestSubscriber) Nettys4Test(org.jocean.http.util.Nettys4Test) 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