public void testDeleteRecordWithParentCollision() throws Exception { FileDataStore fds = new FileDataStore(); fds.init(testDir + "/fileDeleteCollision"); ByteArrayInputStream c1 = new ByteArrayInputStream(ByteBuffer .allocate(8).putLong(0x181c7).array()); ByteArrayInputStream c2 = new ByteArrayInputStream(ByteBuffer .allocate(8).putLong(0x11fd78).array()); DataRecord d1 = fds.addRecord(c1); DataRecord d2 = fds.addRecord(c2); fds.deleteRecord(d1.getIdentifier()); DataRecord testRecord = fds.getRecordIfStored(d2.getIdentifier()); assertNotNull(testRecord); assertEquals(d2.getIdentifier(), testRecord.getIdentifier()); // Check the presence of the parent directory (relies on internal details of the FileDataStore) File parentDirD1 = new File( fds.getPath() + System.getProperty("file.separator") + d1.getIdentifier().toString().substring(0, 2)); assertTrue(parentDirD1.exists()); }
public void testDeleteRecordWithoutParentCollision() throws Exception { FileDataStore fds = new FileDataStore(); fds.init(testDir + "/fileDelete"); String c1 = "idhfigjhehgkdfgk"; String c2 = "02c60cb75083ceef"; DataRecord d1 = fds.addRecord(IOUtils.toInputStream(c1)); DataRecord d2 = fds.addRecord(IOUtils.toInputStream(c2)); fds.deleteRecord(d1.getIdentifier()); DataRecord testRecord = fds.getRecordIfStored(d2.getIdentifier()); assertNotNull(testRecord); assertEquals(d2.getIdentifier(), testRecord.getIdentifier()); // Check the absence of the parent directory (relies on internal details of the FileDataStore) File parentDirD1 = new File( fds.getPath() + System.getProperty("file.separator") + d1.getIdentifier().toString().substring(0, 2)); assertFalse(parentDirD1.exists()); }
public void testReference() throws Exception { byte[] data = new byte[12345]; new Random(12345).nextBytes(data); String reference; FileDataStore store = new FileDataStore(); store.init(testDir + "/reference"); try { DataRecord record = store.addRecord(new ByteArrayInputStream(data)); reference = record.getReference(); assertReference(data, reference, store); } finally { store.close(); } store = new FileDataStore(); store.init(testDir + "/reference"); try { assertReference(data, reference, store); } finally { store.close(); } }
@Test public void delegateRecordTest() throws Exception{ FileDataStore ds = new FileDataStore(); byte[] data = bytes(ds.getMinRecordLength() + 10); ds.init(tempFolder.getRoot().getAbsolutePath()); DataRecord dr = ds.addRecord(new ByteArrayInputStream(data)); File mappingFile = new File(tempFolder.getRoot(), "mapping.txt"); String text = String.format("%s|%s", data.length, dr.getIdentifier().toString()); Files.write(text, mappingFile, Charset.defaultCharset()); LengthCachingDataStore fds = new LengthCachingDataStore(); fds.setDelegateClass(FileDataStore.class.getName()); fds.setMappingFilePath(mappingFile.getAbsolutePath()); fds.init(tempFolder.getRoot().getAbsolutePath()); DataRecord dr2 = fds.getRecordIfStored(dr.getIdentifier()); assertEquals(dr, dr2); assertEquals(dr.getLength(), dr2.getLength()); assertTrue(supplier(dr).contentEquals(supplier(dr2))); }
@Test public void basicOperation() throws Exception { File fdsDir = temporaryFolder.newFolder(); FileDataStore fds = DataStoreUtils.createFDS(fdsDir, 0); ByteArrayInputStream is = new ByteArrayInputStream("hello".getBytes()); DataRecord dr = fds.addRecord(is); File writerDir = temporaryFolder.newFolder(); TextWriter writer = new DataStoreTextWriter(writerDir, false); writer.write(dr.getIdentifier().toString(), "hello"); FileDataStore fds2 = DataStoreUtils.createFDS(writerDir, 0); DataRecord dr2 = fds2.getRecordIfStored(dr.getIdentifier()); is.reset(); assertTrue(IOUtils.contentEquals(is, dr2.getStream())); }
@Test public void nonExistingEntry() throws Exception{ File fdsDir = temporaryFolder.newFolder(); FileDataStore fds = DataStoreUtils.createFDS(fdsDir, 0); ByteArrayInputStream is = new ByteArrayInputStream("hello".getBytes()); DataRecord dr = fds.addRecord(is); File writerDir = temporaryFolder.newFolder(); DataStoreTextWriter w = new DataStoreTextWriter(writerDir, false); String id = dr.getIdentifier().toString(); assertFalse(w.isProcessed(id)); assertNull(w.getText("/a", new IdBlob("foo", id))); w.write(id, "foo"); assertTrue(w.isProcessed(id)); ExtractedText et = w.getText("/a", new IdBlob("foo", id)); assertEquals("foo", et.getExtractedText()); assertEquals(ExtractionResult.SUCCESS, et.getExtractionResult()); w.markEmpty("a"); assertTrue(w.isProcessed("a")); }