Search in sources :

Example 11 with ContentPointer

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());
}
Also used : Random(java.util.Random) Mongo(com.mongodb.Mongo) ByteArrayInputStream(java.io.ByteArrayInputStream) ContentSHA(v7db.files.spi.ContentSHA) ContentPointer(v7db.files.spi.ContentPointer) BasicBSONObject(org.bson.BasicBSONObject) BSONObject(org.bson.BSONObject)

Example 12 with ContentPointer

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();
}
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

ContentPointer (v7db.files.spi.ContentPointer)12 BasicDBObject (com.mongodb.BasicDBObject)4 ByteArrayInputStream (java.io.ByteArrayInputStream)4 BSONObject (org.bson.BSONObject)4 ContentStorage (v7db.files.spi.ContentStorage)4 DBObject (com.mongodb.DBObject)3 Mongo (com.mongodb.Mongo)3 ContentSHA (v7db.files.spi.ContentSHA)3 BasicBSONObject (org.bson.BasicBSONObject)2 MongoContentStorage (v7db.files.mongodb.MongoContentStorage)2 InlineContent (v7db.files.spi.InlineContent)2 DBCollection (com.mongodb.DBCollection)1 DBRef (com.mongodb.DBRef)1 WriteResult (com.mongodb.WriteResult)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 Random (java.util.Random)1 Content (v7db.files.spi.Content)1 ReferenceTracking (v7db.files.spi.ReferenceTracking)1 StoredContent (v7db.files.spi.StoredContent)1