예제 #1
0
  public void testReadChunkedData() throws MongoException, IOException {

    byte[] data1 = "first chunk".getBytes();
    byte[] sha1 = DigestUtils.sha(data1);
    byte[] data2 = " second chunk".getBytes();
    byte[] sha2 = DigestUtils.sha(data2);
    byte[] data = "first chunk second chunk".getBytes();
    byte[] sha = DigestUtils.sha(data);

    prepareMockData("test.v7files.content", new BasicBSONObject("_id", sha1).append("in", data1));
    prepareMockData("test.v7files.content", new BasicBSONObject("_id", sha2).append("in", data2));
    prepareMockData(
        "test.v7files.content",
        new BasicBSONObject("_id", sha)
            .append("store", "cat")
            .append(
                "base",
                Arrays.asList(
                    new BasicBSONObject("sha", sha1).append("length", data1.length),
                    new BasicBSONObject("sha", sha2).append("length", data2.length))));

    Mongo mongo = getMongo();
    ContentStorage storage =
        new MongoContentStorage(mongo.getDB("test").getCollection("v7files.content"));

    Content check = storage.getContent(sha);

    assertEquals(new String(data), IOUtils.toString(check.getInputStream()));
    assertEquals(data.length, check.getLength());
    mongo.close();
  }
예제 #2
0
  public void testRoundtrip() throws MongoException, IOException {

    Mongo mongo = getMongo();
    ContentStorage storage =
        new MongoContentStorage(mongo.getDB("test").getCollection("v7files.content"));

    byte[] data = "abcdefghijklmnopqrstuvwxyz".getBytes();

    ContentPointer pointer = storage.storeContent(new ByteArrayInputStream(data));
    Content check = storage.getContent(pointer);

    assertEquals(new String(data), IOUtils.toString(check.getInputStream()));
    assertEquals(data.length, check.getLength());
    mongo.close();
  }
예제 #3
0
  public void testReadCompressedData() throws MongoException, IOException {

    byte[] data = "some data we are going to store compressed with gzip".getBytes();
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    GZIPOutputStream gzip = new GZIPOutputStream(baos);
    gzip.write(data);
    gzip.close();
    byte[] compressed = baos.toByteArray();
    byte[] sha = DigestUtils.sha(data);

    prepareMockData(
        "test.v7files.content",
        new BasicBSONObject("_id", sha).append("store", "gz").append("zin", compressed));

    Mongo mongo = getMongo();
    ContentStorage storage =
        new MongoContentStorage(mongo.getDB("test").getCollection("v7files.content"));

    Content check = storage.getContent(sha);

    assertEquals(new String(data), IOUtils.toString(check.getInputStream()));
    assertEquals(data.length, check.getLength());
    mongo.close();
  }