use of org.apache.jackrabbit.core.data.DataIdentifier in project jackrabbit-oak by apache.
the class OakFileDataStore method getAllMetadataRecords.
@Override
public List<DataRecord> getAllMetadataRecords(String prefix) {
File root = new File(getPath());
List<DataRecord> rootRecords = new ArrayList<DataRecord>();
for (File file : FileFilterUtils.filterList(FileFilterUtils.prefixFileFilter(prefix), root.listFiles())) {
if (!file.isDirectory()) {
// skip directories which are actual data store files
rootRecords.add(new FileDataRecord(this, new DataIdentifier(file.getName()), file));
}
}
return rootRecords;
}
use of org.apache.jackrabbit.core.data.DataIdentifier in project jackrabbit-oak by apache.
the class CachingDataStoreTest method addDelete.
/**
* Add in datastore.
*/
@Test
public void addDelete() throws Exception {
LOG.info("Starting addDelete");
File f = copyToFile(randomStream(0, 4 * 1024), folder.newFile());
String id = getIdForInputStream(f);
FileInputStream fin = new FileInputStream(f);
closer.register(fin);
DataRecord rec = dataStore.addRecord(fin);
assertEquals(id, rec.getIdentifier().toString());
//start & finish
taskLatch.countDown();
callbackLatch.countDown();
waitFinish();
rec = dataStore.getRecordIfStored(new DataIdentifier(id));
assertNotNull(rec);
assertFile(rec.getStream(), f, folder);
dataStore.deleteRecord(new DataIdentifier(id));
rec = dataStore.getRecordIfStored(new DataIdentifier(id));
assertNull(rec);
LOG.info("Finished addDelete");
}
use of org.apache.jackrabbit.core.data.DataIdentifier in project jackrabbit-oak by apache.
the class CachingDataStoreTest method referenceNoCache.
@Test
public void referenceNoCache() throws Exception {
LOG.info("Starting referenceNoCache");
dataStore.close();
init(1, 0, 0);
File f = copyToFile(randomStream(0, 4 * 1024), folder.newFile());
String id = getIdForInputStream(f);
FileInputStream fin = new FileInputStream(f);
closer.register(fin);
// Record still in staging
DataRecord rec = dataStore.addRecord(fin);
assertEquals(id, rec.getIdentifier().toString());
assertFile(rec.getStream(), f, folder);
assertEquals(backend.getReferenceFromIdentifier(rec.getIdentifier()), rec.getReference());
rec = dataStore.getRecordIfStored(new DataIdentifier(id));
assertNotNull(rec);
assertFile(rec.getStream(), f, folder);
assertEquals(backend.getReferenceFromIdentifier(rec.getIdentifier()), rec.getReference());
LOG.info("Finished referenceNoCache");
}
use of org.apache.jackrabbit.core.data.DataIdentifier in project jackrabbit-oak by apache.
the class LengthCachingDataStoreTest method mappingFileData.
@Test
public void mappingFileData() throws Exception {
File root = tempFolder.getRoot();
File mappingFile = new File(root, "mapping.txt");
String text = "1000|foo\n2000|bar";
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 dr = fds.getRecord(new DataIdentifier("foo"));
assertNotNull(dr);
assertEquals(1000, dr.getLength());
assertEquals(2000, fds.getRecord(new DataIdentifier("bar")).getLength());
}
use of org.apache.jackrabbit.core.data.DataIdentifier in project jackrabbit-oak by apache.
the class LengthCachingDataStoreTest method writeBackNewEntries.
@Test
public void writeBackNewEntries() throws Exception {
//1. Add some entries to FDS
FileDataStore fds1 = new FileDataStore();
File fds1Dir = tempFolder.newFolder();
int minSize = fds1.getMinRecordLength();
fds1.init(fds1Dir.getAbsolutePath());
DataRecord dr1 = fds1.addRecord(byteStream(minSize + 10));
DataRecord dr2 = fds1.addRecord(byteStream(minSize + 100));
//2. Try reading them so as to populate the new mappings
LengthCachingDataStore fds2 = new LengthCachingDataStore();
fds2.setDelegateClass(FileDataStore.class.getName());
fds2.init(fds1Dir.getAbsolutePath());
fds2.getRecord(new DataIdentifier(dr1.getIdentifier().toString()));
fds2.getRecord(new DataIdentifier(dr2.getIdentifier().toString()));
File mappingFile = fds2.getMappingFile();
//3. Get the mappings pushed to file
fds2.close();
//4. Open a new FDS pointing to new directory. Read should still work fine
//as they would be served by the mapping data
LengthCachingDataStore fds3 = new LengthCachingDataStore();
fds3.setDelegateClass(FileDataStore.class.getName());
fds3.setMappingFilePath(mappingFile.getAbsolutePath());
fds3.init(tempFolder.newFolder().getAbsolutePath());
fds3.setReadOnly(false);
assertEquals(dr1.getLength(), fds3.getRecord(dr1.getIdentifier()).getLength());
assertEquals(dr2.getLength(), fds3.getRecord(dr2.getIdentifier()).getLength());
DataRecord dr3 = fds3.addRecord(byteStream(minSize + 200));
//5. Close again so see if update of existing file works
fds3.close();
LengthCachingDataStore fds4 = new LengthCachingDataStore();
fds4.setDelegateClass(FileDataStore.class.getName());
fds4.setMappingFilePath(mappingFile.getAbsolutePath());
fds4.init(tempFolder.newFolder().getAbsolutePath());
assertEquals(dr3.getLength(), fds4.getRecord(dr3.getIdentifier()).getLength());
assertEquals(dr2.getLength(), fds4.getRecord(dr2.getIdentifier()).getLength());
}
Aggregations