本文整理汇总了C++中MojDb类的典型用法代码示例。如果您正苦于以下问题:C++ MojDb类的具体用法?C++ MojDb怎么用?C++ MojDb使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了MojDb类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: engine
MojErr MojDbQuotaTest::testErrors()
{
#ifdef MOJ_USE_BDB
MojRefCountedPtr<MojDbStorageEngine> engine(new MojDbBerkeleyEngine());
#elif MOJ_USE_LDB
MojRefCountedPtr<MojDbStorageEngine> engine(new MojDbLevelEngine());
#else
MojRefCountedPtr<MojDbStorageEngine> engine;
#endif
MojAllocCheck(engine.get());
MojRefCountedPtr<MojDbTestStorageEngine> testEngine(new MojDbTestStorageEngine(engine.get()));
MojAllocCheck(testEngine.get());
MojErr err = testEngine->open(MojDbTestDir);
MojTestErrCheck(err);
MojDb db;
err = db.open(MojDbTestDir, testEngine.get());
MojTestErrCheck(err);
// test that failed put does not affect quota
MojInt64 quotaUsage1 = 0;
err = getQuotaUsage(db, _T("com.foo.*"), quotaUsage1);
MojTestErrCheck(err);
err = testEngine->setNextError(_T("txn.commit"), MojErrDbDeadlock);
MojTestErrCheck(err);
err = put(db, MojTestKind3Objects[1]);
MojTestErrExpected(err, MojErrDbDeadlock);
MojInt64 quotaUsage2 = 0;
err = getQuotaUsage(db, _T("com.foo.*"), quotaUsage2);
MojTestErrCheck(err);
MojTestAssert(quotaUsage2 == quotaUsage1);
// test that failed putQuota has no effect
err = testEngine->setNextError(_T("txn.commit"), MojErrDbDeadlock);
MojTestErrCheck(err);
MojObject obj;
err = obj.fromJson(_T("{\"owner\":\"com.foo.boo\",\"size\":1000}"));
MojErrCheck(err);
err = db.putQuotas(&obj, &obj + 1);
MojTestErrExpected(err, MojErrDbDeadlock);
MojInt64 quotaUsage3 = 0;
err = getQuotaUsage(db, _T("com.foo.*"), quotaUsage3);
MojTestErrCheck(err);
MojTestAssert(quotaUsage3 == quotaUsage1);
// test that failed putKind has no effect
err = testEngine->setNextError(_T("txn.commit"), MojErrDbDeadlock);
MojTestErrCheck(err);
err = obj.fromJson(MojTestKind3Str2);
MojTestErrCheck(err);
err = db.putKind(obj);
MojTestErrExpected(err, MojErrDbDeadlock);
MojInt64 quotaUsage4 = 0;
err = getQuotaUsage(db, _T("com.foo.*"), quotaUsage4);
MojTestErrCheck(err);
MojTestAssert(quotaUsage4 == quotaUsage1);
err = db.close();
MojTestErrCheck(err);
return MojErrNone;
}
示例2: testEnforce
MojErr MojDbQuotaTest::testEnforce(MojDb& db)
{
// set quota size to current usage
MojInt64 quotaUsage1 = 0;
MojErr err = getQuotaUsage(db, _T("com.foo.bar"), quotaUsage1);
MojTestErrCheck(err);
MojObject obj;
err = obj.putString(_T("owner"), _T("com.foo.bar"));
MojErrCheck(err);
err = obj.putInt(_T("size"), quotaUsage1);
MojErrCheck(err);
err = db.putQuotas(&obj, &obj + 1);
MojErrCheck(err);
err = put(db, MojTestKind1Objects[3]);
MojTestErrExpected(err, MojErrDbQuotaExceeded);
// Try to delete the kind
MojString kindStr;
err = kindStr.assign(_T("Test:1"));
MojTestErrCheck(err);
bool found = false;
err = db.delKind(kindStr, found);
//The delete should be failure, because it contain sub kind "Test2:1"
MojTestErrExpected(err,MojErrDbKindHasSubKinds);
MojTestAssert(!found);
return MojErrNone;
}
示例3: MojTestErrCheck
MojErr MojDbPerfUpdateTest::timeUpdateKind(MojDb& db, const MojChar* kindJson, MojObject& kindObj, MojTime& addIndexTime, MojTime& dropIndexTime)
{
MojTime startTime;
MojTime endTime;
MojObject origKindObj;
MojErr err = origKindObj.fromJson(kindJson);
MojTestErrCheck(err);
for (MojUInt64 i = 0; i < numUpdateKindIterations; i++) {
err = MojGetCurrentTime(startTime);
MojTestErrCheck(err);
bool found;
err = kindObj.del(MojDb::RevKey, found);
MojTestErrCheck(err);
err = db.putKind(kindObj);
MojTestErrCheck(err);
err = MojGetCurrentTime(endTime);
MojTestErrCheck(err);
addIndexTime += (endTime - startTime);
totalTestTime += (endTime - startTime);
err = MojGetCurrentTime(startTime);
MojTestErrCheck(err);
err = origKindObj.del(MojDb::RevKey, found);
MojTestErrCheck(err);
err = db.putKind(origKindObj);
MojTestErrCheck(err);
err = MojGetCurrentTime(endTime);
MojTestErrCheck(err);
dropIndexTime += (endTime - startTime);
totalTestTime += (endTime - startTime);
}
return MojErrNone;
}
示例4: MojTestErrCheck
/**
* run
*/
MojErr MojDbShardManagerTest::run()
{
MojErr err = MojErrNone;
MojDb db;
// open
err = db.open(MojDbTestDir);
MojTestErrCheck(err);
MojDbShardEngine* p_eng = db.shardEngine();
MojDbShardIdCache cache;
err = testShardIdCacheIndexes(&cache);
MojTestErrCheck(err);
err = testShardIdCacheOperations(&cache);
MojTestErrCheck(err);
err = testShardEngine(p_eng);
MojTestErrCheck(err);
err = testShardCreateAndRemoveWithRecords(db);
MojTestErrCheck(err);
err = db.close();
MojTestErrCheck(err);
return err;
}
示例5: testEnforce
MojErr MojDbQuotaTest::testEnforce(MojDb& db)
{
// set quota size to current usage
MojInt64 quotaUsage1 = 0;
MojErr err = getQuotaUsage(db, _T("com.foo.bar"), quotaUsage1);
MojTestErrCheck(err);
MojObject obj;
err = obj.putString(_T("owner"), _T("com.foo.bar"));
MojErrCheck(err);
err = obj.putInt(_T("size"), quotaUsage1);
MojErrCheck(err);
err = db.putQuotas(&obj, &obj + 1);
MojErrCheck(err);
err = put(db, MojTestKind1Objects[3]);
MojTestErrExpected(err, MojErrDbQuotaExceeded);
// make sure we can delete the kind
MojString kindStr;
err = kindStr.assign(_T("Test:1"));
MojTestErrCheck(err);
bool found = false;
err = db.delKind(kindStr, found);
MojTestErrCheck(err);
MojTestAssert(found);
return MojErrNone;
}
示例6: MojTestErrCheck
MojErr MojDbPermissionTest::testAdminPermissions(MojDb& db)
{
MojObject permission;
MojErr err = permission.fromJson(MojTestAdminPermission1);
MojTestErrCheck(err);
err = db.putPermissions(&permission, &permission + 1);
MojTestErrCheck(err);
MojDbReq reqAdmin(false);
err = reqAdmin.domain(_T("com.admin"));
MojTestErrCheck(err);
// put kind with non-matching owner with admin role
MojObject kind;
err = kind.fromJson(MojTestKind1);
MojTestErrCheck(err);
err = db.putKind(kind, MojDb::FlagNone, reqAdmin);
MojTestErrCheck(err);
err = kind.fromJson(MojTestKind2);
MojTestErrCheck(err);
err = db.putKind(kind, MojDb::FlagNone, reqAdmin);
MojTestErrCheck(err);
return MojErrNone;
}
示例7: run
MojErr MojDbQuotaTest::run()
{
MojDb db;
MojErr err = db.open(MojDbTestDir);
MojTestErrCheck(err);
MojObject obj;
err = obj.fromJson(MojTestKind1Str1);
MojTestErrCheck(err);
err = db.putKind(obj);
MojTestErrCheck(err);
err = testUsage(db);
MojTestErrCheck(err);
err = testMultipleQuotas(db);
MojTestErrCheck(err);
err = testEnforce(db);
MojTestErrCheck(err);
err = db.close();
MojErrCheck(err);
err = testErrors();
MojTestErrCheck(err);
return MojErrNone;
}
示例8: run
MojErr MojDbDistinctTest::run()
{
// TODO : description, youngseung.ji
MojDb db;
MojErr err = db.open(MojDbTestDir);
MojTestErrCheck(err);
// add kind
MojObject kindObj;
err = kindObj.fromJson(MojDistinctKindStr);
MojTestErrCheck(err);
err = db.putKind(kindObj);
MojTestErrCheck(err);
// put test objects
for (MojSize i = 0; i < sizeof(MojDistinctTestObjects) / sizeof(MojChar*); ++i) {
MojObject obj;
err = obj.fromJson(MojDistinctTestObjects[i]);
MojTestErrCheck(err);
err = db.put(obj);
MojTestErrCheck(err);
}
// Start testing
err = simpleTest(db);
MojTestErrCheck(err);
err = db.close();
MojTestErrCheck(err);
return MojErrNone;
}
示例9: getKindUsage
MojErr MojDbQuotaTest::getKindUsage(MojDb& db, const MojChar* kindId, MojInt64& usageOut)
{
MojRefCountedPtr<MojDbStorageTxn> txn;
MojErr err = db.storageEngine()->beginTxn(txn);
MojTestErrCheck(err);
err = db.quotaEngine()->kindUsage(kindId, usageOut, txn.get());
MojTestErrCheck(err);
return MojErrNone;
}
示例10: MojTestAssert
MojErr MojDbPurgeTest::checkObjectsPurged(MojDb& db, const MojUInt32& count, const MojSize& expectedCount,
const MojSize& expectedNumObjects, const MojSize& expectedNumRevTimestampObjects, const MojObject& expectedLastPurgeRevNum)
{
//check number of objects purged
MojTestAssert(count == expectedCount);
//there should still be expectedNumObjects test objects
MojDbQuery query;
MojErr err = query.from(_T("PurgeTest:1"));
MojTestErrCheck(err);
MojDbCursor cursor;
err = db.find(query, cursor);
MojTestErrCheck(err);
MojUInt32 objCount;
err = cursor.count(objCount);
MojTestErrCheck(err);
err = cursor.close();
MojTestErrCheck(err);
MojTestAssert(objCount == expectedNumObjects);
//there should be expectedNumRevTimestampObjects RevTimestamp objects
MojDbQuery revQuery;
err = revQuery.from(MojDbKindEngine::RevTimestampId);
MojTestErrCheck(err);
MojDbCursor revCursor;
err = db.find(revQuery, revCursor);
MojTestErrCheck(err);
MojUInt32 revTimestampObjCount;
err = revCursor.count(revTimestampObjCount);
MojTestErrCheck(err);
err = revCursor.close();
MojTestErrCheck(err);
MojTestAssert(revTimestampObjCount == expectedNumRevTimestampObjects);
//lastPurgedRevNum should be equal to the expectedLastPurgeRevNum
MojObject revNum;
err = db.purgeStatus(revNum);
MojTestErrCheck(err);
MojTestAssert(revNum == expectedLastPurgeRevNum);
return MojErrNone;
}
示例11: MojTestErrCheck
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;
}
示例12: putLargeArrayObj
MojErr MojDbPerfCreateTest::putLargeArrayObj(MojDb& db, const MojChar* kindId, MojUInt64& lgArrayObjTime)
{
timespec startTime;
startTime.tv_nsec = 0;
startTime.tv_sec = 0;
timespec endTime;
endTime.tv_nsec = 0;
endTime.tv_sec = 0;
for (MojUInt64 i = 0; i < numInsert; i++) {
MojObject obj;
MojErr err = obj.putString(MojDb::KindKey, kindId);
MojTestErrCheck(err);
err = createLargeArrayObj(obj, i);
MojTestErrCheck(err);
clock_gettime(CLOCK_REALTIME, &startTime);
err = db.put(obj);
MojTestErrCheck(err);
clock_gettime(CLOCK_REALTIME, &endTime);
lgArrayObjTime += timeDiff(startTime, endTime);
totalTestTime += timeDiff(startTime, endTime);
}
return MojErrNone;
}
示例13: verifyRecords
/**
* verifyRecords
*/
MojErr MojDbShardManagerTest::verifyRecords (const MojChar* strKind, MojDb& db, const MojDbShardInfo&, MojUInt32& count)
{
MojDbQuery query;
MojDbCursor cursor;
count = 0;
MojErr err = query.from(strKind);
MojErrCheck(err);
err = db.find(query, cursor);
MojErrCheck(err);
while (true)
{
bool found;
MojObject dbObj;
err = cursor.get(dbObj, found);
MojErrCheck(err);
if (!found)
break;
++count;
}
return MojErrNone;
}
示例14: verifyKindExistance
/**
* is kind exist?
*/
MojErr MojDbShardManagerTest::verifyKindExistance (MojString kindId, MojDb& db)
{
bool foundOurKind = false;
MojString str; //for debug
//kinds map
MojDbKindEngine::KindMap& map = db.kindEngine()->kindMap();
for (MojDbKindEngine::KindMap::ConstIterator it = map.begin();
it != map.end();
++it)
{
str = it.key();
if(kindId == str)
{
foundOurKind = true;
break;
}
}
if (!foundOurKind)
MojErrThrowMsg(MojErrDbKindNotRegistered, "Kind %s not found in kindMap", kindId.data());
return MojErrNone;
}
示例15: batchPutLargeArrayObj
MojErr MojDbPerfCreateTest::batchPutLargeArrayObj(MojDb& db, const MojChar* kindId, MojUInt64& lgArrayObjTime)
{
timespec startTime;
startTime.tv_nsec = 0;
startTime.tv_sec = 0;
timespec endTime;
endTime.tv_nsec = 0;
endTime.tv_sec = 0;
MojObject objArray;
for (MojUInt64 i = 0; i < numInsert; i++) {
MojObject obj;
MojErr err = obj.putString(MojDb::KindKey, kindId);
MojTestErrCheck(err);
err = createLargeArrayObj(obj, i);
MojTestErrCheck(err);
err = objArray.push(obj);
MojTestErrCheck(err);
}
MojObject::ArrayIterator begin;
MojErr err = objArray.arrayBegin(begin);
MojTestErrCheck(err);
MojObject::ConstArrayIterator end = objArray.arrayEnd();
clock_gettime(CLOCK_REALTIME, &startTime);
err = db.put(begin, end);
MojTestErrCheck(err);
clock_gettime(CLOCK_REALTIME, &endTime);
lgArrayObjTime += timeDiff(startTime, endTime);
totalTestTime += timeDiff(startTime, endTime);
return MojErrNone;
}