diff options
author | Mark Benvenuto <mark.benvenuto@mongodb.com> | 2015-06-20 00:22:50 -0400 |
---|---|---|
committer | Mark Benvenuto <mark.benvenuto@mongodb.com> | 2015-06-20 10:56:02 -0400 |
commit | 9c2ed42daa8fbbef4a919c21ec564e2db55e8d60 (patch) | |
tree | 3814f79c10d7b490948d8cb7b112ac1dd41ceff1 /src/mongo/dbtests/dbhelper_tests.cpp | |
parent | 01965cf52bce6976637ecb8f4a622aeb05ab256a (diff) | |
download | mongo-9c2ed42daa8fbbef4a919c21ec564e2db55e8d60.tar.gz |
SERVER-18579: Clang-Format - reformat code, no comment reflow
Diffstat (limited to 'src/mongo/dbtests/dbhelper_tests.cpp')
-rw-r--r-- | src/mongo/dbtests/dbhelper_tests.cpp | 348 |
1 files changed, 159 insertions, 189 deletions
diff --git a/src/mongo/dbtests/dbhelper_tests.cpp b/src/mongo/dbtests/dbhelper_tests.cpp index 9a7f2de4103..18dc87428ce 100644 --- a/src/mongo/dbtests/dbhelper_tests.cpp +++ b/src/mongo/dbtests/dbhelper_tests.cpp @@ -39,224 +39,194 @@ namespace mongo { - using std::unique_ptr; - using std::set; +using std::unique_ptr; +using std::set; - /** - * Unit tests related to DBHelpers - */ +/** + * Unit tests related to DBHelpers + */ - static const char * const ns = "unittests.removetests"; +static const char* const ns = "unittests.removetests"; - // TODO: Normalize with test framework - /** Simple test for Helpers::RemoveRange. */ - class RemoveRange { - public: - RemoveRange() : - _min( 4 ), _max( 8 ) - { - } +// TODO: Normalize with test framework +/** Simple test for Helpers::RemoveRange. */ +class RemoveRange { +public: + RemoveRange() : _min(4), _max(8) {} - void run() { - OperationContextImpl txn; - DBDirectClient client(&txn); - - for ( int i = 0; i < 10; ++i ) { - client.insert( ns, BSON( "_id" << i ) ); - } - - { - // Remove _id range [_min, _max). - ScopedTransaction transaction(&txn, MODE_IX); - Lock::DBLock lk(txn.lockState(), nsToDatabaseSubstring(ns), MODE_X); - OldClientContext ctx(&txn, ns ); - - KeyRange range( ns, - BSON( "_id" << _min ), - BSON( "_id" << _max ), - BSON( "_id" << 1 ) ); - mongo::WriteConcernOptions dummyWriteConcern; - Helpers::removeRange(&txn, range, false, dummyWriteConcern); - } - - // Check that the expected documents remain. - ASSERT_EQUALS( expected(), docs(&txn) ); + void run() { + OperationContextImpl txn; + DBDirectClient client(&txn); + + for (int i = 0; i < 10; ++i) { + client.insert(ns, BSON("_id" << i)); } - private: - BSONArray expected() const { - BSONArrayBuilder bab; - for ( int i = 0; i < _min; ++i ) { - bab << BSON( "_id" << i ); - } - for ( int i = _max; i < 10; ++i ) { - bab << BSON( "_id" << i ); - } - return bab.arr(); + + { + // Remove _id range [_min, _max). + ScopedTransaction transaction(&txn, MODE_IX); + Lock::DBLock lk(txn.lockState(), nsToDatabaseSubstring(ns), MODE_X); + OldClientContext ctx(&txn, ns); + + KeyRange range(ns, BSON("_id" << _min), BSON("_id" << _max), BSON("_id" << 1)); + mongo::WriteConcernOptions dummyWriteConcern; + Helpers::removeRange(&txn, range, false, dummyWriteConcern); } - BSONArray docs(OperationContext* txn) const { - DBDirectClient client(txn); - unique_ptr<DBClientCursor> cursor = client.query( ns, - Query().hint( BSON( "_id" << 1 ) ) ); - BSONArrayBuilder bab; - while ( cursor->more() ) { - bab << cursor->next(); - } - return bab.arr(); + // Check that the expected documents remain. + ASSERT_EQUALS(expected(), docs(&txn)); + } + +private: + BSONArray expected() const { + BSONArrayBuilder bab; + for (int i = 0; i < _min; ++i) { + bab << BSON("_id" << i); } - int _min; - int _max; - }; - - class All: public Suite { - public: - All() : - Suite( "remove" ) - { + for (int i = _max; i < 10; ++i) { + bab << BSON("_id" << i); } - void setupTests() { - add<RemoveRange>(); + return bab.arr(); + } + + BSONArray docs(OperationContext* txn) const { + DBDirectClient client(txn); + unique_ptr<DBClientCursor> cursor = client.query(ns, Query().hint(BSON("_id" << 1))); + BSONArrayBuilder bab; + while (cursor->more()) { + bab << cursor->next(); } - } myall; + return bab.arr(); + } + int _min; + int _max; +}; + +class All : public Suite { +public: + All() : Suite("remove") {} + void setupTests() { + add<RemoveRange>(); + } +} myall; - // - // Tests getting disk locs for an index range - // +// +// Tests getting disk locs for an index range +// - TEST(DBHelperTests, FindDiskLocs) { - OperationContextImpl txn; - DBDirectClient client(&txn); +TEST(DBHelperTests, FindDiskLocs) { + OperationContextImpl txn; + DBDirectClient client(&txn); - // Some unique tag we can use to make sure we're pulling back the right data - OID tag = OID::gen(); - client.remove( ns, BSONObj() ); + // Some unique tag we can use to make sure we're pulling back the right data + OID tag = OID::gen(); + client.remove(ns, BSONObj()); - int numDocsInserted = 10; - for ( int i = 0; i < numDocsInserted; ++i ) { - client.insert( ns, BSON( "_id" << i << "tag" << tag ) ); - } + int numDocsInserted = 10; + for (int i = 0; i < numDocsInserted; ++i) { + client.insert(ns, BSON("_id" << i << "tag" << tag)); + } - long long maxSizeBytes = 1024 * 1024 * 1024; + long long maxSizeBytes = 1024 * 1024 * 1024; - set<RecordId> locs; - long long numDocsFound; - long long estSizeBytes; - { - // search _id range (0, 10) - ScopedTransaction transaction(&txn, MODE_IS); - Lock::DBLock lk(txn.lockState(), nsToDatabaseSubstring(ns), MODE_S); - - KeyRange range( ns, - BSON( "_id" << 0 ), - BSON( "_id" << numDocsInserted ), - BSON( "_id" << 1 ) ); - - Status result = Helpers::getLocsInRange( &txn, - range, - maxSizeBytes, - &locs, - &numDocsFound, - &estSizeBytes ); - - ASSERT_EQUALS( result, Status::OK() ); - ASSERT_EQUALS( numDocsFound, numDocsInserted ); - ASSERT_NOT_EQUALS( estSizeBytes, 0 ); - ASSERT_LESS_THAN( estSizeBytes, maxSizeBytes ); - - Database* db = dbHolder().get( &txn, nsToDatabase(range.ns) ); - const Collection* collection = db->getCollection(ns); - - // Make sure all the disklocs actually correspond to the right info - for ( set<RecordId>::const_iterator it = locs.begin(); it != locs.end(); ++it ) { - const BSONObj obj = collection->docFor(&txn, *it).value(); - ASSERT_EQUALS(obj["tag"].OID(), tag); - } + set<RecordId> locs; + long long numDocsFound; + long long estSizeBytes; + { + // search _id range (0, 10) + ScopedTransaction transaction(&txn, MODE_IS); + Lock::DBLock lk(txn.lockState(), nsToDatabaseSubstring(ns), MODE_S); + + KeyRange range(ns, BSON("_id" << 0), BSON("_id" << numDocsInserted), BSON("_id" << 1)); + + Status result = + Helpers::getLocsInRange(&txn, range, maxSizeBytes, &locs, &numDocsFound, &estSizeBytes); + + ASSERT_EQUALS(result, Status::OK()); + ASSERT_EQUALS(numDocsFound, numDocsInserted); + ASSERT_NOT_EQUALS(estSizeBytes, 0); + ASSERT_LESS_THAN(estSizeBytes, maxSizeBytes); + + Database* db = dbHolder().get(&txn, nsToDatabase(range.ns)); + const Collection* collection = db->getCollection(ns); + + // Make sure all the disklocs actually correspond to the right info + for (set<RecordId>::const_iterator it = locs.begin(); it != locs.end(); ++it) { + const BSONObj obj = collection->docFor(&txn, *it).value(); + ASSERT_EQUALS(obj["tag"].OID(), tag); } } +} - // - // Tests index not found error getting disk locs - // +// +// Tests index not found error getting disk locs +// - TEST(DBHelperTests, FindDiskLocsNoIndex) { - OperationContextImpl txn; - DBDirectClient client(&txn); +TEST(DBHelperTests, FindDiskLocsNoIndex) { + OperationContextImpl txn; + DBDirectClient client(&txn); - client.remove( ns, BSONObj() ); - client.insert( ns, BSON( "_id" << OID::gen() ) ); + client.remove(ns, BSONObj()); + client.insert(ns, BSON("_id" << OID::gen())); - long long maxSizeBytes = 1024 * 1024 * 1024; + long long maxSizeBytes = 1024 * 1024 * 1024; - set<RecordId> locs; - long long numDocsFound; - long long estSizeBytes; - { - ScopedTransaction transaction(&txn, MODE_IS); - Lock::DBLock lk(txn.lockState(), nsToDatabaseSubstring(ns), MODE_S); - - // search invalid index range - KeyRange range( ns, - BSON( "badIndex" << 0 ), - BSON( "badIndex" << 10 ), - BSON( "badIndex" << 1 ) ); - - Status result = Helpers::getLocsInRange( &txn, - range, - maxSizeBytes, - &locs, - &numDocsFound, - &estSizeBytes ); - - // Make sure we get the right error code - ASSERT_EQUALS( result.code(), ErrorCodes::IndexNotFound ); - ASSERT_EQUALS( static_cast<long long>( locs.size() ), 0 ); - ASSERT_EQUALS( numDocsFound, 0 ); - ASSERT_EQUALS( estSizeBytes, 0 ); - } + set<RecordId> locs; + long long numDocsFound; + long long estSizeBytes; + { + ScopedTransaction transaction(&txn, MODE_IS); + Lock::DBLock lk(txn.lockState(), nsToDatabaseSubstring(ns), MODE_S); + + // search invalid index range + KeyRange range(ns, BSON("badIndex" << 0), BSON("badIndex" << 10), BSON("badIndex" << 1)); + + Status result = + Helpers::getLocsInRange(&txn, range, maxSizeBytes, &locs, &numDocsFound, &estSizeBytes); + + // Make sure we get the right error code + ASSERT_EQUALS(result.code(), ErrorCodes::IndexNotFound); + ASSERT_EQUALS(static_cast<long long>(locs.size()), 0); + ASSERT_EQUALS(numDocsFound, 0); + ASSERT_EQUALS(estSizeBytes, 0); } +} - // - // Tests chunk too big error getting disk locs - // +// +// Tests chunk too big error getting disk locs +// - TEST(DBHelperTests, FindDiskLocsTooBig) { - OperationContextImpl txn; - DBDirectClient client(&txn); +TEST(DBHelperTests, FindDiskLocsTooBig) { + OperationContextImpl txn; + DBDirectClient client(&txn); - client.remove( ns, BSONObj() ); + client.remove(ns, BSONObj()); - int numDocsInserted = 10; - for ( int i = 0; i < numDocsInserted; ++i ) { - client.insert( ns, BSON( "_id" << i ) ); - } + int numDocsInserted = 10; + for (int i = 0; i < numDocsInserted; ++i) { + client.insert(ns, BSON("_id" << i)); + } - // Very small max size - long long maxSizeBytes = 10; + // Very small max size + long long maxSizeBytes = 10; - set<RecordId> locs; - long long numDocsFound; - long long estSizeBytes; - { - ScopedTransaction transaction(&txn, MODE_IS); - Lock::DBLock lk(txn.lockState(), nsToDatabaseSubstring(ns), MODE_S); - - KeyRange range( ns, - BSON( "_id" << 0 ), - BSON( "_id" << numDocsInserted ), - BSON( "_id" << 1 ) ); - - Status result = Helpers::getLocsInRange( &txn, - range, - maxSizeBytes, - &locs, - &numDocsFound, - &estSizeBytes ); - - // Make sure we get the right error code and our count and size estimates are valid - ASSERT_EQUALS( result.code(), ErrorCodes::InvalidLength ); - ASSERT_EQUALS( numDocsFound, numDocsInserted ); - ASSERT_GREATER_THAN( estSizeBytes, maxSizeBytes ); - } + set<RecordId> locs; + long long numDocsFound; + long long estSizeBytes; + { + ScopedTransaction transaction(&txn, MODE_IS); + Lock::DBLock lk(txn.lockState(), nsToDatabaseSubstring(ns), MODE_S); + + KeyRange range(ns, BSON("_id" << 0), BSON("_id" << numDocsInserted), BSON("_id" << 1)); + + Status result = + Helpers::getLocsInRange(&txn, range, maxSizeBytes, &locs, &numDocsFound, &estSizeBytes); + + // Make sure we get the right error code and our count and size estimates are valid + ASSERT_EQUALS(result.code(), ErrorCodes::InvalidLength); + ASSERT_EQUALS(numDocsFound, numDocsInserted); + ASSERT_GREATER_THAN(estSizeBytes, maxSizeBytes); } +} -} // namespace RemoveTests +} // namespace RemoveTests |