Search in sources :

Example 1 with GetBlobResponse

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

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

the class GetBlobRequestHandler method channelRead0.

@Override
protected void channelRead0(ChannelHandlerContext ctx, GetBlobRequest msg) throws Exception {
    log.debug("Reading blob {} for client {}", msg.getBlobId(), msg.getClientId());
    InputStream in = reader.readBlob(msg.getBlobId());
    long length = reader.getBlobLength(msg.getBlobId());
    if (in == null || length == -1L) {
        log.debug("Blob {} not found, discarding request from client {}", msg.getBlobId(), msg.getClientId());
        return;
    }
    ctx.writeAndFlush(new GetBlobResponse(msg.getClientId(), msg.getBlobId(), in, length));
}
Also used : InputStream(java.io.InputStream) GetBlobResponse(org.apache.jackrabbit.oak.segment.standby.codec.GetBlobResponse)

Example 3 with GetBlobResponse

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

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