Search in sources :

Example 1 with ReferenceTracking

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();
}
Also used : ReferenceTracking(v7db.files.spi.ReferenceTracking) Mongo(com.mongodb.Mongo) DBRef(com.mongodb.DBRef) BasicBSONObject(org.bson.BasicBSONObject) StoredContent(v7db.files.spi.StoredContent)

Example 2 with ReferenceTracking

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();
}
Also used : BasicBSONObject(org.bson.BasicBSONObject) ReferenceTracking(v7db.files.spi.ReferenceTracking) Mongo(com.mongodb.Mongo) BasicBSONObject(org.bson.BasicBSONObject) StoredContent(v7db.files.spi.StoredContent)

Example 3 with ReferenceTracking

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();
}
Also used : DBCollection(com.mongodb.DBCollection) ReferenceTracking(v7db.files.spi.ReferenceTracking) Mongo(com.mongodb.Mongo) ByteArrayInputStream(java.io.ByteArrayInputStream) ContentStorage(v7db.files.spi.ContentStorage) ContentPointer(v7db.files.spi.ContentPointer) DBRef(com.mongodb.DBRef) BasicBSONObject(org.bson.BasicBSONObject)

Aggregations

Mongo (com.mongodb.Mongo)3 BasicBSONObject (org.bson.BasicBSONObject)3 ReferenceTracking (v7db.files.spi.ReferenceTracking)3 DBRef (com.mongodb.DBRef)2 StoredContent (v7db.files.spi.StoredContent)2 DBCollection (com.mongodb.DBCollection)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ContentPointer (v7db.files.spi.ContentPointer)1 ContentStorage (v7db.files.spi.ContentStorage)1