//////////////////////////////////////////////////////////////////////////////// /// DISCLAIMER /// /// Copyright 2019 ArangoDB GmbH, Cologne, Germany /// /// Licensed under the Apache License, Version 2.0 (the "License"); /// you may not use this file except in compliance with the License. /// You may obtain a copy of the License at /// /// http://www.apache.org/licenses/LICENSE-2.0 /// /// Unless required by applicable law or agreed to in writing, software /// distributed under the License is distributed on an "AS IS" BASIS, /// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. /// See the License for the specific language governing permissions and /// limitations under the License. /// /// Copyright holder is ArangoDB GmbH, Cologne, Germany //////////////////////////////////////////////////////////////////////////////// #include "Basics/Common.h" #include "gtest/gtest.h" #include #include #include #include #include "Transaction/Manager.h" using namespace arangodb; // ----------------------------------------------------------------------------- // --SECTION-- test suite // ----------------------------------------------------------------------------- /// @brief test RocksDBTransactionManager /// @brief simple non-overlapping TEST(RocksDBTransactionManager, test_non_overlapping) { transaction::Manager tm(false); EXPECT_EQ(tm.getActiveTransactionCount(), 0); EXPECT_TRUE(tm.holdTransactions(500) ); tm.releaseTransactions(); tm.registerTransaction((TRI_voc_tid_t)1, std::unique_ptr(), false); EXPECT_EQ(tm.getActiveTransactionCount(), 1); tm.unregisterTransaction((TRI_voc_tid_t)1, false, false); EXPECT_EQ(tm.getActiveTransactionCount(), 0); EXPECT_TRUE(tm.holdTransactions(500) ); tm.releaseTransactions(); } /// @brief simple non-overlapping TEST(RocksDBTransactionManager, test_overlapping) { transaction::Manager tm(false); std::chrono::milliseconds five(5); std::mutex mu; std::condition_variable cv; EXPECT_EQ(tm.getActiveTransactionCount(), 0); EXPECT_TRUE(tm.holdTransactions(500) ); std::unique_lock lock(mu); auto getReadLock = [&] () -> void { { std::unique_lock innerLock(mu); cv.notify_all(); } tm.registerTransaction((TRI_voc_tid_t)1, std::unique_ptr(), false); EXPECT_EQ(tm.getActiveTransactionCount(), 1); }; std::thread reader(getReadLock); cv.wait(lock); EXPECT_EQ(tm.getActiveTransactionCount(), 0); std::this_thread::sleep_for(five); EXPECT_EQ(tm.getActiveTransactionCount(), 0); tm.releaseTransactions(); reader.join(); EXPECT_EQ(tm.getActiveTransactionCount(), 1); tm.unregisterTransaction((TRI_voc_tid_t)1, false, false); EXPECT_EQ(tm.getActiveTransactionCount(), 0); }