use of v7db.files.spi.ReferenceTracking in project v7files by thiloplanz.
the class MongoReferenceTrackingTest method testInsert.
public void testInsert() throws MongoException, IOException {
Mongo mongo = getMongo();
ReferenceTracking refs = new MongoReferenceTracking(mongo.getDB("test").getCollection("v7files.refs"));
Object owner = new DBRef(null, "test", "test");
refs.updateReferences(owner, new StoredContent(new byte[20], 1000));
assertMockMongoFieldContains(new byte[20], "test.v7files.refs", owner, "refs");
assertMockMongoFieldContains(new byte[20], "test.v7files.refs", owner, "refHistory");
mongo.close();
}
use of v7db.files.spi.ReferenceTracking in project v7files by thiloplanz.
the class MongoReferenceTrackingTest method testUpdate.
public void testUpdate() throws MongoException, IOException {
byte[] oldRef = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20 };
prepareMockData("test.v7files.refs", new BasicBSONObject("_id", "x").append("refs", new Object[] { oldRef }).append("refHistory", new Object[] { oldRef }));
Mongo mongo = getMongo();
ReferenceTracking refs = new MongoReferenceTracking(mongo.getDB("test").getCollection("v7files.refs"));
refs.updateReferences("x", new StoredContent(new byte[20], 1000));
assertMockMongoFieldContains(new byte[20], "test.v7files.refs", "x", "refs");
assertMockMongoFieldContains(new byte[20], "test.v7files.refs", "x", "refHistory");
assertMockMongoFieldDoesNotContain(oldRef, "test.v7files.refs", "x", "refs");
assertMockMongoFieldContains(oldRef, "test.v7files.refs", "x", "refHistory");
mongo.close();
}
use of v7db.files.spi.ReferenceTracking 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