Commit b68c311a authored by Michael Davis's avatar Michael Davis
Browse files

Merge remote-tracking branch 'origin/master' into kill_bash

parents 56d96045 d272da76
......@@ -146,7 +146,6 @@ ELSE(DEFINED PackageOnly)
add_subdirectory(rdbms)
add_subdirectory(scheduler)
add_subdirectory(tapeserver)
add_subdirectory(tests)
#Generate version information
configure_file(${PROJECT_SOURCE_DIR}/version.hpp.in
......@@ -177,28 +176,39 @@ endif (${COMPILE_PACKAGING} STREQUAL "1")
configure_file(tests/valgrind.suppr tests/valgrind.suppr COPYONLY)
configure_file(tests/helgrind.suppr tests/helgrind.suppr COPYONLY)
set(VALGRIND valgrind)
set(VALGRIND_OPTS "--track-fds=yes --leak-check=full --demangle=yes --gen-suppressions=all --show-reachable=yes --error-exitcode=1")
set(VALGRIND_OPTS_W_SUPPR ${VALGRIND_OPTS} --suppressions=tests/valgrind.suppr)
set(HELGRIND_OPTS "-v --demangle=yes --gen-suppressions=all --num-callers=25 --conflict-cache-size=30000000 --error-exitcode=1 --sim-hints=no-nptl-pthread-stackcache")
set(HELGRIND_OPTS_W_SUPPR ${HELGRIND_OPTS} --suppressions=tests/helgrind.suppr)
IF(NOT DEFINED PackageOnly)
add_subdirectory(tests)
ENDIF(NOT DEFINED PackageOnly)
add_custom_target(fullunittests
tests/cta-unitTests
COMMAND tests/cta-unitTests-multiProcess
COMMAND valgrind --track-fds=yes --leak-check=full --demangle=yes --gen-suppressions=all --show-reachable=yes --error-exitcode=1 --suppressions=tests/valgrind.suppr tests/cta-unitTests
COMMAND valgrind --tool=helgrind -v --demangle=yes --gen-suppressions=all --num-callers=25 --conflict-cache-size=30000000 --error-exitcode=1 --suppressions=tests/helgrind.suppr tests/cta-unitTests
COMMAND ${VALGRIND} ${VALGRIND_OPTS} tests/cta-unitTests
COMMAND ${VALGRIND} --tool=helgrind ${HELGRIND_OPTS} tests/cta-unitTests
COMMAND tests/cta-unitTests-multiProcess
COMMAND valgrind --track-fds=yes --child-silent-after-fork=yes --leak-check=full --demangle=yes --gen-suppressions=all --show-reachable=yes --error-exitcode=1 --suppressions=tests/valgrind.suppr tests/cta-unitTests-multiProcess
COMMAND valgrind --tool=helgrind -v --demangle=yes --gen-suppressions=all --num-callers=25 --conflict-cache-size=30000000 --error-exitcode=1 --suppressions=tests/helgrind.suppr tests/cta-unitTests-multiProcess
COMMAND ${VALGRIND} ${VALGRIND_OPTS} --child-silent-after-fork=yes tests/cta-unitTests-multiProcess
COMMAND ${VALGRIND} --tool=helgrind ${HELGRIND_OPTS} tests/cta-unitTests-multiProcess
DEPENDS tests/cta-unitTests tests/cta-unitTests-multiProcess tests/valgrind.suppr tests/helgrind.suppr
COMMENT "Running unit tests with memory leak and race conditions detection" VERBATIM)
add_custom_target(valgrind
valgrind --track-fds=yes --leak-check=full --demangle=yes --gen-suppressions=all --show-reachable=yes --error-exitcode=1 --suppressions=tests/valgrind.suppr tests/cta-unitTests
COMMAND valgrind --track-fds=yes --child-silent-after-fork=yes --leak-check=full --demangle=yes --gen-suppressions=all --show-reachable=yes --error-exitcode=1 --suppressions=tests/valgrind.suppr tests/cta-unitTests-multiProcess
${VALGRIND} ${VALGRIND_OPTS} tests/cta-unitTests
COMMAND ${VALGRIND} ${VALGRIND_OPTS} --child-silent-after-fork=yes tests/cta-unitTests-multiProcess
DEPENDS tests/cta-unitTests tests/cta-unitTests-multiProcess tests/valgrind.suppr
COMMENT "Running unit tests with memory leak detection" VERBATIM)
add_custom_target(helgrind
valgrind --tool=helgrind -v --demangle=yes --gen-suppressions=all --num-callers=25 --conflict-cache-size=30000000 --error-exitcode=1 --suppressions=tests/helgrind.suppr tests/cta-unitTests
COMMAND valgrind --tool=helgrind -v --child-silent-after-fork=yes --demangle=yes --gen-suppressions=all --num-callers=25 --conflict-cache-size=30000000 --error-exitcode=1 --suppressions=tests/helgrind.suppr tests/cta-unitTests-multiProcess
${VALGRIND} --tool=helgrind ${HELGRIND_OPTS} tests/cta-unitTests
COMMAND ${VALGRIND} --tool=helgrind ${HELGRIND_OPTS} tests/cta-unitTests-multiProcess
DEPENDS tests/cta-unitTests tests/cta-unitTests-multiProcess tests/helgrind.suppr
COMMENT "Running unit tests with race conditions detection" VERBATIM)
......
......@@ -15,9 +15,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
cmake_minimum_required (VERSION 2.6)
if (OCCI_SUPPORT)
include_directories (${ORACLE-INSTANTCLIENT_INCLUDE_DIRS})
endif (OCCI_SUPPORT)
include_directories (${ORACLE-INSTANTCLIENT_INCLUDE_DIRS})
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wshadow")
......@@ -27,8 +25,10 @@ set (CATALOGUE_LIB_SRC_FILES
ArchiveFileItor.cpp
ArchiveFileItorImpl.cpp
Catalogue.cpp
CatalogueFactory.cpp
CmdLineTool.cpp
InMemoryCatalogue.cpp
OracleCatalogue.cpp
SqliteCatalogueSchema.cpp
TapeFileWritten.cpp
RdbmsArchiveFileItorImpl.cpp
......@@ -37,25 +37,12 @@ set (CATALOGUE_LIB_SRC_FILES
SqliteCatalogue.cpp
TapeForWriting.cpp)
if (OCCI_SUPPORT)
set (CATALOGUE_LIB_SRC_FILES
${CATALOGUE_LIB_SRC_FILES}
CatalogueFactory.cpp
OracleCatalogue.cpp)
else (OCCI_SUPPORT)
set (CATALOGUE_LIB_SRC_FILES
${CATALOGUE_LIB_SRC_FILES}
CatalogueFactory_OCCI_SUPPORT_OFF.cpp)
endif (OCCI_SUPPORT)
add_library (ctacatalogue SHARED
${CATALOGUE_LIB_SRC_FILES})
set_property(TARGET ctacatalogue PROPERTY SOVERSION "${CTA_SOVERSION}")
set_property(TARGET ctacatalogue PROPERTY VERSION "${CTA_LIBVERSION}")
if (OCCI_SUPPORT)
set_property (TARGET ctacatalogue APPEND PROPERTY INSTALL_RPATH ${ORACLE-INSTANTCLIENT_RPATH})
endif (OCCI_SUPPORT)
set_property (TARGET ctacatalogue APPEND PROPERTY INSTALL_RPATH ${ORACLE-INSTANTCLIENT_RPATH})
install (TARGETS ctacatalogue DESTINATION usr/${CMAKE_INSTALL_LIBDIR})
......@@ -133,9 +120,7 @@ add_executable(cta-catalogue-schema-create
target_link_libraries (cta-catalogue-schema-create
ctacatalogue)
if (OCCI_SUPPORT)
set_property (TARGET cta-catalogue-schema-create APPEND PROPERTY INSTALL_RPATH ${ORACLE-INSTANTCLIENT_RPATH})
endif (OCCI_SUPPORT)
set_property (TARGET cta-catalogue-schema-create APPEND PROPERTY INSTALL_RPATH ${ORACLE-INSTANTCLIENT_RPATH})
install (TARGETS cta-catalogue-schema-create DESTINATION /usr/bin)
install (FILES ${CMAKE_CURRENT_SOURCE_DIR}/cta-catalogue-schema-create.1cta DESTINATION /usr/share/man/man1)
......@@ -148,9 +133,7 @@ add_executable(cta-catalogue-schema-drop
target_link_libraries (cta-catalogue-schema-drop
ctacatalogue)
if (OCCI_SUPPORT)
set_property (TARGET cta-catalogue-schema-drop APPEND PROPERTY INSTALL_RPATH ${ORACLE-INSTANTCLIENT_RPATH})
endif (OCCI_SUPPORT)
set_property (TARGET cta-catalogue-schema-drop APPEND PROPERTY INSTALL_RPATH ${ORACLE-INSTANTCLIENT_RPATH})
install (TARGETS cta-catalogue-schema-drop DESTINATION /usr/bin)
install (FILES ${CMAKE_CURRENT_SOURCE_DIR}/cta-catalogue-schema-drop.1cta DESTINATION /usr/share/man/man1)
......@@ -163,9 +146,7 @@ add_executable(cta-database-poll
target_link_libraries (cta-database-poll
ctacatalogue)
if (OCCI_SUPPORT)
set_property (TARGET cta-database-poll APPEND PROPERTY INSTALL_RPATH ${ORACLE-INSTANTCLIENT_RPATH})
endif (OCCI_SUPPORT)
set_property (TARGET cta-database-poll APPEND PROPERTY INSTALL_RPATH ${ORACLE-INSTANTCLIENT_RPATH})
install (TARGETS cta-database-poll DESTINATION /usr/bin)
install (FILES ${CMAKE_CURRENT_SOURCE_DIR}/cta-database-poll.1cta DESTINATION /usr/share/man/man1)
......@@ -178,9 +159,7 @@ add_executable(cta-catalogue-admin-user-create
target_link_libraries (cta-catalogue-admin-user-create
ctacatalogue)
if (OCCI_SUPPORT)
set_property (TARGET cta-catalogue-admin-user-create APPEND PROPERTY INSTALL_RPATH ${ORACLE-INSTANTCLIENT_RPATH})
endif (OCCI_SUPPORT)
set_property (TARGET cta-catalogue-admin-user-create APPEND PROPERTY INSTALL_RPATH ${ORACLE-INSTANTCLIENT_RPATH})
install (TARGETS cta-catalogue-admin-user-create DESTINATION /usr/bin)
install (FILES ${CMAKE_CURRENT_SOURCE_DIR}/cta-catalogue-admin-user-create.1cta DESTINATION /usr/share/man/man1)
......@@ -193,9 +172,7 @@ add_executable(cta-catalogue-admin-host-create
target_link_libraries (cta-catalogue-admin-host-create
ctacatalogue)
if (OCCI_SUPPORT)
set_property (TARGET cta-catalogue-admin-host-create APPEND PROPERTY INSTALL_RPATH ${ORACLE-INSTANTCLIENT_RPATH})
endif (OCCI_SUPPORT)
set_property (TARGET cta-catalogue-admin-host-create APPEND PROPERTY INSTALL_RPATH ${ORACLE-INSTANTCLIENT_RPATH})
install (TARGETS cta-catalogue-admin-host-create DESTINATION /usr/bin)
install (FILES ${CMAKE_CURRENT_SOURCE_DIR}/cta-catalogue-admin-host-create.1cta DESTINATION /usr/share/man/man1)
......
......@@ -128,6 +128,7 @@ public:
* disabled, not full and are in the specified logical library.
*
* @param logicalLibraryName The name of the logical library.
* @return The list of tapes for writing.
*/
virtual std::list<TapeForWriting> getTapesForWriting(const std::string &logicalLibraryName) const = 0;
......
......@@ -33,16 +33,18 @@ std::unique_ptr<Catalogue> CatalogueFactory::create(
log::Logger &log,
const rdbms::Login &login,
const uint64_t nbConns,
const uint64_t nbArchiveFileListingConns) {
const uint64_t nbArchiveFileListingConns,
const uint32_t maxTriesToConnect) {
try {
switch(login.dbType) {
case rdbms::Login::DBTYPE_IN_MEMORY:
return cta::make_unique<InMemoryCatalogue>(log, nbConns, nbArchiveFileListingConns);
return cta::make_unique<InMemoryCatalogue>(log, nbConns, nbArchiveFileListingConns, maxTriesToConnect);
case rdbms::Login::DBTYPE_ORACLE:
return cta::make_unique<OracleCatalogue>(log, login.username, login.password, login.database, nbConns,
nbArchiveFileListingConns);
nbArchiveFileListingConns, maxTriesToConnect);
case rdbms::Login::DBTYPE_SQLITE:
return cta::make_unique<SqliteCatalogue>(log, login.database, nbConns, nbArchiveFileListingConns);
return cta::make_unique<SqliteCatalogue>(log, login.database, nbConns, nbArchiveFileListingConns,
maxTriesToConnect);
case rdbms::Login::DBTYPE_NONE:
throw exception::Exception("Cannot create a catalogue without a database type");
default:
......
......@@ -51,12 +51,16 @@ public:
* listing archive files.
* @return The newly created CTA catalogue object. Please note that it is the
* responsibility of the caller to delete the returned CTA catalogue object.
* @param maxTriesToConnext The maximum number of times a single method should
* try to connect to the database in the event of LostDatabaseConnection
* exceptions being thrown.
*/
static std::unique_ptr<Catalogue> create(
log::Logger &log,
const rdbms::Login &login,
const uint64_t nbConns,
const uint64_t nbArchiveFileListingConns);
const uint64_t nbArchiveFileListingConns,
const uint32_t maxTriesToConnect = 3);
}; // class CatalogueFactory
......
......@@ -21,7 +21,7 @@
#include "catalogue/CatalogueTest.hpp"
#include "common/exception/Exception.hpp"
#include "common/exception/UserError.hpp"
#include "rdbms/ConnFactoryFactory.hpp"
#include "rdbms/wrapper/ConnFactoryFactory.hpp"
#include <algorithm>
#include <gtest/gtest.h>
......@@ -53,7 +53,7 @@ void cta_catalogue_CatalogueTest::SetUp() {
try {
const rdbms::Login &login = GetParam()->create();
auto connFactory = rdbms::ConnFactoryFactory::create(login);
auto connFactory = rdbms::wrapper::ConnFactoryFactory::create(login);
const uint64_t nbConns = 2;
const uint64_t nbArchiveFileListingConns = 2;
......@@ -237,6 +237,31 @@ std::map<std::string, cta::common::dataStructures::AdminHost> cta_catalogue_Cata
}
}
//------------------------------------------------------------------------------
// tapePoolListToMap
//------------------------------------------------------------------------------
std::map<std::string, cta::catalogue::TapePool> cta_catalogue_CatalogueTest::tapePoolListToMap(
const std::list<cta::catalogue::TapePool> &listOfTapePools) {
using namespace cta;
try {
std::map<std::string, cta::catalogue::TapePool> m;
for(auto &tapePool: listOfTapePools) {
if(m.end() != m.find(tapePool.name)) {
exception::Exception ex;
ex.getMessage() << "Tape pool " << tapePool.name << " is a duplicate";
throw ex;
}
m[tapePool.name] = tapePool;
}
return m;
} catch(exception::Exception &ex) {
throw exception::Exception(std::string(__FUNCTION__) + " failed: " + ex.getMessage().str());
}
}
TEST_P(cta_catalogue_CatalogueTest, createAdminUser) {
using namespace cta;
......@@ -1789,7 +1814,7 @@ TEST_P(cta_catalogue_CatalogueTest, createTape_9_exabytes_capacity) {
const std::string logicalLibraryName = "logical_library_name";
const std::string tapePoolName = "tape_pool_name";
// The maximum size of an SQLite integer is a signed 64-bit integer
const uint64_t capacityInBytes = std::numeric_limits<int64_t>::max();
const uint64_t capacityInBytes = 9L * 1000 * 1000 * 1000 * 1000 * 1000 * 1000;
const bool disabledValue = true;
const bool fullValue = false;
const std::string comment = "Create tape";
......@@ -4503,6 +4528,64 @@ TEST_P(cta_catalogue_CatalogueTest, deleteRequesterGroupMountRule_non_existant)
exception::UserError);
}
TEST_P(cta_catalogue_CatalogueTest, prepareForNewFile_no_archive_routes) {
using namespace cta;
ASSERT_TRUE(m_catalogue->getRequesterMountRules().empty());
const std::string mountPolicyName = "mount_policy";
const uint64_t archivePriority = 1;
const uint64_t minArchiveRequestAge = 2;
const uint64_t retrievePriority = 3;
const uint64_t minRetrieveRequestAge = 4;
const uint64_t maxDrivesAllowed = 5;
m_catalogue->createMountPolicy(
m_admin,
mountPolicyName,
archivePriority,
minArchiveRequestAge,
retrievePriority,
minRetrieveRequestAge,
maxDrivesAllowed,
"Create mount policy");
const std::string comment = "Create mount rule for requester";
const std::string diskInstanceName = "disk_instance_name";
const std::string requesterName = "requester_name";
m_catalogue->createRequesterMountRule(m_admin, mountPolicyName, diskInstanceName, requesterName, comment);
const std::list<common::dataStructures::RequesterMountRule> rules = m_catalogue->getRequesterMountRules();
ASSERT_EQ(1, rules.size());
const common::dataStructures::RequesterMountRule rule = rules.front();
ASSERT_EQ(diskInstanceName, rule.diskInstance);
ASSERT_EQ(requesterName, rule.name);
ASSERT_EQ(mountPolicyName, rule.mountPolicy);
ASSERT_EQ(comment, rule.comment);
ASSERT_EQ(m_admin.username, rule.creationLog.username);
ASSERT_EQ(m_admin.host, rule.creationLog.host);
ASSERT_EQ(rule.creationLog, rule.lastModificationLog);
// Do not create any archive routes
ASSERT_TRUE(m_catalogue->getArchiveRoutes().empty());
common::dataStructures::StorageClass storageClass;
storageClass.diskInstance = diskInstanceName;
storageClass.name = "storage_class";
storageClass.nbCopies = 2;
storageClass.comment = "Create storage class";
m_catalogue->createStorageClass(m_admin, storageClass);
common::dataStructures::UserIdentity userIdentity;
userIdentity.name = requesterName;
userIdentity.group = "group";
ASSERT_THROW(m_catalogue->prepareForNewFile(storageClass.diskInstance, storageClass.name, userIdentity),
exception::UserError);
}
TEST_P(cta_catalogue_CatalogueTest, prepareForNewFile_requester_mount_rule) {
using namespace cta;
......@@ -5497,7 +5580,8 @@ TEST_P(cta_catalogue_CatalogueTest, fileWrittenToTape_many_archive_files) {
const std::string vid1 = "VID123";
const std::string vid2 = "VID456";
const std::string logicalLibraryName = "logical_library_name";
const std::string tapePoolName = "tape_pool_name";
const std::string tapePoolName1 = "tape_pool_name_1";
const std::string tapePoolName2 = "tape_pool_name_2";
const uint64_t capacityInBytes = (uint64_t)10 * 1000 * 1000 * 1000 * 1000;
const bool disabledValue = true;
const bool fullValue = false;
......@@ -5505,44 +5589,69 @@ TEST_P(cta_catalogue_CatalogueTest, fileWrittenToTape_many_archive_files) {
m_catalogue->createLogicalLibrary(m_admin, logicalLibraryName, "Create logical library");
m_catalogue->createTapePool(m_admin, tapePoolName, 2, true, "Create tape pool");
m_catalogue->createTapePool(m_admin, tapePoolName1, 1, true, "Create tape pool");
{
const auto pools = m_catalogue->getTapePools();
ASSERT_EQ(1, pools.size());
const auto &pool = pools.front();
ASSERT_EQ(tapePoolName, pool.name);
auto tapePoolMap = tapePoolListToMap(pools);
auto tapePoolMapItor = tapePoolMap.find(tapePoolName1);
ASSERT_NE(tapePoolMapItor, tapePoolMap.end());
const auto &pool = tapePoolMapItor->second;
ASSERT_EQ(tapePoolName1, pool.name);
ASSERT_EQ(0, pool.nbTapes);
ASSERT_EQ(0, pool.capacityGigabytes);
ASSERT_EQ(0, pool.dataGigabytes);
}
uint64_t totalCapacityInBytes = 0;
m_catalogue->createTape(m_admin, vid1, logicalLibraryName, tapePoolName, capacityInBytes,
m_catalogue->createTapePool(m_admin, tapePoolName2, 1, true, "Create tape pool");
{
const auto pools = m_catalogue->getTapePools();
ASSERT_EQ(2, pools.size());
auto tapePoolMap = tapePoolListToMap(pools);
auto tapePoolMapItor = tapePoolMap.find(tapePoolName2);
ASSERT_NE(tapePoolMapItor, tapePoolMap.end());
const auto &pool = tapePoolMapItor->second;
ASSERT_EQ(tapePoolName2, pool.name);
ASSERT_EQ(0, pool.nbTapes);
ASSERT_EQ(0, pool.capacityGigabytes);
ASSERT_EQ(0, pool.dataGigabytes);
}
m_catalogue->createTape(m_admin, vid1, logicalLibraryName, tapePoolName1, capacityInBytes,
disabledValue, fullValue, comment);
totalCapacityInBytes += capacityInBytes;
{
const auto pools = m_catalogue->getTapePools();
ASSERT_EQ(1, pools.size());
ASSERT_EQ(2, pools.size());
const auto &pool = pools.front();
ASSERT_EQ(tapePoolName, pool.name);
auto tapePoolMap = tapePoolListToMap(pools);
auto tapePoolMapItor = tapePoolMap.find(tapePoolName1);
ASSERT_NE(tapePoolMapItor, tapePoolMap.end());
const auto &pool = tapePoolMapItor->second;
ASSERT_EQ(tapePoolName1, pool.name);
ASSERT_EQ(1, pool.nbTapes);
ASSERT_EQ(totalCapacityInBytes/1000000000, pool.capacityGigabytes);
ASSERT_EQ(capacityInBytes/1000000000, pool.capacityGigabytes);
ASSERT_EQ(0, pool.dataGigabytes);
}
m_catalogue->createTape(m_admin, vid2, logicalLibraryName, tapePoolName, capacityInBytes,
m_catalogue->createTape(m_admin, vid2, logicalLibraryName, tapePoolName2, capacityInBytes,
disabledValue, fullValue, comment);
totalCapacityInBytes += capacityInBytes;
{
const auto pools = m_catalogue->getTapePools();
ASSERT_EQ(1, pools.size());
ASSERT_EQ(2, pools.size());
const auto &pool = pools.front();
ASSERT_EQ(tapePoolName, pool.name);
ASSERT_EQ(2, pool.nbTapes);
ASSERT_EQ(totalCapacityInBytes/1000000000, pool.capacityGigabytes);
auto tapePoolMap = tapePoolListToMap(pools);
auto tapePoolMapItor = tapePoolMap.find(tapePoolName2);
ASSERT_NE(tapePoolMapItor, tapePoolMap.end());
const auto &pool = tapePoolMapItor->second;
ASSERT_EQ(tapePoolName2, pool.name);
ASSERT_EQ(1, pool.nbTapes);
ASSERT_EQ(capacityInBytes/1000000000, pool.capacityGigabytes);
ASSERT_EQ(0, pool.dataGigabytes);
}
......@@ -5558,7 +5667,7 @@ TEST_P(cta_catalogue_CatalogueTest, fileWrittenToTape_many_archive_files) {
const common::dataStructures::Tape &tape = it->second;
ASSERT_EQ(vid1, tape.vid);
ASSERT_EQ(logicalLibraryName, tape.logicalLibraryName);
ASSERT_EQ(tapePoolName, tape.tapePoolName);
ASSERT_EQ(tapePoolName1, tape.tapePoolName);
ASSERT_EQ(capacityInBytes, tape.capacityInBytes);
ASSERT_TRUE(disabledValue == tape.disabled);
ASSERT_TRUE(fullValue == tape.full);
......@@ -5582,7 +5691,7 @@ TEST_P(cta_catalogue_CatalogueTest, fileWrittenToTape_many_archive_files) {
const auto &tape = it->second;
ASSERT_EQ(vid2, tape.vid);
ASSERT_EQ(logicalLibraryName, tape.logicalLibraryName);
ASSERT_EQ(tapePoolName, tape.tapePoolName);
ASSERT_EQ(tapePoolName2, tape.tapePoolName);
ASSERT_EQ(capacityInBytes, tape.capacityInBytes);
ASSERT_TRUE(disabledValue == tape.disabled);
ASSERT_TRUE(fullValue == tape.full);
......@@ -5617,7 +5726,6 @@ TEST_P(cta_catalogue_CatalogueTest, fileWrittenToTape_many_archive_files) {
const uint64_t archiveFileSize = 2 * 1000 * 1000 * 1000;
const uint64_t compressedFileSize = archiveFileSize;
uint64_t totalCompressedFileSize = 0;
std::set<catalogue::TapeFileWritten> tapeFilesWrittenCopy1;
for(uint64_t i = 1; i <= nbArchiveFiles; i++) {
std::ostringstream diskFileId;
......@@ -5645,19 +5753,21 @@ TEST_P(cta_catalogue_CatalogueTest, fileWrittenToTape_many_archive_files) {
fileWritten.copyNb = 1;
fileWritten.tapeDrive = tapeDrive;
tapeFilesWrittenCopy1.emplace(fileWritten);
totalCompressedFileSize += compressedFileSize;
}
m_catalogue->filesWrittenToTape(tapeFilesWrittenCopy1);
{
const auto pools = m_catalogue->getTapePools();
ASSERT_EQ(1, pools.size());
ASSERT_EQ(2, pools.size());
const auto &pool = pools.front();
ASSERT_EQ(tapePoolName, pool.name);
ASSERT_EQ(2, pool.nbTapes);
ASSERT_EQ(totalCapacityInBytes/1000000000, pool.capacityGigabytes);
ASSERT_EQ(totalCompressedFileSize/1000000000, pool.dataGigabytes);
const auto tapePoolMap = tapePoolListToMap(pools);
auto tapePoolMapItor = tapePoolMap.find(tapePoolName1);
ASSERT_NE(tapePoolMapItor, tapePoolMap.end());
const auto &pool = tapePoolMapItor->second;
ASSERT_EQ(tapePoolName1, pool.name);
ASSERT_EQ(1, pool.nbTapes);
ASSERT_EQ(capacityInBytes/1000000000, pool.capacityGigabytes);
ASSERT_EQ(nbArchiveFiles * compressedFileSize/1000000000, pool.dataGigabytes);
}
{
......@@ -5705,19 +5815,21 @@ TEST_P(cta_catalogue_CatalogueTest, fileWrittenToTape_many_archive_files) {
fileWritten.copyNb = 2;
fileWritten.tapeDrive = tapeDrive;
tapeFilesWrittenCopy2.emplace(fileWritten);
totalCompressedFileSize += compressedFileSize;
}
m_catalogue->filesWrittenToTape(tapeFilesWrittenCopy2);
{
const auto pools = m_catalogue->getTapePools();
ASSERT_EQ(1, pools.size());
ASSERT_EQ(2, pools.size());
const auto &pool = pools.front();
ASSERT_EQ(tapePoolName, pool.name);
ASSERT_EQ(2, pool.nbTapes);
ASSERT_EQ(totalCapacityInBytes/1000000000, pool.capacityGigabytes);
ASSERT_EQ(totalCompressedFileSize/1000000000, pool.dataGigabytes);
const auto tapePoolMap = tapePoolListToMap(pools);
auto tapePoolMapItor = tapePoolMap.find(tapePoolName2);
ASSERT_NE(tapePoolMapItor, tapePoolMap.end());
const auto &pool = tapePoolMapItor->second;
ASSERT_EQ(tapePoolName2, pool.name);
ASSERT_EQ(1, pool.nbTapes);
ASSERT_EQ(capacityInBytes/1000000000, pool.capacityGigabytes);
ASSERT_EQ(nbArchiveFiles * compressedFileSize/1000000000, pool.dataGigabytes);
}
{
......@@ -5749,7 +5861,7 @@ TEST_P(cta_catalogue_CatalogueTest, fileWrittenToTape_many_archive_files) {
searchCriteria.storageClass = storageClass.name;
searchCriteria.vid = vid1;
searchCriteria.tapeFileCopyNb = 1;
searchCriteria.tapePool = tapePoolName;
searchCriteria.tapePool = tapePoolName1;
auto archiveFileItor = m_catalogue->getArchiveFiles(searchCriteria);
std::map<uint64_t, common::dataStructures::ArchiveFile> m = archiveFileItorToMap(archiveFileItor);
......@@ -5988,15 +6100,28 @@ TEST_P(cta_catalogue_CatalogueTest, fileWrittenToTape_many_archive_files) {
{
catalogue::TapeFileSearchCriteria searchCriteria;
searchCriteria.tapePool = "tape_pool_name";
searchCriteria.tapePool = tapePoolName1;
auto archiveFileItor = m_catalogue->getArchiveFiles(searchCriteria);
const auto m = archiveFileItorToMap(archiveFileItor);
ASSERT_EQ(nbArchiveFiles, m.size());
const common::dataStructures::ArchiveFileSummary summary = m_catalogue->getTapeFileSummary(searchCriteria);
ASSERT_EQ(nbArchiveFiles * storageClass.nbCopies * archiveFileSize, summary.totalBytes);
ASSERT_EQ(nbArchiveFiles * storageClass.nbCopies * compressedFileSize, summary.totalCompressedBytes);
ASSERT_EQ(nbArchiveFiles * storageClass.nbCopies, summary.totalFiles);
ASSERT_EQ(nbArchiveFiles * archiveFileSize, summary.totalBytes);
ASSERT_EQ(nbArchiveFiles * compressedFileSize, summary.totalCompressedBytes);
ASSERT_EQ(nbArchiveFiles, summary.totalFiles);
}
{
catalogue::TapeFileSearchCriteria searchCriteria;
searchCriteria.tapePool = tapePoolName2;
auto archiveFileItor = m_catalogue->getArchiveFiles(searchCriteria);
const auto m = archiveFileItorToMap(archiveFileItor);
ASSERT_EQ(nbArchiveFiles, m.size());
const common::dataStructures::ArchiveFileSummary summary = m_catalogue->getTapeFileSummary(searchCriteria);
ASSERT_EQ(nbArchiveFiles * archiveFileSize, summary.totalBytes);
ASSERT_EQ(nbArchiveFiles * compressedFileSize, summary.totalCompressedBytes);
ASSERT_EQ(nbArchiveFiles, summary.totalFiles);
}
{
......
......@@ -22,7 +22,7 @@
#include "catalogue/CatalogueFactory.hpp"
#include "common/exception/Exception.hpp"
#include "common/log/DummyLogger.hpp"
#include "rdbms/Conn.hpp"
#include "rdbms/wrapper/Conn.hpp"
#include "rdbms/LoginFactory.hpp"
#include <gtest/gtest.h>
......@@ -48,7 +48,7 @@ protected:
* A general purpose database connection outside of the m_catalogue object to
* be used to run tests directly on the underlying "raw" catalogue database.
*/
std::unique_ptr<cta::rdbms::Conn> m_conn;
std::unique_ptr<cta::rdbms::wrapper::Conn> m_conn;
virtual void SetUp();
......@@ -92,6 +92,16 @@ protected:
*/
std::map<std::string, cta::common::dataStructures::AdminHost> adminHostListToMap(
const std::list<cta::common::dataStructures::AdminHost> &listOfAdminHosts);
/**
* Creates a map from tape pool name to tape pool from the specified list of
* tape pools.
*
* @param listOfTapePools The list of tape pools.
* @return Map from tape pool name to tape pool.
*/
std::map<std::string, cta::catalogue::TapePool> tapePoolListToMap(
const std::list<cta::catalogue::TapePool> &listOfTapePools);
}; // cta_catalogue_CatalogueTest
} // namespace unitTests
......@@ -21,7 +21,7 @@
#include "catalogue/CreateAdminHostCmdLineArgs.hpp"
#include "common/exception/Exception.hpp"
#include "common/log/DummyLogger.hpp"
#include "rdbms/ConnFactoryFactory.hpp"
#include "rdbms/wrapper/ConnFactoryFactory.hpp"
namespace cta {
namespace catalogue {
......
......@@ -21,7 +21,7 @@
#include "catalogue/CreateAdminUserCmdLineArgs.hpp"
#include "common/exception/Exception.hpp"
#include "common/log/DummyLogger.hpp"
#include "rdbms/ConnFactoryFactory.hpp"
#include "rdbms/wrapper/ConnFactoryFactory.hpp"
namespace cta {