@Override public int readBlob(String encodedBlobId, long pos, byte[] buff, int off, int length) throws IOException { //This is inefficient as repeated calls for same blobId would involve opening new Stream //instead clients should directly access the stream from DataRecord by special casing for //BlobStore which implements DataStore InputStream stream = getInputStream(encodedBlobId); boolean threw = true; try { ByteStreams.skipFully(stream, pos); int readCount = stream.read(buff, off, length); threw = false; return readCount; } finally { Closeables.close(stream, threw); } }
@Override public int readBlob(String encodedBlobId, long pos, byte[] buff, int off, int length) throws IOException { //This is inefficient as repeated calls for same blobId would involve opening new Stream //instead clients should directly access the stream from DataRecord by special casing for //BlobStore which implements DataStore InputStream stream = getInputStream(encodedBlobId); boolean threw = true; try { ByteStreams.skipFully(stream, pos); int readCount = stream.read(buff, off, length); threw = false; return readCount; } finally { Closeables.close(stream, threw); } }
@Override public int readBlob(String encodedBlobId, long pos, byte[] buff, int off, int length) throws IOException { //This is inefficient as repeated calls for same blobId would involve opening new Stream //instead clients should directly access the stream from DataRecord by special casing for //BlobStore which implements DataStore InputStream stream = getInputStream(encodedBlobId); boolean threw = true; try { ByteStreams.skipFully(stream, pos); int readCount = stream.read(buff, off, length); threw = false; return readCount; } finally { Closeables.close(stream, threw); } }
@Test public void testAddOnTrackError() throws Exception { int maxInlineSize = 300; byte[] data = new byte[maxInlineSize]; new Random().nextBytes(data); DataStore mockedDS = mock(DataStore.class); when(mockedDS.getMinRecordLength()).thenReturn(maxInlineSize); DataStoreBlobStore ds = new DataStoreBlobStore(mockedDS); BlobIdTracker mockedTracker = mock(BlobIdTracker.class); doThrow(new IOException("Mocking tracking error")).when(mockedTracker).add(any(String.class)); ds.addTracker(mockedTracker); String id = ds.writeBlob(new ByteArrayInputStream(data)); assertTrue(IOUtils.contentEquals(new ByteArrayInputStream(data), ds.getInputStream(id))); }
@Test public void testDataStoreBlob() throws Exception { FileDataStore fds = createFileDataStore(); DataStoreBlobStore dbs = new DataStoreBlobStore(fds); nodeStore = getNodeStore(dbs); //Test for Blob which get inlined Blob b1 = testCreateAndRead(createBlob(fds.getMinRecordLength()-2)); assertTrue(b1 instanceof SegmentBlob); assertNull(((SegmentBlob) b1).getBlobId()); //Test for Blob which need to be pushed to BlobStore byte[] data2 = new byte[Segment.MEDIUM_LIMIT + 1]; new Random().nextBytes(data2); Blob b2 = testCreateAndRead(nodeStore.createBlob(new ByteArrayInputStream(data2))); assertTrue(b2 instanceof SegmentBlob); assertNotNull(b2.getReference()); assertEquals(b2.getContentIdentity(), ((SegmentBlob) b2).getBlobId()); InputStream is = dbs.getInputStream(((SegmentBlob) b2).getBlobId()); assertNotNull(IOUtils.contentEquals(new ByteArrayInputStream(data2), is)); is.close(); }