@Override public long getBlobLength(String blobId) throws IOException { return delegate.getBlobLength(blobId); }
@Test public void testIllegalIdentifier2() throws Exception { try { store.getBlobLength("ff"); fail(); } catch (Exception e) { // expected } }
@Test public void testCombinedIdentifier() throws Exception { String id = store.writeBlob(new ByteArrayInputStream(new byte[2])); assertEquals(2, store.getBlobLength(id)); String combinedId = id + id; assertEquals(4, store.getBlobLength(combinedId)); doTestRead(new byte[4], 4, combinedId); }
private void doTest(int maxLength, int count) throws Exception { String[] s = new String[count * 2]; Random r = new Random(0); for (int i = 0; i < s.length;) { byte[] data = new byte[r.nextInt(maxLength)]; r.nextBytes(data); s[i++] = store.writeBlob(new ByteArrayInputStream(data)); s[i++] = store.writeBlob(new ByteArrayInputStream(data)); } r.setSeed(0); for (int i = 0; i < s.length;) { int expectedLen = r.nextInt(maxLength); byte[] expectedData = new byte[expectedLen]; r.nextBytes(expectedData); assertEquals(expectedLen, store.getBlobLength(s[i++])); String id = s[i++]; doTestRead(expectedData, expectedLen, id); } }
public byte[] readFully(String id) throws Exception { int len = (int) store.getBlobLength(id); byte[] data; if (len < 100) { data = new byte[len]; for (int i = 0; i < len; i++) { store.readBlob(id, i, data, i, 1); } } else { data = BlobStoreInputStream.readFully(store, id); } assertEquals(len, data.length); return data; }
@Test public void testWriteFile() throws Exception { store.setBlockSize(1024 * 1024); byte[] data = new byte[4 * 1024 * 1024]; Random r = new Random(0); r.nextBytes(data); String tempFileName = "target/temp/test"; File tempFile = new File(tempFileName); tempFile.getParentFile().mkdirs(); OutputStream out = new FileOutputStream(tempFile, false); out.write(data); out.close(); String s = store.writeBlob(tempFileName); assertEquals(data.length, store.getBlobLength(s)); byte[] buff = new byte[1]; for (int i = 0; i < data.length; i += 1024) { store.readBlob(s, i, buff, 0, 1); assertEquals(data[i], buff[0]); } try { store.writeBlob(tempFileName + "_wrong"); fail(); } catch (Exception e) { // expected } }
@Test public void testEmptyIdentifier() throws Exception { byte[] data = new byte[1]; assertEquals(-1, store.readBlob("", 0, data, 0, 1)); assertEquals(0, store.getBlobLength("")); }
} else { store.getBlobLength(id); int failedCount = 0; for (String id : map.keySet()) { long length = store.getBlobLength(id); try { readFully(id);