Search in sources :

Example 1 with GetSegmentResponse

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());
}
Also used : GetSegmentResponse(org.apache.jackrabbit.oak.segment.standby.codec.GetSegmentResponse) GetSegmentRequest(org.apache.jackrabbit.oak.segment.standby.codec.GetSegmentRequest) EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel) Test(org.junit.Test)

Example 2 with GetSegmentResponse

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();
}
Also used : GetSegmentResponse(org.apache.jackrabbit.oak.segment.standby.codec.GetSegmentResponse) GetSegmentRequest(org.apache.jackrabbit.oak.segment.standby.codec.GetSegmentRequest) Nullable(javax.annotation.Nullable)

Example 3 with GetSegmentResponse

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));
}
Also used : GetSegmentResponse(org.apache.jackrabbit.oak.segment.standby.codec.GetSegmentResponse)

Aggregations

GetSegmentResponse (org.apache.jackrabbit.oak.segment.standby.codec.GetSegmentResponse)3 GetSegmentRequest (org.apache.jackrabbit.oak.segment.standby.codec.GetSegmentRequest)2 EmbeddedChannel (io.netty.channel.embedded.EmbeddedChannel)1 Nullable (javax.annotation.Nullable)1 Test (org.junit.Test)1