本文整理汇总了C++中MojDb::putQuotas方法的典型用法代码示例。如果您正苦于以下问题:C++ MojDb::putQuotas方法的具体用法?C++ MojDb::putQuotas怎么用?C++ MojDb::putQuotas使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MojDb
的用法示例。
在下文中一共展示了MojDb::putQuotas方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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;
}
示例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: 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;
}
示例4: testMultipleQuotas
MojErr MojDbQuotaTest::testMultipleQuotas(MojDb& db)
{
// quota for com.foo.baz
MojObject obj;
MojErr err = obj.fromJson(_T("{\"owner\":\"com.foo.baz\",\"size\":1000}"));
MojErrCheck(err);
err = db.putQuotas(&obj, &obj + 1);
MojErrCheck(err);
// register kinds
err = obj.fromJson(MojTestKind1Str1);
MojTestErrCheck(err);
err = db.putKind(obj);
MojTestErrCheck(err);
err = obj.fromJson(MojTestKind2Str1);
MojTestErrCheck(err);
err = db.putKind(obj);
MojTestErrCheck(err);
// put object of kind1 and kind2
err = put(db, MojTestKind1Objects[0]);
MojTestErrCheck(err);
err = put(db, MojTestKind2Objects[0]);
MojTestErrCheck(err);
MojInt64 quotaUsage1 = 0;
err = getQuotaUsage(db, _T("com.foo.bar"), quotaUsage1);
MojTestErrCheck(err);
MojInt64 quotaUsage2 = 0;
err = getQuotaUsage(db, _T("com.foo.baz"), quotaUsage2);
MojTestErrCheck(err);
MojTestAssert(quotaUsage1 > 0);
MojTestAssert(quotaUsage2 == 0);
// change owner of kind2 to com.foo.baz
err = obj.fromJson(MojTestKind2Str2);
MojTestErrCheck(err);
err = db.putKind(obj);
MojTestErrCheck(err);
MojInt64 quotaUsage3 = 0;
err = getQuotaUsage(db, _T("com.foo.bar"), quotaUsage3);
MojTestErrCheck(err);
MojInt64 quotaUsage4 = 0;
err = getQuotaUsage(db, _T("com.foo.baz"), quotaUsage4);
MojTestErrCheck(err);
MojTestAssert(quotaUsage3 > 0);
MojTestAssert(quotaUsage3 == quotaUsage4);
// make kind2 inherit from kind1
err = obj.fromJson(MojTestKind2Str3);
MojTestErrCheck(err);
err = db.putKind(obj);
MojTestErrCheck(err);
MojInt64 quotaUsage5 = 0;
err = getQuotaUsage(db, _T("com.foo.bar"), quotaUsage5);
MojTestErrCheck(err);
MojInt64 quotaUsage6 = 0;
err = getQuotaUsage(db, _T("com.foo.baz"), quotaUsage6);
MojTestErrCheck(err);
MojTestAssert(quotaUsage5 > quotaUsage1);
MojTestAssert(quotaUsage6 == 0);
// kind3 and object
err = obj.fromJson(MojTestKind3Str1);
MojTestErrCheck(err);
err = db.putKind(obj);
MojTestErrCheck(err);
err = put(db, MojTestKind3Objects[0]);
MojTestErrCheck(err);
MojInt64 quotaUsage7 = 0;
err = getQuotaUsage(db, _T("com.foo.bar"), quotaUsage7);
MojTestErrCheck(err);
MojTestAssert(quotaUsage7 == quotaUsage5);
// wildcard
err = obj.fromJson(_T("{\"owner\":\"com.foo.*\",\"size\":1000}"));
MojErrCheck(err);
err = db.putQuotas(&obj, &obj + 1);
MojErrCheck(err);
MojInt64 quotaUsage8 = 0;
err = getQuotaUsage(db, _T("com.foo.bar"), quotaUsage8);
MojTestErrCheck(err);
MojInt64 quotaUsage9 = 0;
err = getQuotaUsage(db, _T("com.foo.*"), quotaUsage9);
MojTestErrCheck(err);
MojTestAssert(quotaUsage8 == quotaUsage5);
MojTestAssert(quotaUsage9 > 0);
return MojErrNone;
}
示例5: testUsage
MojErr MojDbQuotaTest::testUsage(MojDb& db)
{
// put quota
MojObject obj;
MojErr err = obj.fromJson(_T("{\"owner\":\"com.foo.bar\",\"size\":1000}"));
MojErrCheck(err);
err = db.putQuotas(&obj, &obj + 1);
MojErrCheck(err);
// empty
MojInt64 kindUsage = 0;
err = getKindUsage(db, _T("Test:1"), kindUsage);
MojTestErrCheck(err);
MojTestAssert(kindUsage == 0);
MojInt64 quotaUsage = 0;
err = getQuotaUsage(db, _T("com.foo.bar"), quotaUsage);
MojTestErrCheck(err);
MojTestAssert(quotaUsage == 0);
// new obj
err = put(db, MojTestKind1Objects[0]);
MojTestErrCheck(err);
MojInt64 kindUsage1 = 0;
err = getKindUsage(db, _T("Test:1"), kindUsage1);
MojTestErrCheck(err);
MojTestAssert(kindUsage1 > 0);
MojInt64 quotaUsage1 = 0;
err = getQuotaUsage(db, _T("com.foo.bar"), quotaUsage1);
MojTestErrCheck(err);
MojTestAssert(quotaUsage1 > 0);
// add prop to existing obj
err = obj.fromJson(MojTestKind1Objects[0]);
MojTestErrCheck(err);
err = obj.put(_T("bar"), 2);
MojTestErrCheck(err);
err = db.put(obj, MojDb::FlagForce);
MojTestErrCheck(err);
MojInt64 kindUsage2 = 0;
err = getKindUsage(db, _T("Test:1"), kindUsage2);
MojTestErrCheck(err);
MojTestAssert(kindUsage2 > kindUsage1);
MojInt64 quotaUsage2 = 0;
err = getQuotaUsage(db, _T("com.foo.bar"), quotaUsage2);
MojTestErrCheck(err);
MojTestAssert(quotaUsage2 > quotaUsage1);
// add 2nd obj
err = put(db, MojTestKind1Objects[1]);
MojTestErrCheck(err);
MojInt64 kindUsage3 = 0;
err = getKindUsage(db, _T("Test:1"), kindUsage3);
MojTestErrCheck(err);
MojTestAssert(kindUsage3 > kindUsage2);
MojInt64 quotaUsage3 = 0;
err = getQuotaUsage(db, _T("com.foo.bar"), quotaUsage3);
MojTestErrCheck(err);
MojTestAssert(quotaUsage3 > quotaUsage2);
// del first obj
bool found = false;
err = db.del(1, found, MojDb::FlagPurge);
MojTestErrCheck(err);
MojTestAssert(found);
MojInt64 kindUsage4 = 0;
err = getKindUsage(db, _T("Test:1"), kindUsage4);
MojTestErrCheck(err);
MojTestAssert(kindUsage4 == kindUsage3 - kindUsage2);
MojInt64 quotaUsage4 = 0;
err = getQuotaUsage(db, _T("com.foo.bar"), quotaUsage4);
MojTestErrCheck(err);
MojTestAssert(quotaUsage4 == quotaUsage3 - quotaUsage2);
// add index
err = obj.fromJson(MojTestKind1Str2);
MojTestErrCheck(err);
err = db.putKind(obj);
MojTestErrCheck(err);
MojInt64 kindUsage5 = 0;
err = getKindUsage(db, _T("Test:1"), kindUsage5);
MojTestErrCheck(err);
MojTestAssert(kindUsage5 > kindUsage4);
MojInt64 quotaUsage5 = 0;
err = getQuotaUsage(db, _T("com.foo.bar"), quotaUsage5);
MojTestErrCheck(err);
MojTestAssert(quotaUsage5 > quotaUsage4);
// update locale
err = db.updateLocale(_T("FR_fr"));
MojTestErrCheck(err);
err = db.updateLocale(_T("EN_us"));
MojTestErrCheck(err);
MojInt64 kindUsage6 = 0;
err = getKindUsage(db, _T("Test:1"), kindUsage6);
MojTestErrCheck(err);
MojTestAssert(kindUsage6 == kindUsage5);
MojInt64 quotaUsage6 = 0;
err = getQuotaUsage(db, _T("com.foo.bar"), quotaUsage6);
MojTestErrCheck(err);
MojTestAssert(quotaUsage6 == quotaUsage5);
// drop index
err = obj.fromJson(MojTestKind1Str1);
MojTestErrCheck(err);
err = db.putKind(obj);
MojTestErrCheck(err);
MojInt64 kindUsage7 = 0;
err = getKindUsage(db, _T("Test:1"), kindUsage7);
//.........这里部分代码省略.........