//------------------------------------------------------------------------------ // File: MockContainerMD.hh // Author: Cedric Caffy //------------------------------------------------------------------------------ /************************************************************************ * EOS - the CERN Disk Storage System * * Copyright (C) 2017 CERN/Switzerland * * * * This program is free software: you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation, either version 3 of the License, or * * (at your option) any later version. * * * * 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 * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program. If not, see .* ************************************************************************/ #ifndef EOS_MOCKCONTAINERMD_HH #define EOS_MOCKCONTAINERMD_HH #include "namespace/ns_quarkdb/ContainerMD.hh" #include EOSNSNAMESPACE_BEGIN /** * A MockContainerMD class allowing to do some unit tests with it... * It was mainly created to allow to unit test the new locking mechanism and the BulkNsObjectLocker */ class MockContainerMD : public QuarkContainerMD, public std::enable_shared_from_this { public: //Vector to keep track of the order of write locking of the containers static std::vector writeLockedContainers; //Vector to keep track of the order of write unlocking of the containers static std::vector writeUnlockedContainers; //Vector to keep track of the order of read locking of the containers static std::vector readLockedContainers; //Vector to keep track of the order of read unlocking of the containers static std::vector readUnlockedContainers; static void clearVectors() { writeLockedContainers.clear(); writeUnlockedContainers.clear(); readLockedContainers.clear(); readUnlockedContainers.clear(); } MockContainerMD(uint64_t id){ mId = ContainerIdentifier(id); } inline identifier_t getIdentifier() const override { return mId; } void registerLock(MDWriteLock & lock) override { QuarkContainerMD::registerLock(lock); writeLockedContainers.push_back(shared_from_this()); } void registerLock(MDReadLock & lock) override { QuarkContainerMD::registerLock(lock); readLockedContainers.push_back(shared_from_this()); } void unregisterLock(MDWriteLock & lock) override { QuarkContainerMD::unregisterLock(lock); writeUnlockedContainers.push_back(shared_from_this()); } void unregisterLock(MDReadLock & lock) override { QuarkContainerMD::unregisterLock(lock); readUnlockedContainers.push_back(shared_from_this()); } static std::vector getWriteLockedContainers() { return writeLockedContainers; } static std::vector getWriteUnlockedContainers() { return writeUnlockedContainers; } static std::vector getReadLockedContainers() { return readLockedContainers; } static std::vector getReadUnlockedContainers() { return readUnlockedContainers; } private: identifier_t mId; }; std::vector MockContainerMD::writeLockedContainers = std::vector(); std::vector MockContainerMD::writeUnlockedContainers = std::vector(); std::vector MockContainerMD::readLockedContainers = std::vector(); std::vector MockContainerMD::readUnlockedContainers = std::vector(); EOSNSNAMESPACE_END #endif // EOS_MOCKCONTAINERMD_HH