use of org.apache.jackrabbit.oak.segment.standby.codec.GetSegmentResponse 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.GetSegmentResponse 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.GetSegmentResponse in project jackrabbit-oak by apache.
the class GetSegmentRequestHandler method channelRead0.
@Override
protected void channelRead0(ChannelHandlerContext ctx, GetSegmentRequest msg) throws Exception {
log.debug("Reading segment {} for client {}", msg.getSegmentId(), msg.getClientId());
byte[] data = reader.readSegment(msg.getSegmentId());
if (data == null) {
log.debug("Segment {} not found, discarding request from client {}", msg.getSegmentId(), msg.getClientId());
return;
}
ctx.writeAndFlush(new GetSegmentResponse(msg.getClientId(), msg.getSegmentId(), data));
}
Aggregations