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