@Override public BlobStore setUp() { fds = new FileDataStore(); fds.setMinRecordLength(4092); storeDir = new File(basedir, unique); fds.init(storeDir.getAbsolutePath()); configure(fds); DataStoreBlobStore bs = new DataStoreBlobStore(fds, true, fdsCacheInMB); bs.setBlobStatsCollector(new BlobStoreStats(statisticsProvider)); configure(bs); return bs; }
private DataStoreBlobStore createDataStore() { FileDataStore fds = new OakFileDataStore(); fds.setPath(dir.getAbsolutePath()); fds.setMinRecordLength(maxInlineSize); fds.init(null); return new DataStoreBlobStore(fds); }
@Override public void close() throws IOException { store.close(); } };
public DataStore getDataStore() throws RepositoryException { FileDataStore datastore=new FileDataStore(); datastore.setPath(""+repoHomeDir+"/repository/datastore"); datastore.setMinRecordLength(100); return null; } };
public void testFile() throws Exception { FileDataStore store = new FileDataStore(); store.setPath(TEST_DIR + "/fs"); store.init(TEST_DIR + "/fs"); store.setMinRecordLength(0); doTest(store); }
@Override protected DataStore createDataStore() throws RepositoryException { FileDataStore fds = new FileDataStore(); Properties props = loadProperties("/fs.properties"); String pathValue = props.getProperty(FSBackend.FS_BACKEND_PATH); if (pathValue != null && !"".equals(pathValue.trim())) { fsPath = pathValue + "/fds" + "-" + String.valueOf(randomGen.nextInt(100000)) + "-" + String.valueOf(randomGen.nextInt(100000)); } else { fsPath = dataStoreDir + "/repository/datastore"; } LOG.info("path [{}] set.", fsPath); fds.setPath(fsPath); fds.init(dataStoreDir); return fds; }
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()); }
@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))); }
private void testGetAllIdentifiers(String path, String unnormalizedPath) throws Exception { File testDir = new File(path); FileUtils.touch(new File(testDir, "ab/cd/ef/abcdef")); FileUtils.touch(new File(testDir, "bc/de/fg/bcdefg")); FileUtils.touch(new File(testDir, "cd/ef/gh/cdefgh")); FileUtils.touch(new File(testDir, "c")); FileDataStore fds = new OakFileDataStore(); fds.setPath(unnormalizedPath); fds.init(null); Iterator<DataIdentifier> dis = fds.getAllIdentifiers(); Set<String> fileNames = Sets.newHashSet(Iterators.transform(dis, new Function<DataIdentifier, String>() { @Override public String apply(@Nullable DataIdentifier input) { return input.toString(); } })); Set<String> expectedNames = Sets.newHashSet("abcdef","bcdefg","cdefgh"); assertEquals(expectedNames, fileNames); FileUtils.cleanDirectory(testDir); }
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(); } }
@Override protected void before() throws Throwable { FileDataStore fds = new FileDataStore(); configureDataStore(fds); fds.init(folder.newFolder().getAbsolutePath()); store = new DataStoreBlobStore(fds); }
} else if (bsType == Type.FAKE) { FileDataStore fakeDs = new DummyDataStore(); fakeDs.setPath(bsopts.getFakeDataStorePath()); fakeDs.init(null); delegate = fakeDs; } else { delegate = fds; if (bsopts.getFDSPath() != null) { fds.setPath(bsopts.getFDSPath()); } else { String cfgPath = bsopts.getFDSConfigPath();
dds.setPassword("sa"); dds.setCopyWhenReading(true); dds.init(dbPath); dds.close(); shutdownDatabase(url); FileDataStore fds = new FileDataStore(); fds.init(testDir + "/file"); doTest(fds, 0); fds.close();
@Test public void referenceHandling() throws Exception{ int minSize = new FileDataStore().getMinRecordLength(); LengthCachingDataStore fds = new LengthCachingDataStore(); fds.setDelegateClass(FileDataStore.class.getName()); fds.init(tempFolder.newFolder().getAbsolutePath()); fds.setReadOnly(false); DataRecord dr1 = fds.addRecord(byteStream(minSize + 10)); assertNotNull(fds.getRecordFromReference(dr1.getReference())); assertEquals(dr1.getIdentifier(), fds.getRecordFromReference(dr1.getReference()).getIdentifier()); }
@NotNull @Override public DataStore createDataStore() { return new FileDataStore(); }
@Override protected void configureDataStore(FileDataStore dataStore) { dataStore.setMinRecordLength(SegmentTestConstants.MEDIUM_LIMIT); }
@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")); }
@Test public void readOnly() throws Exception{ FileDataStore fds = new FileDataStore(); fds.setPath(temporaryFolder.getRoot().getAbsolutePath()); fds.init(null); DataStoreBlobStore writableBS = new DataStoreBlobStore(fds); BlobStore readOnly = ReadOnlyBlobStoreWrapper.wrap(writableBS); try { readOnly.writeBlob(new ByteArrayInputStream("foo".getBytes())); fail(); } catch (Exception ignore) { } String blobId = writableBS.writeBlob(new ByteArrayInputStream("foo".getBytes())); try(InputStream is = readOnly.getInputStream(blobId)) { assertNotNull(is); } }
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()); }