diff options
author | Benety Goh <benety@mongodb.com> | 2022-08-25 13:11:17 -0400 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2022-08-25 19:17:34 +0000 |
commit | f32f550aff1def5709ea68f42dc9d4bf9321d5e6 (patch) | |
tree | 24c3420ba615b8733221baac0f7f6f21c3823266 /src/mongo | |
parent | 6f0bf18913176a133ff2d6dc99c3e761606f9b50 (diff) | |
download | mongo-f32f550aff1def5709ea68f42dc9d4bf9321d5e6.tar.gz |
SERVER-68477 add unit test for TTLCollectionCache
Diffstat (limited to 'src/mongo')
-rw-r--r-- | src/mongo/db/SConscript | 2 | ||||
-rw-r--r-- | src/mongo/db/ttl_collection_cache_test.cpp | 90 |
2 files changed, 92 insertions, 0 deletions
diff --git a/src/mongo/db/SConscript b/src/mongo/db/SConscript index f677e021b30..a9404ebedfa 100644 --- a/src/mongo/db/SConscript +++ b/src/mongo/db/SConscript @@ -2517,6 +2517,7 @@ if wiredtiger: 'transaction/transaction_history_iterator_test.cpp', 'transaction/transaction_participant_retryable_writes_test.cpp', 'transaction/transaction_participant_test.cpp', + 'ttl_collection_cache_test.cpp', 'ttl_test.cpp', 'update_index_data_test.cpp', 'vector_clock_mongod_test.cpp', @@ -2617,6 +2618,7 @@ if wiredtiger: 'snapshot_window_options', 'startup_warnings_mongod', 'time_proof_service', + 'ttl_collection_cache', 'ttl_d', 'update_index_data', 'vector_clock', diff --git a/src/mongo/db/ttl_collection_cache_test.cpp b/src/mongo/db/ttl_collection_cache_test.cpp new file mode 100644 index 00000000000..4f598b3736c --- /dev/null +++ b/src/mongo/db/ttl_collection_cache_test.cpp @@ -0,0 +1,90 @@ +/** + * Copyright (C) 2022-present MongoDB, Inc. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the Server Side Public License, version 1, + * as published by MongoDB, Inc. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * Server Side Public License for more details. + * + * You should have received a copy of the Server Side Public License + * along with this program. If not, see + * <http://www.mongodb.com/licensing/server-side-public-license>. + * + * As a special exception, the copyright holders give permission to link the + * code of portions of this program with the OpenSSL library under certain + * conditions as described in each individual source file and distribute + * linked combinations including the program with the OpenSSL library. You + * must comply with the Server Side Public License in all respects for + * all of the code used other than as permitted herein. If you modify file(s) + * with this exception, you may extend this exception to your version of the + * file(s), but you are not obligated to do so. If you do not wish to do so, + * delete this exception statement from your version. If you delete this + * exception statement from all source files in the program, then also delete + * it in the license file. + */ + +#include "mongo/db/ttl_collection_cache.h" +#include "mongo/unittest/unittest.h" + +namespace mongo { +namespace { + +TEST(TTLCollectionCacheTest, Basic) { + TTLCollectionCache cache; + ASSERT_EQ(cache.getTTLInfos().size(), 0); + + auto uuidCollA = UUID::gen(); + auto uuidCollB = UUID::gen(); + auto infoIndexA1 = TTLCollectionCache::Info{"collA_ttl_1"}; + auto infoClusteredA = TTLCollectionCache::Info{TTLCollectionCache::ClusteredId{}}; + auto infoIndexB1 = TTLCollectionCache::Info("collB_ttl_1"); + + // Confirm registerTTLInfo() behavior using getTTLInfo(). + cache.registerTTLInfo(uuidCollA, infoIndexA1); + cache.registerTTLInfo(uuidCollA, infoClusteredA); + cache.registerTTLInfo(uuidCollB, infoIndexB1); + + auto infos = cache.getTTLInfos(); + ASSERT_EQ(infos.size(), 2U); + ASSERT_EQ(infos.count(uuidCollA), 1U); + ASSERT_EQ(infos[uuidCollA].size(), 2U); + auto indexNameA = stdx::get_if<TTLCollectionCache::IndexName>(&infos[uuidCollA][0]); + ASSERT(indexNameA); + ASSERT_EQ(*indexNameA, "collA_ttl_1"); + ASSERT(stdx::get_if<TTLCollectionCache::ClusteredId>(&infos[uuidCollA][1])); + + ASSERT_EQ(infos.count(uuidCollB), 1U); + ASSERT_EQ(infos[uuidCollB].size(), 1U); + + auto indexNameB = stdx::get_if<TTLCollectionCache::IndexName>(&infos[uuidCollB][0]); + ASSERT(indexNameB); + ASSERT_EQ(*indexNameB, "collB_ttl_1"); + + // Check deregisterTTLInfo(). TTLCollectionCache should clean up + // UUIDs that no longer have any TTL infos registered. + cache.deregisterTTLInfo(uuidCollB, infoIndexB1); + infos = cache.getTTLInfos(); + ASSERT_EQ(infos.size(), 1U); + ASSERT_EQ(infos.count(uuidCollA), 1U); + ASSERT_EQ(infos[uuidCollA].size(), 2U); + + // Remove info for TTL index on collection A. + cache.deregisterTTLInfo(uuidCollA, infoIndexA1); + infos = cache.getTTLInfos(); + ASSERT_EQ(infos.size(), 1U); + ASSERT_EQ(infos.count(uuidCollA), 1U); + ASSERT_EQ(infos[uuidCollA].size(), 1U); + ASSERT(stdx::get_if<TTLCollectionCache::ClusteredId>(&infos[uuidCollA][0])); + + // Remove clustered info for collection A. + cache.deregisterTTLInfo(uuidCollA, infoClusteredA); + infos = cache.getTTLInfos(); + ASSERT_EQ(infos.size(), 0U); +} + +} // namespace +} // namespace mongo |