Example #1
0
MojErr MojDbWatchTest::cancelTest(MojDb& db)
{
    // cancel find
    MojDbQuery query;
    MojErr err = query.from(_T("WatchTest:1"));
    MojTestErrCheck(err);
    err = query.where(_T("foo"), MojDbQuery::OpLessThanEq, 45);
    MojTestErrCheck(err);
    MojRefCountedPtr<TestWatcher> watcher(new TestWatcher);
    MojTestAssert(watcher.get());
    watcher->m_slot.cancel();
    MojDbCursor cursor;
    err = db.find(query, cursor, watcher->m_slot);
    MojTestErrCheck(err);
    err = cursor.close();
    MojTestErrCheck(err);
    MojTestAssert(watcher->m_count == 0);
    watcher->m_slot.cancel();
    MojTestAssert(watcher->m_count == 0);
    MojObject id;
    err = put(db, 1, 1, id, m_rev);
    MojTestErrCheck(err);
    MojTestAssert(watcher->m_count == 0);
    // cancel watch
    watcher.reset(new TestWatcher);
    MojTestAssert(watcher.get());
    MojDbQuery queryWithRev;
    err = queryWithRev.from(_T("WatchTest:1"));
    MojTestErrCheck(err);
    err = queryWithRev.where(_T("foo"), MojDbQuery::OpEq, 45);
    MojTestErrCheck(err);
    err = queryWithRev.where(_T("_rev"), MojDbQuery::OpGreaterThan, m_rev);
    MojTestErrCheck(err);
    bool fired = false;
    err = db.watch(queryWithRev, cursor, watcher->m_slot, fired);
    MojTestErrCheck(err);
    err = cursor.close();
    MojTestErrCheck(err);
    MojTestAssert(!fired);
    MojTestAssert(watcher->m_count == 0);
    watcher->m_slot.cancel();
    MojTestAssert(watcher->m_count == 0);
    err = put(db, 45, 45, id, m_rev);
    MojTestErrCheck(err);
    MojTestAssert(watcher->m_count == 0);

    return MojErrNone;
}
Example #2
0
MojErr MojDbWatchTest::eqTest(MojDb& db)
{
    MojDbQuery query;
    MojErr err = query.from(_T("WatchTest:1"));
    MojTestErrCheck(err);
    err = query.where(_T("foo"), MojDbQuery::OpEq, 1);
    MojTestErrCheck(err);
    MojRefCountedPtr<TestWatcher> watcher(new TestWatcher);
    MojTestAssert(watcher.get());
    MojDbCursor cursor;
    err = db.find(query, cursor, watcher->m_slot);
    MojTestErrCheck(err);
    err = cursor.close();
    MojTestErrCheck(err);
    MojTestAssert(watcher->m_count == 0);
    MojRefCountedPtr<TestWatcher> watcher2(new TestWatcher);
    MojTestAssert(watcher2.get());
    bool fired = false;
    err = db.watch(query, cursor, watcher2->m_slot, fired);
    MojTestErrCheck(err);
    err = cursor.close();
    MojTestErrCheck(err);
    MojTestAssert(!fired);
    // puts
    MojObject id;
    err = put(db, 0, 0, id, m_rev);
    MojTestErrCheck(err);
    MojTestAssert(watcher->m_count == 0);
    MojTestAssert(watcher2->m_count == 0);
    err = put(db, 2, 2, id, m_rev);
    MojTestErrCheck(err);
    MojTestAssert(watcher->m_count == 0);
    MojTestAssert(watcher2->m_count == 0);
    err = put(db, 1, 1, id, m_rev);
    MojTestErrCheck(err);
    MojTestAssert(watcher->m_count == 1);
    MojTestAssert(watcher2->m_count == 1);
    err = put(db, 1, 1, id, m_rev);
    MojTestErrCheck(err);
    MojTestAssert(watcher->m_count == 1);
    MojTestAssert(watcher2->m_count == 1);
    // put, changing property not in index
    watcher.reset(new TestWatcher);
    MojTestAssert(watcher.get());
    err = db.find(query, cursor, watcher->m_slot);
    MojTestErrCheck(err);
    err = cursor.close();
    MojTestErrCheck(err);
    err = put(db, 1, 2, id, m_rev);
    MojTestErrCheck(err);
    MojTestAssert(watcher->m_count == 1);
    // dels
    watcher.reset(new TestWatcher);
    MojTestAssert(watcher.get());
    err = db.find(query, cursor, watcher->m_slot);
    MojTestErrCheck(err);
    err = cursor.close();
    MojTestErrCheck(err);
    watcher2.reset(new TestWatcher);
    MojTestAssert(watcher2.get());
    MojDbQuery queryWithRev;
    err = queryWithRev.from(_T("WatchTest:1"));
    MojTestErrCheck(err);
    err = queryWithRev.where(_T("foo"), MojDbQuery::OpEq, 1);
    MojTestErrCheck(err);
    err = queryWithRev.where(_T("_rev"), MojDbQuery::OpGreaterThan, m_rev);
    MojTestErrCheck(err);
    err = queryWithRev.includeDeleted();
    MojTestErrCheck(err);
    fired = false;
    err = db.watch(queryWithRev, cursor, watcher2->m_slot, fired);
    MojTestErrCheck(err);
    err = cursor.close();
    MojTestErrCheck(err);
    MojTestAssert(!fired);
    MojTestAssert(watcher->m_count == 0);
    MojTestAssert(watcher2->m_count == 0);
    bool found;
    err = db.del(id, found);
    MojTestErrCheck(err);
    MojTestAssert(found);
    MojTestAssert(watcher->m_count == 1);
    MojTestAssert(watcher2->m_count == 1);
    // ordering
    watcher.reset(new TestWatcher);
    MojTestAssert(watcher.get());
    err = db.find(query, cursor, watcher->m_slot);
    MojTestErrCheck(err);
    err = put(db, 1, 1, id, m_rev);
    MojTestErrCheck(err);
    MojTestAssert(watcher->m_count == 0);
    err = cursor.close();
    MojTestErrCheck(err);
    MojTestAssert(watcher->m_count == 1);

    return MojErrNone;
}