diff options
Diffstat (limited to 'src/mongo/db/storage/wiredtiger/wiredtiger_index_test.cpp')
-rw-r--r-- | src/mongo/db/storage/wiredtiger/wiredtiger_index_test.cpp | 153 |
1 files changed, 76 insertions, 77 deletions
diff --git a/src/mongo/db/storage/wiredtiger/wiredtiger_index_test.cpp b/src/mongo/db/storage/wiredtiger/wiredtiger_index_test.cpp index f7e308e6cf2..ea468aa5d76 100644 --- a/src/mongo/db/storage/wiredtiger/wiredtiger_index_test.cpp +++ b/src/mongo/db/storage/wiredtiger/wiredtiger_index_test.cpp @@ -47,96 +47,95 @@ namespace mongo { - using std::string; +using std::string; - class MyHarnessHelper final : public HarnessHelper { - public: - MyHarnessHelper() : _dbpath( "wt_test" ), _conn( NULL ) { +class MyHarnessHelper final : public HarnessHelper { +public: + MyHarnessHelper() : _dbpath("wt_test"), _conn(NULL) { + const char* config = "create,cache_size=1G,"; + int ret = wiredtiger_open(_dbpath.path().c_str(), NULL, config, &_conn); + invariantWTOK(ret); - const char* config = "create,cache_size=1G,"; - int ret = wiredtiger_open( _dbpath.path().c_str(), NULL, config, &_conn); - invariantWTOK( ret ); - - _sessionCache = new WiredTigerSessionCache( _conn ); - } - - ~MyHarnessHelper() final { - delete _sessionCache; - _conn->close(_conn, NULL); - } - - std::unique_ptr<SortedDataInterface> newSortedDataInterface( bool unique ) final { - std::string ns = "test.wt"; - OperationContextNoop txn( newRecoveryUnit().release() ); - - BSONObj spec = BSON( "key" << BSON( "a" << 1 ) << - "name" << "testIndex" << - "ns" << ns ); - - IndexDescriptor desc( NULL, "", spec ); - - StatusWith<std::string> result = WiredTigerIndex::generateCreateString("", desc); - ASSERT_OK(result.getStatus()); - - string uri = "table:" + ns; - invariantWTOK( WiredTigerIndex::Create(&txn, uri, result.getValue())); + _sessionCache = new WiredTigerSessionCache(_conn); + } - if ( unique ) - return stdx::make_unique<WiredTigerIndexUnique>( &txn, uri, &desc ); - return stdx::make_unique<WiredTigerIndexStandard>( &txn, uri, &desc ); - } + ~MyHarnessHelper() final { + delete _sessionCache; + _conn->close(_conn, NULL); + } - std::unique_ptr<RecoveryUnit> newRecoveryUnit() final { - return stdx::make_unique<WiredTigerRecoveryUnit>( _sessionCache ); - } + std::unique_ptr<SortedDataInterface> newSortedDataInterface(bool unique) final { + std::string ns = "test.wt"; + OperationContextNoop txn(newRecoveryUnit().release()); - private: - unittest::TempDir _dbpath; - WT_CONNECTION* _conn; - WiredTigerSessionCache* _sessionCache; - }; + BSONObj spec = BSON("key" << BSON("a" << 1) << "name" + << "testIndex" + << "ns" << ns); - std::unique_ptr<HarnessHelper> newHarnessHelper() { - return stdx::make_unique<MyHarnessHelper>(); - } + IndexDescriptor desc(NULL, "", spec); - TEST(WiredTigerIndexTest, GenerateCreateStringEmptyDocument) { - BSONObj spec = fromjson("{}"); - StatusWith<std::string> result = WiredTigerIndex::parseIndexOptions(spec); + StatusWith<std::string> result = WiredTigerIndex::generateCreateString("", desc); ASSERT_OK(result.getStatus()); - ASSERT_EQ(result.getValue(), ""); // "," would also be valid. - } - TEST(WiredTigerIndexTest, GenerateCreateStringUnknownField) { - BSONObj spec = fromjson("{unknownField: 1}"); - StatusWith<std::string> result = WiredTigerIndex::parseIndexOptions(spec); - const Status& status = result.getStatus(); - ASSERT_NOT_OK(status); - ASSERT_EQUALS(ErrorCodes::InvalidOptions, status); - } + string uri = "table:" + ns; + invariantWTOK(WiredTigerIndex::Create(&txn, uri, result.getValue())); - TEST(WiredTigerIndexTest, GenerateCreateStringNonStringConfig) { - BSONObj spec = fromjson("{configString: 12345}"); - StatusWith<std::string> result = WiredTigerIndex::parseIndexOptions(spec); - const Status& status = result.getStatus(); - ASSERT_NOT_OK(status); - ASSERT_EQUALS(ErrorCodes::TypeMismatch, status); + if (unique) + return stdx::make_unique<WiredTigerIndexUnique>(&txn, uri, &desc); + return stdx::make_unique<WiredTigerIndexStandard>(&txn, uri, &desc); } - TEST(WiredTigerIndexTest, GenerateCreateStringEmptyConfigString) { - BSONObj spec = fromjson("{configString: ''}"); - StatusWith<std::string> result = WiredTigerIndex::parseIndexOptions(spec); - ASSERT_OK(result.getStatus()); - ASSERT_EQ(result.getValue(), ","); // "" would also be valid. + std::unique_ptr<RecoveryUnit> newRecoveryUnit() final { + return stdx::make_unique<WiredTigerRecoveryUnit>(_sessionCache); } - TEST(WiredTigerIndexTest, GenerateCreateStringValidConfigFormat) { - // TODO eventually this should fail since "abc" is not a valid WT option. - BSONObj spec = fromjson("{configString: 'abc=def'}"); - StatusWith<std::string> result = WiredTigerIndex::parseIndexOptions(spec); - const Status& status = result.getStatus(); - ASSERT_OK(status); - ASSERT_EQ(result.getValue(), "abc=def,"); - } +private: + unittest::TempDir _dbpath; + WT_CONNECTION* _conn; + WiredTigerSessionCache* _sessionCache; +}; + +std::unique_ptr<HarnessHelper> newHarnessHelper() { + return stdx::make_unique<MyHarnessHelper>(); +} + +TEST(WiredTigerIndexTest, GenerateCreateStringEmptyDocument) { + BSONObj spec = fromjson("{}"); + StatusWith<std::string> result = WiredTigerIndex::parseIndexOptions(spec); + ASSERT_OK(result.getStatus()); + ASSERT_EQ(result.getValue(), ""); // "," would also be valid. +} + +TEST(WiredTigerIndexTest, GenerateCreateStringUnknownField) { + BSONObj spec = fromjson("{unknownField: 1}"); + StatusWith<std::string> result = WiredTigerIndex::parseIndexOptions(spec); + const Status& status = result.getStatus(); + ASSERT_NOT_OK(status); + ASSERT_EQUALS(ErrorCodes::InvalidOptions, status); +} + +TEST(WiredTigerIndexTest, GenerateCreateStringNonStringConfig) { + BSONObj spec = fromjson("{configString: 12345}"); + StatusWith<std::string> result = WiredTigerIndex::parseIndexOptions(spec); + const Status& status = result.getStatus(); + ASSERT_NOT_OK(status); + ASSERT_EQUALS(ErrorCodes::TypeMismatch, status); +} + +TEST(WiredTigerIndexTest, GenerateCreateStringEmptyConfigString) { + BSONObj spec = fromjson("{configString: ''}"); + StatusWith<std::string> result = WiredTigerIndex::parseIndexOptions(spec); + ASSERT_OK(result.getStatus()); + ASSERT_EQ(result.getValue(), ","); // "" would also be valid. +} + +TEST(WiredTigerIndexTest, GenerateCreateStringValidConfigFormat) { + // TODO eventually this should fail since "abc" is not a valid WT option. + BSONObj spec = fromjson("{configString: 'abc=def'}"); + StatusWith<std::string> result = WiredTigerIndex::parseIndexOptions(spec); + const Status& status = result.getStatus(); + ASSERT_OK(status); + ASSERT_EQ(result.getValue(), "abc=def,"); +} } // namespace mongo |