|
| 1 | + |
| 2 | +/** |
| 3 | + * Copyright (C) 2018-present MongoDB, Inc. |
| 4 | + * |
| 5 | + * This program is free software: you can redistribute it and/or modify |
| 6 | + * it under the terms of the Server Side Public License, version 1, |
| 7 | + * as published by MongoDB, Inc. |
| 8 | + * |
| 9 | + * This program is distributed in the hope that it will be useful, |
| 10 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | + * Server Side Public License for more details. |
| 13 | + * |
| 14 | + * You should have received a copy of the Server Side Public License |
| 15 | + * along with this program. If not, see |
| 16 | + * <http://www.mongodb.com/licensing/server-side-public-license>. |
| 17 | + * |
| 18 | + * As a special exception, the copyright holders give permission to link the |
| 19 | + * code of portions of this program with the OpenSSL library under certain |
| 20 | + * conditions as described in each individual source file and distribute |
| 21 | + * linked combinations including the program with the OpenSSL library. You |
| 22 | + * must comply with the Server Side Public License in all respects for |
| 23 | + * all of the code used other than as permitted herein. If you modify file(s) |
| 24 | + * with this exception, you may extend this exception to your version of the |
| 25 | + * file(s), but you are not obligated to do so. If you do not wish to do so, |
| 26 | + * delete this exception statement from your version. If you delete this |
| 27 | + * exception statement from all source files in the program, then also delete |
| 28 | + * it in the license file. |
| 29 | + */ |
| 30 | + |
| 31 | +#include "mongo/db/catalog/catalog_control.h" |
| 32 | + |
| 33 | +#include "mongo/db/client.h" |
| 34 | +#include "mongo/db/operation_context_noop.h" |
| 35 | +#include "mongo/db/service_context.h" |
| 36 | +#include "mongo/db/storage/storage_engine.h" |
| 37 | +#include "mongo/unittest/unittest.h" |
| 38 | + |
| 39 | +namespace mongo { |
| 40 | +namespace { |
| 41 | + |
| 42 | +/** |
| 43 | + * Mock storage engine. |
| 44 | + */ |
| 45 | +class MockStorageEngine : public StorageEngine { |
| 46 | +public: |
| 47 | + RecoveryUnit* newRecoveryUnit() final { |
| 48 | + return nullptr; |
| 49 | + } |
| 50 | + void listDatabases(std::vector<std::string>* out) const final {} |
| 51 | + DatabaseCatalogEntry* getDatabaseCatalogEntry(OperationContext* opCtx, StringData db) final { |
| 52 | + return nullptr; |
| 53 | + } |
| 54 | + bool supportsDocLocking() const final { |
| 55 | + return false; |
| 56 | + } |
| 57 | + bool isDurable() const final { |
| 58 | + return false; |
| 59 | + } |
| 60 | + bool isEphemeral() const { |
| 61 | + return true; |
| 62 | + } |
| 63 | + Status closeDatabase(OperationContext* opCtx, StringData db) final { |
| 64 | + return Status::OK(); |
| 65 | + } |
| 66 | + Status dropDatabase(OperationContext* opCtx, StringData db) final { |
| 67 | + return Status::OK(); |
| 68 | + } |
| 69 | + int flushAllFiles(OperationContext* opCtx, bool sync) final { |
| 70 | + return 0; |
| 71 | + } |
| 72 | + Status repairRecordStore(OperationContext* opCtx, const std::string& ns) final { |
| 73 | + return Status::OK(); |
| 74 | + } |
| 75 | + std::unique_ptr<TemporaryRecordStore> makeTemporaryRecordStore(OperationContext* opCtx) final { |
| 76 | + return {}; |
| 77 | + } |
| 78 | + void cleanShutdown() final {} |
| 79 | + void setJournalListener(JournalListener* jl) final {} |
| 80 | + Timestamp getAllCommittedTimestamp() const final { |
| 81 | + return {}; |
| 82 | + } |
| 83 | + Timestamp getOldestOpenReadTimestamp() const final { |
| 84 | + return {}; |
| 85 | + } |
| 86 | + std::string getFilesystemPathForDb(const std::string& dbName) const final { |
| 87 | + return ""; |
| 88 | + } |
| 89 | +}; |
| 90 | + |
| 91 | +/** |
| 92 | + * Simple test for openCatalog() and closeCatalog() to check library dependencies. |
| 93 | + */ |
| 94 | +class CatalogControlTest : public unittest::Test { |
| 95 | +private: |
| 96 | + void setUp() override; |
| 97 | + void tearDown() override; |
| 98 | + |
| 99 | + std::unique_ptr<ThreadClient> _tc; |
| 100 | +}; |
| 101 | + |
| 102 | +void CatalogControlTest::setUp() { |
| 103 | + { |
| 104 | + auto serviceContext = ServiceContext::make(); |
| 105 | + auto storageEngine = std::make_unique<MockStorageEngine>(); |
| 106 | + serviceContext->setStorageEngine(std::move(storageEngine)); |
| 107 | + setGlobalServiceContext(std::move(serviceContext)); |
| 108 | + } |
| 109 | + |
| 110 | + _tc = std::make_unique<ThreadClient>(getGlobalServiceContext()); |
| 111 | +} |
| 112 | + |
| 113 | +void CatalogControlTest::tearDown() { |
| 114 | + _tc = {}; |
| 115 | +} |
| 116 | + |
| 117 | +TEST_F(CatalogControlTest, CloseAndOpenCatalog) { |
| 118 | + OperationContextNoop opCtx(&cc(), 0); |
| 119 | + auto map = catalog::closeCatalog(&opCtx); |
| 120 | + ASSERT_EQUALS(0U, map.size()); |
| 121 | + catalog::openCatalog(&opCtx, {}); |
| 122 | +} |
| 123 | + |
| 124 | +} // namespace |
| 125 | +} // namespace mongo |
0 commit comments