use of org.apache.jackrabbit.core.data.DataRecord in project jackrabbit-oak by apache.
the class CachingDataStoreTest method zeroCacheAddGetDelete.
/**
* Add, get, delete when zero cache size.
* @throws Exception
*/
@Test
public void zeroCacheAddGetDelete() throws Exception {
LOG.info("Starting zeroCacheAddGetDelete");
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);
DataRecord rec = dataStore.addRecord(fin);
assertEquals(id, rec.getIdentifier().toString());
assertFile(rec.getStream(), f, folder);
rec = dataStore.getRecordIfStored(new DataIdentifier(id));
assertEquals(id, rec.getIdentifier().toString());
assertFile(rec.getStream(), f, folder);
assertEquals(1, Iterators.size(dataStore.getAllIdentifiers()));
dataStore.deleteRecord(new DataIdentifier(id));
rec = dataStore.getRecordIfStored(new DataIdentifier(id));
assertNull(rec);
LOG.info("Finished zeroCacheAddGetDelete");
}
use of org.apache.jackrabbit.core.data.DataRecord in project jackrabbit-oak by apache.
the class AbstractDataStoreTest method doDeleteRecordTest.
/**
* Test {@link MultiDataStoreAware#deleteRecord(DataIdentifier)}.
*/
protected void doDeleteRecordTest() throws Exception {
Random random = randomGen;
byte[] data1 = new byte[dataLength];
random.nextBytes(data1);
DataRecord rec1 = ds.addRecord(new ByteArrayInputStream(data1));
byte[] data2 = new byte[dataLength];
random.nextBytes(data2);
DataRecord rec2 = ds.addRecord(new ByteArrayInputStream(data2));
byte[] data3 = new byte[dataLength];
random.nextBytes(data3);
DataRecord rec3 = ds.addRecord(new ByteArrayInputStream(data3));
((MultiDataStoreAware) ds).deleteRecord(rec1.getIdentifier());
assertNull("rec1 should be null", ds.getRecordIfStored(rec1.getIdentifier()));
assertEquals(new ByteArrayInputStream(data2), ds.getRecord(rec2.getIdentifier()).getStream());
assertEquals(new ByteArrayInputStream(data3), ds.getRecord(rec3.getIdentifier()).getStream());
}
use of org.apache.jackrabbit.core.data.DataRecord in project jackrabbit-oak by apache.
the class LengthCachingDataStore method addRecord.
@Override
public DataRecord addRecord(InputStream inputStream) throws DataStoreException {
checkIfReadOnly();
DataRecord result = getDelegate().addRecord(inputStream);
addNewMapping(result);
return result;
}
use of org.apache.jackrabbit.core.data.DataRecord in project jackrabbit-oak by apache.
the class SafeDataStoreBlobStore method getReference.
@Override
public String getReference(@Nonnull String encodedBlobId) {
checkNotNull(encodedBlobId);
String blobId = extractBlobId(encodedBlobId);
//Reference are not created for in memory record
if (InMemoryDataRecord.isInstance(blobId)) {
return null;
}
DataRecord record;
try {
record = delegate.getRecordIfStored(new DataIdentifier(blobId));
if (record != null) {
return record.getReference();
} else {
log.debug("No blob found for id [{}]", blobId);
}
} catch (DataStoreException e) {
log.warn("Unable to access the blobId for [{}]", blobId, e);
}
return null;
}
use of org.apache.jackrabbit.core.data.DataRecord in project jackrabbit by apache.
the class TestS3DSWithSSES3 method testDataMigration.
/**
* Test data migration enabling SSE_S3 encryption.
*/
public void testDataMigration() {
try {
String bucket = props.getProperty(S3Constants.S3_BUCKET);
S3DataStore s3ds = new S3DataStore();
s3ds.setProperties(props);
s3ds.setCacheSize(0);
s3ds.init(dataStoreDir);
byte[] data = new byte[dataLength];
randomGen.nextBytes(data);
DataRecord rec = s3ds.addRecord(new ByteArrayInputStream(data));
assertEquals(data.length, rec.getLength());
assertRecord(data, rec);
s3ds.close();
// turn encryption now.
props.setProperty(S3Constants.S3_BUCKET, bucket);
props.setProperty(S3Constants.S3_ENCRYPTION, S3Constants.S3_ENCRYPTION_SSE_S3);
props.setProperty(S3Constants.S3_RENAME_KEYS, "true");
s3ds = new S3DataStore();
s3ds.setProperties(props);
s3ds.setCacheSize(0);
s3ds.init(dataStoreDir);
rec = s3ds.getRecord(rec.getIdentifier());
assertEquals(data.length, rec.getLength());
assertRecord(data, rec);
randomGen.nextBytes(data);
rec = s3ds.addRecord(new ByteArrayInputStream(data));
s3ds.close();
} catch (Exception e) {
LOG.error("error:", e);
fail(e.getMessage());
}
}
Aggregations