use of org.apache.jackrabbit.oak.segment.standby.codec.GetSegmentRequest in project jackrabbit-oak by apache.
the class GetSegmentRequestHandlerTest method successfulReadsShouldGenerateResponses.
@Test
public void successfulReadsShouldGenerateResponses() throws Exception {
byte[] data = new byte[] { 3, 4, 5 };
StandbySegmentReader reader = mock(StandbySegmentReader.class);
when(reader.readSegment("segmentId")).thenReturn(data);
EmbeddedChannel channel = new EmbeddedChannel(new GetSegmentRequestHandler(reader));
channel.writeInbound(new GetSegmentRequest("clientId", "segmentId"));
GetSegmentResponse response = (GetSegmentResponse) channel.readOutbound();
assertEquals("clientId", response.getClientId());
assertEquals("segmentId", response.getSegmentId());
assertArrayEquals(data, response.getSegmentData());
}
use of org.apache.jackrabbit.oak.segment.standby.codec.GetSegmentRequest 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.jackrabbit.oak.segment.standby.codec.GetSegmentRequest in project jackrabbit-oak by apache.
the class StandbyClient method getSegment.
@Nullable
byte[] getSegment(String segmentId) throws InterruptedException {
channel.writeAndFlush(new GetSegmentRequest(clientId, segmentId));
GetSegmentResponse response = segmentQueue.poll(readTimeoutMs, TimeUnit.MILLISECONDS);
if (response == null) {
return null;
}
return response.getSegmentData();
}
use of org.apache.jackrabbit.oak.segment.standby.codec.GetSegmentRequest in project jackrabbit-oak by apache.
the class RequestObserverHandler method channelRead.
@Override
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
InetSocketAddress address = (InetSocketAddress) ctx.channel().remoteAddress();
if (msg instanceof GetHeadRequest) {
onGetHeadRequest((GetHeadRequest) msg, address);
} else if (msg instanceof GetSegmentRequest) {
onGetSegmentRequest((GetSegmentRequest) msg, address);
} else if (msg instanceof GetBlobRequest) {
onGetBlobRequest((GetBlobRequest) msg, address);
}
ctx.fireChannelRead(msg);
}
Aggregations