Package com.findwise.hydra.memorydb

Examples of com.findwise.hydra.memorydb.MemoryDocument


    LocalDocument doc = new LocalDocument();

    doc.putContentField("field", "value");
    doc.putContentField("field2", "value2");
   
    MemoryDocument d = (MemoryDocument)mc.convert(doc);
    mc.getDocumentWriter().insert(d);
   
    doc = rp.getDocument(new LocalQuery());
   
    doc.putContentField("field3", "value3");
   
    if(!rp.markProcessed(doc)) {
      fail("markProcessed returned false");
    }
   
    MemoryDocument doc2 = (MemoryDocument) mc.getDocumentReader().getDocumentById(d.getID(), true);
   
    for(String field : doc.getContentFields()) {
      if(!doc2.hasContentField(field)) {
        fail("Missing a field: "+field);
      }
      if(!doc.getContentField(field).equals(doc2.getContentField(field))) {
        fail("Content mismatch");
      }
    }
   
    if(!doc2.getStatus().equals(Status.PROCESSED)) {
      fail("No FAILED status on the document");
    }
  }
View Full Code Here


    server = RESTServer.getNewStartedRESTServer(20000, handler);
  }
 
  @Test
  public void testSave() throws Exception {
    MemoryDocument testDoc = new MemoryDocument();
    mc.getDocumentWriter().insert(testDoc);
   
    RemotePipeline rp = new HttpRemotePipeline("localhost", server.getPort(), "stage");
   
    String content = "adsafgoaiuhgahgo\ndasdas";
    String fileName = "test.txt";
   
    rp.saveFile(new DocumentFile<Local>(testDoc.getID().getLocalDocumentID(), fileName, IOUtils.toInputStream(content, "UTF-8")));
   
    DocumentFile<MemoryType> df = mc.getDocumentReader().getDocumentFile(testDoc, fileName);
   
    if(df==null) {
      fail("File was not properly saved");
View Full Code Here

    RemotePipeline rp = new HttpRemotePipeline("localhost", server.getPort(), "stage");
    if(rp.getFileNames(new LocalDocumentID(""))!=null) {
      fail("Got filenames for non-existant document");
    }
   
    MemoryDocument testDoc = new MemoryDocument();
    mc.getDocumentWriter().insert(testDoc);
   
    List<String> list = rp.getFileNames(testDoc.getID());
   
    if(list==null) {
      fail("Got null when requesting filenames for a real document");
    }
   
    if(list.size()!=0) {
      fail("Got non-zero filename list before any files were added");
    }
   
    String content = "adsafgoaiuhgahgo\ndasåäödas";
    String fileName = "test.txt";
    String fileName2 = "test2.txt";
   
    mc.getDocumentWriter().write(new DocumentFile<MemoryType>(testDoc.getID(), fileName, IOUtils.toInputStream(content, "UTF-8"), "stage"));
    mc.getDocumentWriter().write(new DocumentFile<MemoryType>(testDoc.getID(), fileName2, IOUtils.toInputStream(content, "UTF-8"), "stage"));
   
    list = rp.getFileNames(testDoc.getID());
    if(list.size()!=2) {
      fail("Didn't get two filenames back");
    }
    if(!list.contains(fileName)) {
      fail("Filename list is missing the first file name");
View Full Code Here

    RemotePipeline rp = new HttpRemotePipeline("localhost", server.getPort(), "stage");
    if(rp.getFile("id", new LocalDocumentID("file"))!=null) {
      fail("Got non-null for non-existant document and non-existant file");
    }
   
    MemoryDocument testDoc = new MemoryDocument();
    mc.getDocumentWriter().insert(testDoc);

    if(rp.getFile(testDoc.getID().getID().toString(), new LocalDocumentID("file"))!=null) {
      fail("Got non-null for non-existant file");
    }
   
    String content = "adsafgoaiuhgahgo\ndndasasddåäöäöåäöäas";
    String fileName = "test.txt";
    String content2 = "adsagagasdgarqRE13123AFg da\nndasdas";
    String fileName2 = "test2.txt";
   
    mc.getDocumentWriter().write(new DocumentFile<MemoryType>(testDoc.getID(), fileName, IOUtils.toInputStream(content, "UTF-8"), "stage"));
    mc.getDocumentWriter().write(new DocumentFile<MemoryType>(testDoc.getID(), fileName2, IOUtils.toInputStream(content2, "UTF-8"), "stage"));
   
    InputStream s = rp.getFile(fileName, testDoc.getID().getLocalDocumentID()).getStream();
    if(s==null) {
      fail("Did not get a file stream for file 1");
    }
    String fc = IOUtils.toString(s, "UTF-8");
    if(!fc.equals(content)) {
      fail("Content of file 1 did not match");
    }
   
    s = rp.getFile(fileName2, testDoc.getID().getLocalDocumentID()).getStream();
    if(s==null) {
      fail("Did not get a file stream for file 2");
    }
   
    if(!IOUtils.toString(s, "UTF-8").equals(content2)) {
View Full Code Here

    RemotePipeline rp = new HttpRemotePipeline("localhost", server.getPort(), "stage");
    if(rp.deleteFile("name", new LocalDocumentID("id"))) {
      fail("Got positive response for non-existant document and non-existant file");
    }
   
    MemoryDocument testDoc = new MemoryDocument();
    mc.getDocumentWriter().insert(testDoc);

    if(rp.getFile("file", testDoc.getID().getLocalDocumentID())!=null) {
      fail("Got positive response for non-existant file");
    }
   
    String content = "adsafgoaiuhgahgo\ndasdas";
    String fileName = "test.txt";
    String fileName2 = "test2.txt";
   
    mc.getDocumentWriter().write(new DocumentFile<MemoryType>(testDoc.getID(), fileName, IOUtils.toInputStream(content, "UTF-8"), "stage"));
    mc.getDocumentWriter().write(new DocumentFile<MemoryType>(testDoc.getID(), fileName2, IOUtils.toInputStream(content, "UTF-8"), "stage"));
   
    rp.deleteFile(fileName, LocalDocumentID.getDocumentID(testDoc.getID().toJSON()));
   
    if(mc.getDocumentReader().getDocumentFileNames(testDoc).size()!=1) {
      fail("Incorrect amount of files attached to document after delete");
    }
   
    if(!mc.getDocumentReader().getDocumentFileNames(testDoc).get(0).equals(fileName2)) {
      fail("Wrong file left after delete");
    }

    rp.deleteFile(fileName2, LocalDocumentID.getDocumentID(testDoc.getID().toJSON()));
   
    if(mc.getDocumentReader().getDocumentFileNames(testDoc).size()!=0) {
      fail("Still some files after both should have been deleted");
    }
  }
View Full Code Here

TOP

Related Classes of com.findwise.hydra.memorydb.MemoryDocument

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.