예제 #1
0
  @Before
  public void setUp() throws Exception {
    mdc =
        new MongoConnector(
            DatabaseConfigurationFactory.getDatabaseConfiguration("junit-QueryTest"));
    mdc.waitForWrites(true);

    test = new MongoDocument();
    test.setAction(Action.ADD);
    test.putContentField("name", "test");
    test.putMetadataField("date", new Date());

    test2 = new MongoDocument();
    test2.setAction(Action.DELETE);
    test2.putContentField("name", "test");
    test2.putContentField("number", 2);
    test2.putMetadataField("date", new Date());

    random = new MongoDocument();

    try {
      mdc.connect();
    } catch (IOException e) {
      fail("IOException when establishing connection");
    }

    DatabaseDocument<MongoType> d;
    while ((d = mdc.getDocumentReader().getDocument(new MongoQuery())) != null) {
      mdc.getDocumentWriter().delete(d);
    }

    mdc.getDocumentWriter().insert(test);
    mdc.getDocumentWriter().insert(test2);
    mdc.getDocumentWriter().insert(random);
  }
예제 #2
0
 public long insertCurrentDocuments(int count) throws Exception {
   long start = System.currentTimeMillis();
   for (int i = 0; i < count; i++) {
     MongoDocument d = new MongoDocument();
     d.putContentField(getRandomString(5), getRandomString(20));
     mdc.getDocumentWriter().insert(d);
   }
   return System.currentTimeMillis() - start;
 }
예제 #3
0
  @Test
  public void testRequireNotTouchedByStage() throws JsonException {
    LocalQuery q = new LocalQuery();
    q.requireNotTouchedByStage("xyz");
    List<DatabaseDocument<MongoType>> ds =
        mdc.getDocumentReader().getDocuments(new MongoQuery(q.toJson()), 3);
    if (ds.size() != 3) {
      fail("Received incorrect number of documents..");
    }

    Document d = mdc.getDocumentWriter().getAndTag(new MongoQuery(), "xyz");
    if (d == null) {
      fail("Should have gotten a document back...");
    }
    mdc.getDocumentWriter().markTouched(d.getID(), "xyz");

    ds = mdc.getDocumentReader().getDocuments(new MongoQuery(q.toJson()), 3);
    if (ds.size() != 2) {
      fail("Received incorrect number of documents..");
    }
  }