Search in sources :

Example 1 with GetSegmentRequest

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

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());
}
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 3 with GetSegmentRequest

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();
}
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 4 with GetSegmentRequest

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);
}
Also used : GetBlobRequest(org.apache.jackrabbit.oak.segment.standby.codec.GetBlobRequest) GetHeadRequest(org.apache.jackrabbit.oak.segment.standby.codec.GetHeadRequest) InetSocketAddress(java.net.InetSocketAddress) GetSegmentRequest(org.apache.jackrabbit.oak.segment.standby.codec.GetSegmentRequest)

Aggregations

GetSegmentRequest (org.apache.jackrabbit.oak.segment.standby.codec.GetSegmentRequest)4 EmbeddedChannel (io.netty.channel.embedded.EmbeddedChannel)2 GetSegmentResponse (org.apache.jackrabbit.oak.segment.standby.codec.GetSegmentResponse)2 Test (org.junit.Test)2 InetSocketAddress (java.net.InetSocketAddress)1 UUID (java.util.UUID)1 Nullable (javax.annotation.Nullable)1 GetBlobRequest (org.apache.jackrabbit.oak.segment.standby.codec.GetBlobRequest)1 GetHeadRequest (org.apache.jackrabbit.oak.segment.standby.codec.GetHeadRequest)1