Beispiel #1
0
  @Test
  public void testPagination() {
    Map<String, Object> fileContents = new HashMap<String, Object>();
    final int TOTAL_POSTS = 5;
    final int PER_PAGE = 2;

    for (int i = 1; i <= TOTAL_POSTS; i++) {
      fileContents.put("name", "dummyfile" + i);

      ODocument doc = new ODocument("post");
      doc.fields(fileContents);
      boolean cached =
          fileContents.get("cached") != null
              ? Boolean.valueOf((String) fileContents.get("cached"))
              : true;
      doc.field("cached", cached);
      doc.save();
    }

    int iterationCount = 0;
    int start = 0;
    db.setLimit(PER_PAGE);

    while (start < TOTAL_POSTS) {
      db.setStart(start);
      List<ODocument> posts = db.getAllContent("post");
      Assert.assertEquals(
          "dummyfile" + (1 + (PER_PAGE * iterationCount)), posts.get(0).field("name"));
      //            Assert.assertEquals("dummyfile" + (PER_PAGE + (PER_PAGE * iterationCount)),
      // posts.get(posts.size()-1).field("name"));
      iterationCount++;
      start += PER_PAGE;
    }
    Assert.assertEquals(Math.round(TOTAL_POSTS / (1.0 * PER_PAGE) + 0.4), iterationCount);
  }
Beispiel #2
0
 public byte[] getData() {
   // if there's no data, load it from disk
   if (data == null) {
     if (file == null) file = new File(store.getDirectory().getPath() + "/" + id);
     try {
       InputStream in = new FileInputStream(file);
       data = new byte[in.available()];
       in.read(data);
       in.close();
       touch();
     } catch (IOException e) {
       System.out.println(e.toString());
     }
   }
   return data;
 }
Beispiel #3
0
  /** Flushes the item to disk. */
  public synchronized void flush(boolean removeFromMemory) {
    if (file == null && data != null) {
      file = new File(store.getDirectory().getPath() + "/" + id);
      try {
        OutputStream out = new FileOutputStream(file);
        out.write(data);
        out.close();
      } catch (IOException e) {
        System.out.println(e.toString());
      }

      // remove the content item from memory
      if (removeFromMemory) data = null;

    } else {
      // the contents of the file are immutable, simply update the lastAccessed date
      if (lastAccessed != previouslyAccessed) {
        file.setLastModified(lastAccessed);
      }
    }
  }
 private List<String> buildContentList(String lastItem) throws ContentStoreException {
   return store.getSpace(spaceId, prefix, maxResults, lastItem).getContentIds();
 }
Beispiel #5
0
 @After
 public void cleanup() throws InterruptedException {
   db.drop();
   db.close();
 }