Search in sources :

Example 1 with GetBlobRequest

use of org.apache.jackrabbit.oak.segment.standby.codec.GetBlobRequest in project jackrabbit-oak by apache.

the class StandbyClient method getBlob.

@Nullable
InputStream getBlob(String blobId) throws InterruptedException {
    channel.writeAndFlush(new GetBlobRequest(clientId, blobId));
    GetBlobResponse response = blobQueue.poll(readTimeoutMs, TimeUnit.MILLISECONDS);
    if (response == null) {
        return null;
    }
    return response.getInputStream();
}
Also used : GetBlobRequest(org.apache.jackrabbit.oak.segment.standby.codec.GetBlobRequest) GetBlobResponse(org.apache.jackrabbit.oak.segment.standby.codec.GetBlobResponse) Nullable(javax.annotation.Nullable)

Example 2 with GetBlobRequest

use of org.apache.jackrabbit.oak.segment.standby.codec.GetBlobRequest 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)

Example 3 with GetBlobRequest

use of org.apache.jackrabbit.oak.segment.standby.codec.GetBlobRequest in project jackrabbit-oak by apache.

the class GetBlobRequestHandlerTest method unsuccessfulReadsShouldBeDiscarded.

@Test
public void unsuccessfulReadsShouldBeDiscarded() throws Exception {
    StandbyBlobReader reader = mock(StandbyBlobReader.class);
    when(reader.readBlob("blobId")).thenReturn(null);
    EmbeddedChannel channel = new EmbeddedChannel(new GetBlobRequestHandler(reader));
    channel.writeInbound(new GetBlobRequest("clientId", "blobId"));
    assertNull(channel.readOutbound());
}
Also used : GetBlobRequest(org.apache.jackrabbit.oak.segment.standby.codec.GetBlobRequest) EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel) Test(org.junit.Test)

Example 4 with GetBlobRequest

use of org.apache.jackrabbit.oak.segment.standby.codec.GetBlobRequest in project jackrabbit-oak by apache.

the class GetBlobRequestHandlerTest method successfulReadsShouldGenerateResponses.

@Test
public void successfulReadsShouldGenerateResponses() throws Exception {
    byte[] blobData = new byte[] { 99, 114, 97, 112 };
    StandbyBlobReader reader = mock(StandbyBlobReader.class);
    when(reader.readBlob("blobId")).thenReturn(new ByteArrayInputStream(blobData));
    when(reader.getBlobLength("blobId")).thenReturn(4L);
    EmbeddedChannel channel = new EmbeddedChannel(new GetBlobRequestHandler(reader));
    channel.writeInbound(new GetBlobRequest("clientId", "blobId"));
    GetBlobResponse response = (GetBlobResponse) channel.readOutbound();
    assertEquals("clientId", response.getClientId());
    assertEquals("blobId", response.getBlobId());
    assertEquals(blobData.length, response.getLength());
    try (InputStream is = response.getInputStream()) {
        byte[] receivedData = IOUtils.toByteArray(is);
        assertArrayEquals(blobData, receivedData);
    }
}
Also used : GetBlobRequest(org.apache.jackrabbit.oak.segment.standby.codec.GetBlobRequest) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel) GetBlobResponse(org.apache.jackrabbit.oak.segment.standby.codec.GetBlobResponse) Test(org.junit.Test)

Aggregations

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