use of v7db.files.spi.ContentPointer in project v7files by thiloplanz.
the class MongoContentStorageTest method testSaveAsChunks.
public void testSaveAsChunks() throws IOException {
byte[] data = new byte[10 * 1024 * 1024];
new Random(12345).nextBytes(data);
byte[] sha = DigestUtils.sha(data);
Mongo mongo = getMongo();
MongoContentStorage storage = new MongoContentStorage(mongo.getDB("test"));
ContentPointer pointer = storage.storeContent(new ByteArrayInputStream(data));
BSONObject doc = assertMockMongoContainsDocument("test.v7files.content", sha);
assertEquals("cat", doc.get("store"));
assertEquals(data.length, storage.getContent(pointer).getLength());
assertEquals(Hex.encodeHexString(sha), DigestUtils.shaHex(storage.getContent(pointer).getInputStream()));
ContentSHA storeAgain = storage.storeContent(new ByteArrayInputStream(data));
assertEquals(Hex.encodeHexString(sha), storeAgain.getDigest());
}
use of v7db.files.spi.ContentPointer in project v7files by thiloplanz.
the class MongoReferenceTrackingTest method testPurge.
public void testPurge() throws MongoException, IOException, DecoderException {
Mongo mongo = getMongo();
DBCollection contents = mongo.getDB("test").getCollection("v7files.content");
ContentStorage storage = new MongoContentStorage(contents);
byte[] data = "abcdefghijklmnopqrstuvwxyz".getBytes();
ContentPointer pointer = storage.storeContent(new ByteArrayInputStream(data));
DBCollection references = mongo.getDB("test").getCollection("v7files.refs");
ReferenceTracking refs = new MongoReferenceTracking(references);
Object owner = new DBRef(null, "test", "test");
refs.updateReferences(owner, pointer);
refs.purge(owner);
SimpleGarbageCollector.purge(contents, references);
assertMockMongoDoesNotContainDocument("test.v7files.refs", owner);
assertMockMongoDoesNotContainDocument("test.v7files.content", DigestUtils.sha(data));
mongo.close();
}
Aggregations