本文整理汇总了C++中KVEngine类的典型用法代码示例。如果您正苦于以下问题:C++ KVEngine类的具体用法?C++ KVEngine怎么用?C++ KVEngine使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了KVEngine类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: TEST
TEST( KVEngineTestHarness, SimpleRS1 ) {
scoped_ptr<KVHarnessHelper> helper( KVHarnessHelper::create() );
KVEngine* engine = helper->getEngine();
ASSERT( engine );
string ns = "a.b";
scoped_ptr<RecordStore> rs;
{
MyOperationContext opCtx( engine );
ASSERT_OK( engine->createRecordStore( &opCtx, ns, CollectionOptions() ) );
rs.reset( engine->getRecordStore( &opCtx, ns, ns, CollectionOptions() ) );
ASSERT( rs );
}
DiskLoc loc;
{
MyOperationContext opCtx( engine );
WriteUnitOfWork uow( &opCtx );
StatusWith<DiskLoc> res = rs->insertRecord( &opCtx, "abc", 4, false );
ASSERT_OK( res.getStatus() );
loc = res.getValue();
uow.commit();
}
{
MyOperationContext opCtx( engine );
ASSERT_EQUALS( string("abc"), rs->dataFor( &opCtx, loc ).data() );
}
}
示例2: TEST
TEST(KVEngineTestHarness, SimpleSorted1) {
unique_ptr<KVHarnessHelper> helper(KVHarnessHelper::create());
KVEngine* engine = helper->getEngine();
ASSERT(engine);
string ident = "abc";
IndexDescriptor desc(nullptr,
"",
BSON("v" << static_cast<int>(IndexDescriptor::kLatestIndexVersion) << "ns"
<< "mydb.mycoll"
<< "key"
<< BSON("a" << 1)));
unique_ptr<SortedDataInterface> sorted;
{
MyOperationContext opCtx(engine);
ASSERT_OK(engine->createSortedDataInterface(&opCtx, ident, &desc));
sorted.reset(engine->getSortedDataInterface(&opCtx, ident, &desc));
ASSERT(sorted);
}
{
MyOperationContext opCtx(engine);
WriteUnitOfWork uow(&opCtx);
ASSERT_OK(sorted->insert(&opCtx, BSON("" << 5), RecordId(6, 4), true));
uow.commit();
}
{
MyOperationContext opCtx(engine);
ASSERT_EQUALS(1, sorted->numEntries(&opCtx));
}
}
示例3: TEST_F
TEST_F(KVCatalogTest, BackupImplemented) {
unique_ptr<KVHarnessHelper> helper(KVHarnessHelper::create());
KVEngine* engine = helper->getEngine();
ASSERT(engine);
{
MyOperationContext opCtx(engine);
ASSERT_OK(engine->beginBackup(&opCtx));
engine->endBackup(&opCtx);
}
}
示例4: TEST
TEST(KVCatalogTest, DirectoryPerAndSplit1) {
unique_ptr<KVHarnessHelper> helper(KVHarnessHelper::create());
KVEngine* engine = helper->getEngine();
unique_ptr<RecordStore> rs;
unique_ptr<KVCatalog> catalog;
{
MyOperationContext opCtx(engine);
WriteUnitOfWork uow(&opCtx);
ASSERT_OK(engine->createRecordStore(&opCtx, "catalog", "catalog", CollectionOptions()));
rs = engine->getRecordStore(&opCtx, "catalog", "catalog", CollectionOptions());
catalog.reset(new KVCatalog(rs.get(), true, true));
uow.commit();
}
{
MyOperationContext opCtx(engine);
WriteUnitOfWork uow(&opCtx);
ASSERT_OK(
catalog->newCollection(&opCtx, "a.b", CollectionOptions(), KVPrefix::kNotPrefixed));
ASSERT_STRING_CONTAINS(catalog->getCollectionIdent("a.b"), "a/collection/");
ASSERT_TRUE(catalog->isUserDataIdent(catalog->getCollectionIdent("a.b")));
uow.commit();
}
{ // index
MyOperationContext opCtx(engine);
WriteUnitOfWork uow(&opCtx);
BSONCollectionCatalogEntry::MetaData md;
md.ns = "a.b";
md.indexes.push_back(BSONCollectionCatalogEntry::IndexMetaData(BSON("name"
<< "foo"),
false,
RecordId(),
false,
KVPrefix::kNotPrefixed,
false));
catalog->putMetaData(&opCtx, "a.b", md);
ASSERT_STRING_CONTAINS(catalog->getIndexIdent(&opCtx, "a.b", "foo"), "a/index/");
ASSERT_TRUE(catalog->isUserDataIdent(catalog->getIndexIdent(&opCtx, "a.b", "foo")));
uow.commit();
}
}
示例5: TEST
TEST(KVEngineTestHarness, Restart1) {
unique_ptr<KVHarnessHelper> helper(KVHarnessHelper::create());
KVEngine* engine = helper->getEngine();
ASSERT(engine);
string ns = "a.b";
// 'loc' holds location of "abc" and is referenced after restarting engine.
RecordId loc;
{
unique_ptr<RecordStore> rs;
{
MyOperationContext opCtx(engine);
ASSERT_OK(engine->createRecordStore(&opCtx, ns, ns, CollectionOptions()));
rs.reset(engine->getRecordStore(&opCtx, ns, ns, CollectionOptions()));
ASSERT(rs);
}
{
MyOperationContext opCtx(engine);
WriteUnitOfWork uow(&opCtx);
StatusWith<RecordId> res = rs->insertRecord(&opCtx, "abc", 4, false);
ASSERT_OK(res.getStatus());
loc = res.getValue();
uow.commit();
}
{
MyOperationContext opCtx(engine);
ASSERT_EQUALS(string("abc"), rs->dataFor(&opCtx, loc).data());
}
}
// returns null if the engine does not support restart (transient, test-only engines)
engine = helper->restartEngine();
if (engine != NULL) {
unique_ptr<RecordStore> rs;
MyOperationContext opCtx(engine);
rs.reset(engine->getRecordStore(&opCtx, ns, ns, CollectionOptions()));
ASSERT_EQUALS(string("abc"), rs->dataFor(&opCtx, loc).data());
}
}
示例6: TEST
TEST( KVEngineTestHarness, SimpleRS1 ) {
unique_ptr<KVHarnessHelper> helper( KVHarnessHelper::create() );
KVEngine* engine = helper->getEngine();
ASSERT( engine );
string ns = "a.b";
unique_ptr<RecordStore> rs;
{
MyOperationContext opCtx( engine );
ASSERT_OK( engine->createRecordStore( &opCtx, ns, ns, CollectionOptions() ) );
rs.reset( engine->getRecordStore( &opCtx, ns, ns, CollectionOptions() ) );
ASSERT( rs );
}
RecordId loc;
{
MyOperationContext opCtx( engine );
WriteUnitOfWork uow( &opCtx );
StatusWith<RecordId> res = rs->insertRecord( &opCtx, "abc", 4, false );
ASSERT_OK( res.getStatus() );
loc = res.getValue();
uow.commit();
}
{
MyOperationContext opCtx( engine );
ASSERT_EQUALS( string("abc"), rs->dataFor( &opCtx, loc ).data() );
}
{
MyOperationContext opCtx( engine );
std::vector<std::string> all = engine->getAllIdents( &opCtx );
ASSERT_EQUALS( 1U, all.size() );
ASSERT_EQUALS( ns, all[0] );
}
}
示例7: TEST
TEST(KVCatalogTest, Idx1) {
unique_ptr<KVHarnessHelper> helper(KVHarnessHelper::create());
KVEngine* engine = helper->getEngine();
unique_ptr<RecordStore> rs;
unique_ptr<KVCatalog> catalog;
{
MyOperationContext opCtx(engine);
WriteUnitOfWork uow(&opCtx);
ASSERT_OK(engine->createRecordStore(&opCtx, "catalog", "catalog", CollectionOptions()));
rs = engine->getRecordStore(&opCtx, "catalog", "catalog", CollectionOptions());
catalog.reset(new KVCatalog(rs.get(), false, false));
uow.commit();
}
{
MyOperationContext opCtx(engine);
WriteUnitOfWork uow(&opCtx);
ASSERT_OK(
catalog->newCollection(&opCtx, "a.b", CollectionOptions(), KVPrefix::kNotPrefixed));
ASSERT_NOT_EQUALS("a.b", catalog->getCollectionIdent("a.b"));
ASSERT_TRUE(catalog->isUserDataIdent(catalog->getCollectionIdent("a.b")));
uow.commit();
}
{
MyOperationContext opCtx(engine);
WriteUnitOfWork uow(&opCtx);
BSONCollectionCatalogEntry::MetaData md;
md.ns = "a.b";
BSONCollectionCatalogEntry::IndexMetaData imd;
imd.spec = BSON("name"
<< "foo");
imd.ready = false;
imd.head = RecordId();
imd.multikey = false;
imd.prefix = KVPrefix::kNotPrefixed;
imd.isBackgroundSecondaryBuild = false;
md.indexes.push_back(imd);
catalog->putMetaData(&opCtx, "a.b", md);
uow.commit();
}
string idxIndent;
{
MyOperationContext opCtx(engine);
idxIndent = catalog->getIndexIdent(&opCtx, "a.b", "foo");
}
{
MyOperationContext opCtx(engine);
ASSERT_EQUALS(idxIndent, catalog->getIndexIdent(&opCtx, "a.b", "foo"));
ASSERT_TRUE(catalog->isUserDataIdent(catalog->getIndexIdent(&opCtx, "a.b", "foo")));
}
{
MyOperationContext opCtx(engine);
WriteUnitOfWork uow(&opCtx);
BSONCollectionCatalogEntry::MetaData md;
md.ns = "a.b";
catalog->putMetaData(&opCtx, "a.b", md); // remove index
BSONCollectionCatalogEntry::IndexMetaData imd;
imd.spec = BSON("name"
<< "foo");
imd.ready = false;
imd.head = RecordId();
imd.multikey = false;
imd.prefix = KVPrefix::kNotPrefixed;
imd.isBackgroundSecondaryBuild = false;
md.indexes.push_back(imd);
catalog->putMetaData(&opCtx, "a.b", md);
uow.commit();
}
{
MyOperationContext opCtx(engine);
ASSERT_NOT_EQUALS(idxIndent, catalog->getIndexIdent(&opCtx, "a.b", "foo"));
}
}