diff options
Diffstat (limited to 'src/mongo/db/storage/record_store_test_touch.cpp')
-rw-r--r-- | src/mongo/db/storage/record_store_test_touch.cpp | 202 |
1 files changed, 99 insertions, 103 deletions
diff --git a/src/mongo/db/storage/record_store_test_touch.cpp b/src/mongo/db/storage/record_store_test_touch.cpp index 80b8909611c..c765bc2638b 100644 --- a/src/mongo/db/storage/record_store_test_touch.cpp +++ b/src/mongo/db/storage/record_store_test_touch.cpp @@ -40,131 +40,127 @@ using std::stringstream; namespace mongo { - // Verify that calling touch() on an empty collection returns an OK status. - TEST( RecordStoreTestHarness, TouchEmpty ) { - unique_ptr<HarnessHelper> harnessHelper( newHarnessHelper() ); - unique_ptr<RecordStore> rs( harnessHelper->newNonCappedRecordStore() ); - - { - unique_ptr<OperationContext> opCtx( harnessHelper->newOperationContext() ); - ASSERT_EQUALS( 0, rs->numRecords( opCtx.get() ) ); - } - - { - unique_ptr<OperationContext> opCtx( harnessHelper->newOperationContext() ); - { - BSONObjBuilder stats; - Status status = rs->touch( opCtx.get(), &stats ); - ASSERT( status.isOK() || status.code() == ErrorCodes::CommandNotSupported ); - } - } +// Verify that calling touch() on an empty collection returns an OK status. +TEST(RecordStoreTestHarness, TouchEmpty) { + unique_ptr<HarnessHelper> harnessHelper(newHarnessHelper()); + unique_ptr<RecordStore> rs(harnessHelper->newNonCappedRecordStore()); + + { + unique_ptr<OperationContext> opCtx(harnessHelper->newOperationContext()); + ASSERT_EQUALS(0, rs->numRecords(opCtx.get())); } - // Insert multiple records, and verify that calling touch() on a nonempty collection - // returns an OK status. - TEST( RecordStoreTestHarness, TouchNonEmpty ) { - unique_ptr<HarnessHelper> harnessHelper( newHarnessHelper() ); - unique_ptr<RecordStore> rs( harnessHelper->newNonCappedRecordStore() ); - + { + unique_ptr<OperationContext> opCtx(harnessHelper->newOperationContext()); { - unique_ptr<OperationContext> opCtx( harnessHelper->newOperationContext() ); - ASSERT_EQUALS( 0, rs->numRecords( opCtx.get() ) ); + BSONObjBuilder stats; + Status status = rs->touch(opCtx.get(), &stats); + ASSERT(status.isOK() || status.code() == ErrorCodes::CommandNotSupported); } + } +} - int nToInsert = 10; - for ( int i = 0; i < nToInsert; i++ ) { - unique_ptr<OperationContext> opCtx( harnessHelper->newOperationContext() ); - { - stringstream ss; - ss << "record " << i; - string data = ss.str(); - - WriteUnitOfWork uow( opCtx.get() ); - StatusWith<RecordId> res = rs->insertRecord( opCtx.get(), - data.c_str(), - data.size() + 1, - false ); - ASSERT_OK( res.getStatus() ); - uow.commit(); - } - } +// Insert multiple records, and verify that calling touch() on a nonempty collection +// returns an OK status. +TEST(RecordStoreTestHarness, TouchNonEmpty) { + unique_ptr<HarnessHelper> harnessHelper(newHarnessHelper()); + unique_ptr<RecordStore> rs(harnessHelper->newNonCappedRecordStore()); - { - unique_ptr<OperationContext> opCtx( harnessHelper->newOperationContext() ); - ASSERT_EQUALS( nToInsert, rs->numRecords( opCtx.get() ) ); - } + { + unique_ptr<OperationContext> opCtx(harnessHelper->newOperationContext()); + ASSERT_EQUALS(0, rs->numRecords(opCtx.get())); + } + int nToInsert = 10; + for (int i = 0; i < nToInsert; i++) { + unique_ptr<OperationContext> opCtx(harnessHelper->newOperationContext()); { - unique_ptr<OperationContext> opCtx( harnessHelper->newOperationContext() ); - { - BSONObjBuilder stats; - // XXX does not verify the collection was loaded into cache - // (even if supported by storage engine) - Status status = rs->touch( opCtx.get(), &stats ); - ASSERT( status.isOK() || status.code() == ErrorCodes::CommandNotSupported ); - } + stringstream ss; + ss << "record " << i; + string data = ss.str(); + + WriteUnitOfWork uow(opCtx.get()); + StatusWith<RecordId> res = + rs->insertRecord(opCtx.get(), data.c_str(), data.size() + 1, false); + ASSERT_OK(res.getStatus()); + uow.commit(); } } - // Verify that calling touch() on an empty collection returns an OK status, - // even when NULL is passed in for the stats output. - TEST( RecordStoreTestHarness, TouchEmptyWithNullStats ) { - unique_ptr<HarnessHelper> harnessHelper( newHarnessHelper() ); - unique_ptr<RecordStore> rs( harnessHelper->newNonCappedRecordStore() ); + { + unique_ptr<OperationContext> opCtx(harnessHelper->newOperationContext()); + ASSERT_EQUALS(nToInsert, rs->numRecords(opCtx.get())); + } + { + unique_ptr<OperationContext> opCtx(harnessHelper->newOperationContext()); { - unique_ptr<OperationContext> opCtx( harnessHelper->newOperationContext() ); - ASSERT_EQUALS( 0, rs->numRecords( opCtx.get() ) ); + BSONObjBuilder stats; + // XXX does not verify the collection was loaded into cache + // (even if supported by storage engine) + Status status = rs->touch(opCtx.get(), &stats); + ASSERT(status.isOK() || status.code() == ErrorCodes::CommandNotSupported); } + } +} - { - unique_ptr<OperationContext> opCtx( harnessHelper->newOperationContext() ); - Status status = rs->touch( opCtx.get(), NULL /* stats output */ ); - ASSERT( status.isOK() || status.code() == ErrorCodes::CommandNotSupported ); - } +// Verify that calling touch() on an empty collection returns an OK status, +// even when NULL is passed in for the stats output. +TEST(RecordStoreTestHarness, TouchEmptyWithNullStats) { + unique_ptr<HarnessHelper> harnessHelper(newHarnessHelper()); + unique_ptr<RecordStore> rs(harnessHelper->newNonCappedRecordStore()); + + { + unique_ptr<OperationContext> opCtx(harnessHelper->newOperationContext()); + ASSERT_EQUALS(0, rs->numRecords(opCtx.get())); } - // Insert multiple records, and verify that calling touch() on a nonempty collection - // returns an OK status, even when NULL is passed in for the stats output. - TEST( RecordStoreTestHarness, TouchNonEmptyWithNullStats ) { - unique_ptr<HarnessHelper> harnessHelper( newHarnessHelper() ); - unique_ptr<RecordStore> rs( harnessHelper->newNonCappedRecordStore() ); + { + unique_ptr<OperationContext> opCtx(harnessHelper->newOperationContext()); + Status status = rs->touch(opCtx.get(), NULL /* stats output */); + ASSERT(status.isOK() || status.code() == ErrorCodes::CommandNotSupported); + } +} - { - unique_ptr<OperationContext> opCtx( harnessHelper->newOperationContext() ); - ASSERT_EQUALS( 0, rs->numRecords( opCtx.get() ) ); - } +// Insert multiple records, and verify that calling touch() on a nonempty collection +// returns an OK status, even when NULL is passed in for the stats output. +TEST(RecordStoreTestHarness, TouchNonEmptyWithNullStats) { + unique_ptr<HarnessHelper> harnessHelper(newHarnessHelper()); + unique_ptr<RecordStore> rs(harnessHelper->newNonCappedRecordStore()); - int nToInsert = 10; - for ( int i = 0; i < nToInsert; i++ ) { - unique_ptr<OperationContext> opCtx( harnessHelper->newOperationContext() ); - { - stringstream ss; - ss << "record " << i; - string data = ss.str(); - - WriteUnitOfWork uow( opCtx.get() ); - StatusWith<RecordId> res = rs->insertRecord( opCtx.get(), - data.c_str(), - data.size() + 1, - false ); - ASSERT_OK( res.getStatus() ); - uow.commit(); - } - } + { + unique_ptr<OperationContext> opCtx(harnessHelper->newOperationContext()); + ASSERT_EQUALS(0, rs->numRecords(opCtx.get())); + } + int nToInsert = 10; + for (int i = 0; i < nToInsert; i++) { + unique_ptr<OperationContext> opCtx(harnessHelper->newOperationContext()); { - unique_ptr<OperationContext> opCtx( harnessHelper->newOperationContext() ); - ASSERT_EQUALS( nToInsert, rs->numRecords( opCtx.get() ) ); + stringstream ss; + ss << "record " << i; + string data = ss.str(); + + WriteUnitOfWork uow(opCtx.get()); + StatusWith<RecordId> res = + rs->insertRecord(opCtx.get(), data.c_str(), data.size() + 1, false); + ASSERT_OK(res.getStatus()); + uow.commit(); } + } - { - unique_ptr<OperationContext> opCtx( harnessHelper->newOperationContext() ); - // XXX does not verify the collection was loaded into cache - // (even if supported by storage engine) - Status status = rs->touch( opCtx.get(), NULL /* stats output */ ); - ASSERT( status.isOK() || status.code() == ErrorCodes::CommandNotSupported ); - } + { + unique_ptr<OperationContext> opCtx(harnessHelper->newOperationContext()); + ASSERT_EQUALS(nToInsert, rs->numRecords(opCtx.get())); + } + + { + unique_ptr<OperationContext> opCtx(harnessHelper->newOperationContext()); + // XXX does not verify the collection was loaded into cache + // (even if supported by storage engine) + Status status = rs->touch(opCtx.get(), NULL /* stats output */); + ASSERT(status.isOK() || status.code() == ErrorCodes::CommandNotSupported); } +} -} // namespace mongo +} // namespace mongo |