Ejemplo n.º 1
0
  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()));
  }
Ejemplo n.º 2
0
  public void testFindByPrefix() throws IOException {
    byte[] data = "abcdefghijklmnopqrstuvwxyz".getBytes();
    byte[] sha = DigestUtils.sha(data);

    prepareMockData("test.v7files.content", new BasicBSONObject("_id", sha).append("in", data));

    Mongo mongo = getMongo();
    MongoContentStorage storage = new MongoContentStorage(mongo.getDB("test"));

    assertEquals(
        new String(data), IOUtils.toString(storage.findContentByPrefix(sha).getInputStream()));

    // TODO (needs range queries in jmockmongo)
    // assertEquals(new String(data), IOUtils.toString(storage
    // .findContentByPrefix(ArrayUtils.subarray(sha, 0, 5))
    // .getInputStream()));

    // assertNull(storage.findContentByPrefix(new byte[] { 0, 0, 0, 0 }));
    // mongo.close();
  }