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());
}
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());
}
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());
}
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());
}
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);
}
Aggregations