Search in sources :

Example 31 with EmbeddedChannel

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

the class ResponseDecoderTest method shouldDecodeValidGetBlobResponses.

@Test
public void shouldDecodeValidGetBlobResponses() throws Exception {
    byte[] blobData = new byte[] { 1, 2, 3 };
    String blobId = "blobId";
    byte[] blobIdBytes = blobId.getBytes(Charsets.UTF_8);
    ByteBuf buf = Unpooled.buffer();
    buf.writeInt(1 + 4 + blobIdBytes.length + 8 + blobData.length);
    buf.writeByte(Messages.HEADER_BLOB);
    buf.writeInt(blobIdBytes.length);
    buf.writeBytes(blobIdBytes);
    buf.writeLong(hash(blobData));
    buf.writeBytes(blobData);
    EmbeddedChannel channel = new EmbeddedChannel(new ResponseDecoder());
    channel.writeInbound(buf);
    GetBlobResponse response = (GetBlobResponse) channel.readInbound();
    assertEquals("blobId", response.getBlobId());
    assertArrayEquals(blobData, response.getBlobData());
}
Also used : EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel) ByteBuf(io.netty.buffer.ByteBuf) Test(org.junit.Test)

Example 32 with EmbeddedChannel

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

the class GetBlobRequestHandlerTest method unrecognizedMessagesShouldBeIgnored.

@Test
public void unrecognizedMessagesShouldBeIgnored() throws Exception {
    StandbyBlobReader reader = mock(StandbyBlobReader.class);
    EmbeddedChannel channel = new EmbeddedChannel(new GetBlobRequestHandler(reader));
    channel.writeInbound("unrecognized");
    assertEquals("unrecognized", channel.readInbound());
}
Also used : EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel) Test(org.junit.Test)

Example 33 with EmbeddedChannel

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

the class GetSegmentRequestHandlerTest method unsuccessfulReadsShouldBeDiscarded.

@Test
public void unsuccessfulReadsShouldBeDiscarded() throws Exception {
    UUID uuid = new UUID(1, 2);
    StandbySegmentReader reader = mock(StandbySegmentReader.class);
    when(reader.readSegment(uuid.toString())).thenReturn(null);
    EmbeddedChannel channel = new EmbeddedChannel(new GetSegmentRequestHandler(reader));
    channel.writeInbound(new GetSegmentRequest("clientId", uuid.toString()));
    assertNull(channel.readOutbound());
}
Also used : GetSegmentRequest(org.apache.jackrabbit.oak.segment.standby.codec.GetSegmentRequest) EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel) UUID(java.util.UUID) Test(org.junit.Test)

Example 34 with EmbeddedChannel

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

the class GetSegmentRequestHandlerTest method unrecognizedMessagesShouldBeIgnored.

@Test
public void unrecognizedMessagesShouldBeIgnored() throws Exception {
    StandbySegmentReader reader = mock(StandbySegmentReader.class);
    EmbeddedChannel channel = new EmbeddedChannel(new GetSegmentRequestHandler(reader));
    channel.writeInbound("unrecognized");
    assertEquals("unrecognized", channel.readInbound());
}
Also used : EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel) Test(org.junit.Test)

Example 35 with EmbeddedChannel

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

the class GetHeadResponseEncoderTest method encodeResponse.

@Test
public void encodeResponse() throws Exception {
    String recordId = "recordId";
    byte[] recordIdBytes = recordId.getBytes(Charsets.UTF_8);
    EmbeddedChannel channel = new EmbeddedChannel(new GetHeadResponseEncoder());
    channel.writeOutbound(new GetHeadResponse("clientId", "recordId"));
    ByteBuf buffer = (ByteBuf) channel.readOutbound();
    ByteBuf expected = Unpooled.buffer();
    expected.writeInt(recordIdBytes.length + 1);
    expected.writeByte(Messages.HEADER_RECORD);
    expected.writeBytes(recordIdBytes);
    assertEquals(expected, buffer);
}
Also used : EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel) ByteBuf(io.netty.buffer.ByteBuf) Test(org.junit.Test)

Aggregations

EmbeddedChannel (io.netty.channel.embedded.EmbeddedChannel)1065 Test (org.junit.jupiter.api.Test)540 ByteBuf (io.netty.buffer.ByteBuf)371 Test (org.junit.Test)342 ChannelHandlerContext (io.netty.channel.ChannelHandlerContext)88 HttpResponse (io.netty.handler.codec.http.HttpResponse)75 HttpRequest (io.netty.handler.codec.http.HttpRequest)72 DefaultFullHttpRequest (io.netty.handler.codec.http.DefaultFullHttpRequest)65 DefaultLastHttpContent (io.netty.handler.codec.http.DefaultLastHttpContent)62 FullHttpResponse (io.netty.handler.codec.http.FullHttpResponse)60 LastHttpContent (io.netty.handler.codec.http.LastHttpContent)55 FullHttpRequest (io.netty.handler.codec.http.FullHttpRequest)49 DefaultFullHttpResponse (io.netty.handler.codec.http.DefaultFullHttpResponse)47 ArrayList (java.util.ArrayList)47 EmbeddedChannel (org.apache.flink.shaded.netty4.io.netty.channel.embedded.EmbeddedChannel)42 IOException (java.io.IOException)39 InetSocketAddress (java.net.InetSocketAddress)38 Executable (org.junit.jupiter.api.function.Executable)36 Before (org.junit.Before)32 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)32