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