本文整理汇总了C++中MojDb::close方法的典型用法代码示例。如果您正苦于以下问题:C++ MojDb::close方法的具体用法?C++ MojDb::close怎么用?C++ MojDb::close使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MojDb
的用法示例。
在下文中一共展示了MojDb::close方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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;
}
示例2: 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;
}
示例3: run
MojErr MojDbPermissionTest::run()
{
MojDb db;
MojObject conf;
MojErr err = conf.fromJson(MojTestConf);
MojTestErrCheck(err);
err = db.configure(conf);
MojErrCheck(err);
err = db.open(MojDbTestDir);
MojTestErrCheck(err);
err = testInvalidPermissions(db);
MojTestErrCheck(err);
err = testAdminPermissions(db);
MojTestErrCheck(err);
err = testKindPermissions(db);
MojTestErrCheck(err);
err = testObjectPermissions(db);
MojTestErrCheck(err);
err = db.close();
MojTestErrCheck(err);
return MojErrNone;
}
示例4: run
/**
* 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: testErrors
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;
}
示例6: run
MojErr MojDbSearchTest::run()
{
MojDb db;
MojErr err = db.open(MojDbTestDir);
MojTestErrCheck(err);
// add kind
MojObject kindObj;
err = kindObj.fromJson(MojSearchKindStr);
MojTestErrCheck(err);
err = db.putKind(kindObj);
MojTestErrCheck(err);
// put test objects
for (MojSize i = 0; i < sizeof(MojSearchTestObjects) / sizeof(MojChar*); ++i) {
MojObject obj;
err = obj.fromJson(MojSearchTestObjects[i]);
MojTestErrCheck(err);
err = db.put(obj);
MojTestErrCheck(err);
}
err = simpleTest(db);
MojTestErrCheck(err);
err = filterTest(db);
MojTestErrCheck(err);
// add kind for page test
err = kindObj.fromJson(MojSearchKindStr2);
MojTestErrCheck(err);
err = db.putKind(kindObj);
MojTestErrCheck(err);
// put test objects for page test
for (MojSize i = 0; i < sizeof(MojSearchTestObjects2) / sizeof(MojChar*); ++i) {
MojObject obj;
err = obj.fromJson(MojSearchTestObjects2[i]);
MojTestErrCheck(err);
err = db.put(obj);
MojTestErrCheck(err);
}
err = pageTest(db);
MojTestErrCheck(err);
err = db.close();
MojTestErrCheck(err);
return MojErrNone;
}
示例7: testObjectPermissions
MojErr MojDbPermissionTest::testObjectPermissions(MojDb& db)
{
MojErr err = putPermissions(db);
MojTestErrCheck(err);
err = checkPermissions(db);
MojTestErrCheck(err);
err = db.close();
MojTestErrCheck(err);
err = db.open(MojDbTestDir);
MojTestErrCheck(err);
err = checkPermissions(db);
MojTestErrCheck(err);
return MojErrNone;
}
示例8: run
MojErr MojDbPerfUpdateTest::run()
{
MojErr err = file.open(UpdateTestFileName, MOJ_O_RDWR | MOJ_O_CREAT | MOJ_O_TRUNC, MOJ_S_IRUSR | MOJ_S_IWUSR);
MojTestErrCheck(err);
MojString buf;
err = buf.format("MojoDb Update Performance Test,,,,,\n\nOperation,Kind,Total Time,Time Per Iteration,Time Per Object\n");
MojTestErrCheck(err);
err = fileWrite(file, buf);
MojTestErrCheck(err);
MojDb db;
err = db.open(MojDbTestDir);
MojTestErrCheck(err);
err = testPut(db);
MojTestErrCheck(err);
err = testMerge(db);
MojTestErrCheck(err);
err = testUpdateKind(db);
MojTestErrCheck(err);
err = MojPrintF("\n\n TOTAL TEST TIME: %llu microseconds\n\n", totalTestTime.microsecs());
MojTestErrCheck(err);
err = MojPrintF("\n-------\n");
MojTestErrCheck(err);
err = buf.format("\n\nTOTAL TEST TIME,,%llu,,,", totalTestTime.microsecs());
MojTestErrCheck(err);
err = fileWrite(file, buf);
MojTestErrCheck(err);
err = db.close();
MojTestErrCheck(err);
err = file.close();
MojTestErrCheck(err);
return MojErrNone;
}
示例9: run
MojErr MojDbWatchTest::run()
{
MojDb db;
MojErr err = db.open(MojDbTestDir);
MojTestErrCheck(err);
MojObject type;
err = type.fromJson(MojKindStr);
MojTestErrCheck(err);
err = db.putKind(type);
MojTestErrCheck(err);
// eq
err = eqTest(db);
MojTestErrCheck(err);
// gt
err = gtTest(db);
MojTestErrCheck(err);
// lt
err = ltTest(db);
MojTestErrCheck(err);
// cancel
err = cancelTest(db);
MojTestErrCheck(err);
// range
err = rangeTest(db);
MojTestErrCheck(err);
// pages
err = pageTest(db);
MojTestErrCheck(err);
// make sure we're not hanging onto watcher references
MojTestAssert(TestWatcher::s_instanceCount == 0);
err = db.close();
MojTestErrCheck(err);
return MojErrNone;
}
示例10: run
MojErr MojDbSearchCacheTest::run()
{
MojDb db;
MojErr err = db.open(MojDbTestDir);
MojTestErrCheck(err);
// add kind
MojObject kindObj;
err = kindObj.fromJson(SearchCacheKindStr);
MojTestErrCheck(err);
err = db.putKind(kindObj);
MojTestErrCheck(err);
// put test objects
for (MojSize i = 0; i < sizeof(MojSearchCacheObjects) / sizeof(MojChar*); ++i) {
MojObject obj;
err = obj.fromJson(MojSearchCacheObjects[i]);
MojTestErrCheck(err);
err = db.put(obj);
MojTestErrCheck(err);
}
err = testQueryKey();
MojTestErrCheck(err);
err = operatorTest(db);
MojTestErrCheck(err);
/*** :: TODO :: make query scenario
err = queryTest(db);
MojTestErrCheck(err);
***/
err = db.close();
MojTestErrCheck(err);
return MojErrNone;
}
示例11: TearDown
void TearDown()
{
// TODO: clean DB
MojExpectNoErr( db.close() );
}
示例12: run
//.........这里部分代码省略.........
MojTestErrCheck(err);
//create a RevTimestamp entry - that's not more than PurgeNumDays days ago
MojTime time;
err = MojGetCurrentTime(time);
MojTestErrCheck(err);
err = createRevTimestamp(db, revNums[0], time.microsecs());
MojTestErrCheck(err);
//purge now, there are no RevTimestamp entries that are more than
//PurgeNumDays ago, so nothing should be purged
count = 0;
err = db.purge(count, 30);
MojTestErrCheck(err);
err = checkObjectsPurged(db, count, 0, 10, 3, -1);
MojTestErrCheck(err);
//create a RevTimestamp entry for more than PurgeNumDays days ago
err = MojGetCurrentTime(time);
MojTestErrCheck(err);
err = createRevTimestamp(db, revNums[9], time.microsecs() - (((MojInt64)40) * MojTime::UnitsPerDay));
MojTestErrCheck(err);
//purge now, since nothing has been deleted, nothing should be purged,
//but the RevTimestamp object should be deleted
count = 0;
err = db.purge(count, 30);
MojTestErrCheck(err);
err = checkObjectsPurged(db, count, 0, 10, 4, -1);
MojTestErrCheck(err);
//delete something - this will set its revision number higher
bool found;
err = db.del(ids[0], found);
MojTestErrCheck(err);
MojTestAssert(found == true);
//purge now, since nothing has been deleted prior to the revision
//number, nothing should be purged
count = 0;
err = db.purge(count, 30);
MojTestErrCheck(err);
err = checkObjectsPurged(db, count, 0, 9, 5, -1);
MojTestErrCheck(err);
//delete another object
err = db.del(ids[1], found);
MojTestErrCheck(err);
MojTestAssert(found == true);
//create a RevTimestamp entry for more than PurgeNumDays days ago,
//with the rev number of the 1st obj we deleted
MojDbQuery query;
err = query.from(_T("PurgeTest:1"));
MojTestErrCheck(err);
err = query.where(MojDb::IdKey, MojDbQuery::OpEq, ids[0]);
MojTestErrCheck(err);
err = query.includeDeleted();
MojTestErrCheck(err);
MojDbCursor cursor;
err = db.find(query, cursor);
MojTestErrCheck(err);
MojObject objFromDb;
err = cursor.get(objFromDb, found);
MojTestErrCheck(err);
err = cursor.close();
MojTestErrCheck(err);
MojTestAssert(found == true);
MojObject revFromDb;
err = objFromDb.getRequired(MojDb::RevKey, revFromDb);
MojTestErrCheck(err);
err = MojGetCurrentTime(time);
MojTestErrCheck(err);
err = createRevTimestamp(db, revFromDb, time.microsecs() - (((MojInt64)35) * MojTime::UnitsPerDay));
MojTestErrCheck(err);
//now purge, only id[0] should be purged
count = 0;
err = db.purge(count, 30);
MojTestErrCheck(err);
err = checkObjectsPurged(db, count, 1, 8, 6, revFromDb);
MojTestErrCheck(err);
//TODO 2.12.10 - this test does not pass yet, we need to fix calling delKind after a purge
//err = delKindTest(db);
//MojTestErrCheck(err);
err = db.close();
MojTestErrCheck(err);
return MojErrNone;
}
示例13: testCreate
MojErr MojDbPerfCreateTest::testCreate()
{
MojDb db;
MojErr err = db.open(MojDbTestDir);
MojTestErrCheck(err);
// time put kind
MojUInt64 putKindTime = 0;
for (int i = 0; i < numRepetitions; i++) {
err = putKinds(db, putKindTime);
MojTestErrCheck(err);
err = delKinds(db);
MojTestErrCheck(err);
}
err = MojPrintF("\n -------------------- \n");
MojTestErrCheck(err);
err = MojPrintF(" putKind took: %llu nanosecs", (putKindTime / (numKinds * numRepetitions)));
MojTestErrCheck(err);
err = MojPrintF("\n\n");
MojTestErrCheck(err);
MojString buf;
err = buf.format("put Kind,all %llu kinds,%llu,%llu,%llu,\n", numKinds, putKindTime, putKindTime/numRepetitions, putKindTime / (numKinds * numRepetitions));
MojTestErrCheck(err);
err = fileWrite(file, buf);
MojTestErrCheck(err);
// insert objects with one index
err = testInsertSmallObj(db, MojPerfSmKindId);
MojTestErrCheck(err);
err = testInsertMedObj(db, MojPerfMedKindId);
MojTestErrCheck(err);
err = testInsertLgObj(db, MojPerfLgKindId);
MojTestErrCheck(err);
err = testInsertMedNestedObj(db, MojPerfMedNestedKindId);
MojTestErrCheck(err);
err = testInsertLgNestedObj(db, MojPerfLgNestedKindId);
MojTestErrCheck(err);
err = testInsertMedArrayObj(db, MojPerfMedArrayKindId);
MojTestErrCheck(err);
err = testInsertLgArrayObj(db, MojPerfLgArrayKindId);
MojTestErrCheck(err);
// insert objects with two indices
err = testInsertSmallObj(db, MojPerfSmKind2Id);
MojTestErrCheck(err);
err = testInsertMedObj(db, MojPerfMedKind2Id);
MojTestErrCheck(err);
err = testInsertLgObj(db, MojPerfLgKind2Id);
MojTestErrCheck(err);
err = testInsertMedNestedObj(db, MojPerfMedNestedKind2Id);
MojTestErrCheck(err);
err = testInsertLgNestedObj(db, MojPerfLgNestedKind2Id);
MojTestErrCheck(err);
err = testInsertMedArrayObj(db, MojPerfMedArrayKind2Id);
MojTestErrCheck(err);
err = testInsertLgArrayObj(db, MojPerfLgArrayKind2Id);
MojTestErrCheck(err);
// batch insert with one index
err = testBatchInsertLgObj(db, MojPerfLgKindId);
MojTestErrCheck(err);
err = testBatchInsertLgNestedObj(db, MojPerfLgNestedKindId);
MojTestErrCheck(err);
err = testBatchInsertLgArrayObj(db, MojPerfLgArrayKindId);
MojTestErrCheck(err);
// batch insert with two indices
err = testBatchInsertLgObj(db, MojPerfLgKind2Id);
MojTestErrCheck(err);
err = testBatchInsertLgNestedObj(db, MojPerfLgNestedKind2Id);
MojTestErrCheck(err);
err = testBatchInsertLgArrayObj(db, MojPerfLgArrayKind2Id);
MojTestErrCheck(err);
err = db.close();
MojTestErrCheck(err);
return MojErrNone;
}
示例14: run
//.........这里部分代码省略.........
MojDbQuery query;
err = query.from(_T("Test:1"));
MojTestErrCheck(err);
err = query.where(_T("bar"), MojDbQuery::OpEq, -2);
MojTestErrCheck(err);
MojObject update;
err = update.put(_T("bar"), -2);
MojTestErrCheck(err);
MojUInt32 count = 0;
err = db.merge(query, update, count);
MojTestErrCheck(err);
MojTestAssert(count == 0);
}
// test visibility with delete
{
MojDbReq req;
// start transaction
req.begin(&db, false);
MojDbQuery query;
err = query.from(_T("Test:1"));
MojTestErrCheck(err);
err = query.where(_T("bar"), MojDbQuery::OpEq, -1);
MojTestErrCheck(err);
MojUInt32 count = 0;
err = db.del(query, count, MojDb::FlagNone, req);
MojTestErrCheck(err);
MojTestAssert(count == 50);
// txn: x25 = (50,1) .. x74 = (99,2)
// visible within transaction
{
MojDbQuery query;
err = query.from(_T("Test:1"));
MojTestErrCheck(err);
err = query.where(_T("bar"), MojDbQuery::OpLessThan, 2);
MojTestErrCheck(err);
MojObject update;
err = update.put(_T("bar"), -3);
MojTestErrCheck(err);
MojUInt32 count = 0;
err = db.merge(query, update, count, MojDb::FlagNone, req);
MojTestErrCheck(err);
MojTestAssert(count == 33);
}
// With BerkeleyDB parallel transaction is locked
// invisible outside of transaction
if (engineName().compare(_T("leveldb")) == 0)
{
MojDbQuery query;
err = query.from(_T("Test:1"));
MojTestErrCheck(err);
err = query.where(_T("bar"), MojDbQuery::OpLessThan, 2);
MojTestErrCheck(err);
MojObject update;
err = update.put(_T("bar"), -3);
MojTestErrCheck(err);
MojUInt32 count = 0;
err = db.merge(query, update, count);
MojTestErrCheck(err);
MojTestAssert(count == 83);
}
}
// invisible after aborted transaction
{
MojDbQuery query;
err = query.from(_T("Test:1"));
MojTestErrCheck(err);
err = query.where(_T("bar"), MojDbQuery::OpLessThan, 2);
MojTestErrCheck(err);
MojObject update;
// Note that if we change bar=1 here we might get double-update when
// record we just updated moved into records range ahead of our current
// cursor position
MojUInt32 count = 0;
err = db.merge(query, update, count);
MojTestErrCheck(err);
MojTestAssert(count == 83);
}
err = db.close();
MojTestErrCheck(err);
return MojErrNone;
}
示例15: run
//.........这里部分代码省略.........
MojTestErrCheck(err);
// put identical obj and verify rev not changed
err = db.put(obj);
MojTestErrCheck(err);
err = checkRevEq(db, id, rev);
MojTestErrCheck(err);
// put with changed prop and verify rev gt
err = obj.fromJson(MojTestObjStr2);
MojTestErrCheck(err);
err = obj.put(MojDb::IdKey, id);
MojTestErrCheck(err);
err = db.put(obj); // this put will fail because we haven't included a rev
MojTestErrExpected(err, MojErrDbRevNotSpecified);
bool found = false;
err = db.del(id, found); // verify that we can put without a rev if the object is deleted
MojTestErrCheck(err);
MojTestAssert(found);
err = db.put(obj);
MojTestErrCheck(err);
err = obj.getRequired(MojDb::RevKey, rev);
MojTestErrCheck(err);
err = obj.put(MojDb::RevKey, 1);
MojTestErrCheck(err);
err = db.put(obj); // this put will fail because the revision num is lower
MojTestErrExpected(err, MojErrDbRevisionMismatch);
err = obj.put(MojDb::RevKey, rev);
MojTestErrCheck(err);
err = db.put(obj); // now this should succeed
MojTestErrCheck(err);
// merge with unchanged prop and verify rev not changed
err = obj.fromJson(MojTestObjStr3);
MojTestErrCheck(err);
err = obj.put(MojDb::IdKey, id);
MojTestErrCheck(err);
err = db.merge(obj);
MojTestErrCheck(err);
err = checkRevEq(db, id, rev);
MojTestErrCheck(err);
// merge with changed prop and verify rev gt
err = obj.fromJson(MojTestObjStr4);
MojTestErrCheck(err);
err = obj.put(MojDb::IdKey, id);
MojTestErrCheck(err);
err = db.merge(obj);
MojTestErrCheck(err);
err = checkRevGt(db, id, rev);
MojTestErrCheck(err);
// query merge with unchanged prop and verify rev not changed
MojDbQuery query;
err = query.from("RevTest:1");
MojTestErrCheck(err);
err = obj.fromJson(MojTestObjStr4);
MojTestErrCheck(err);
MojUInt32 count = 0;
err = db.merge(query, obj, count);
MojTestErrCheck(err);
MojTestAssert(count == 1);
err = checkRevEq(db, id, rev);
MojTestErrCheck(err);
// query merge with changed prop and verify rev gt
err = obj.fromJson(MojTestObjStr3);
MojTestErrCheck(err);
err = db.merge(query, obj, count);
MojTestErrCheck(err);
MojTestAssert(count == 1);
err = checkRevGt(db, id, rev);
MojTestErrCheck(err);
// del verify rev gt
err = db.del(id, found);
MojTestErrCheck(err);
MojTestAssert(found);
err = checkRevGt(db, id, rev);
MojTestErrCheck(err);
// del again and verify rev not changed
err = db.del(id, found);
MojTestErrCheck(err);
MojTestAssert(found);
err = checkRevEq(db, id, rev);
MojTestErrCheck(err);
// undel and verify rev gt
err = obj.fromJson(MojTestObjStr5);
MojTestErrCheck(err);
err = obj.put(MojDb::IdKey, id);
MojTestErrCheck(err);
err = db.merge(obj);
MojTestErrCheck(err);
err = checkRevGt(db, id, rev);
MojTestErrCheck(err);
// query del and verify rev gt
err = db.del(query, count);
MojTestErrCheck(err);
MojTestAssert(count == 1);
err = checkRevGt(db, id, rev);
MojTestErrCheck(err);
err = db.close();
MojTestErrCheck(err);
return MojErrNone;
}