Commit ab6bba1d authored by Steven Murray's avatar Steven Murray
Browse files

CatalogueTest now tests the writing of two tape files with the same copy number

parent a3af47e3
......@@ -6713,6 +6713,416 @@ TEST_P(cta_catalogue_CatalogueTest, filesWrittenToTape_1_archive_file_2_tape_cop
}
}
TEST_P(cta_catalogue_CatalogueTest, filesWrittenToTape_1_archive_file_2_tape_copies_same_copy_number) {
using namespace cta;
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 uint64_t capacityInBytes = (uint64_t)10 * 1000 * 1000 * 1000 * 1000;
const bool disabledValue = true;
const bool fullValue = false;
const std::string comment = "Create tape";
m_catalogue->createLogicalLibrary(m_admin, logicalLibraryName,
"Create logical library");
m_catalogue->createTapePool(m_admin, tapePoolName, 2, true, "Create tape pool");
m_catalogue->createTape(m_admin, vid1, logicalLibraryName, tapePoolName, capacityInBytes, disabledValue, fullValue,
comment);
m_catalogue->createTape(m_admin, vid2, logicalLibraryName, tapePoolName, capacityInBytes, disabledValue, fullValue,
comment);
{
const std::list<common::dataStructures::Tape> tapes = m_catalogue->getTapes();
ASSERT_EQ(2, tapes.size());
const std::map<std::string, common::dataStructures::Tape> vidToTape = tapeListToMap(tapes);
{
auto it = vidToTape.find(vid1);
const common::dataStructures::Tape &tape = it->second;
ASSERT_EQ(vid1, tape.vid);
ASSERT_EQ(logicalLibraryName, tape.logicalLibraryName);
ASSERT_EQ(tapePoolName, tape.tapePoolName);
ASSERT_EQ(capacityInBytes, tape.capacityInBytes);
ASSERT_TRUE(disabledValue == tape.disabled);
ASSERT_TRUE(fullValue == tape.full);
ASSERT_FALSE(tape.lbp);
ASSERT_EQ(comment, tape.comment);
ASSERT_FALSE(tape.labelLog);
ASSERT_FALSE(tape.lastReadLog);
ASSERT_FALSE(tape.lastWriteLog);
const common::dataStructures::EntryLog creationLog = tape.creationLog;
ASSERT_EQ(m_admin.username, creationLog.username);
ASSERT_EQ(m_admin.host, creationLog.host);
const common::dataStructures::EntryLog lastModificationLog =
tape.lastModificationLog;
ASSERT_EQ(creationLog, lastModificationLog);
}
{
auto it = vidToTape.find(vid2);
const common::dataStructures::Tape &tape = it->second;
ASSERT_EQ(vid2, tape.vid);
ASSERT_EQ(logicalLibraryName, tape.logicalLibraryName);
ASSERT_EQ(tapePoolName, tape.tapePoolName);
ASSERT_EQ(capacityInBytes, tape.capacityInBytes);
ASSERT_TRUE(disabledValue == tape.disabled);
ASSERT_TRUE(fullValue == tape.full);
ASSERT_FALSE(tape.lbp);
ASSERT_EQ(comment, tape.comment);
ASSERT_FALSE(tape.labelLog);
ASSERT_FALSE(tape.lastReadLog);
ASSERT_FALSE(tape.lastWriteLog);
const common::dataStructures::EntryLog creationLog = tape.creationLog;
ASSERT_EQ(m_admin.username, creationLog.username);
ASSERT_EQ(m_admin.host, creationLog.host);
const common::dataStructures::EntryLog lastModificationLog =
tape.lastModificationLog;
ASSERT_EQ(creationLog, lastModificationLog);
}
}
const uint64_t archiveFileId = 1234;
ASSERT_FALSE(m_catalogue->getArchiveFiles().hasMore());
ASSERT_THROW(m_catalogue->getArchiveFileById(archiveFileId), exception::Exception);
common::dataStructures::StorageClass storageClass;
storageClass.diskInstance = "disk_instance";
storageClass.name = "storage_class";
storageClass.nbCopies = 2;
storageClass.comment = "Create storage class";
m_catalogue->createStorageClass(m_admin, storageClass);
const uint64_t archiveFileSize = 1;
const std::string checksumType = "checksum_type";
const std::string checksumValue = "checksum_value";
const std::string tapeDrive = "tape_drive";
catalogue::TapeFileWritten file1Written;
file1Written.archiveFileId = archiveFileId;
file1Written.diskInstance = storageClass.diskInstance;
file1Written.diskFileId = "5678";
file1Written.diskFilePath = "/public_dir/public_file";
file1Written.diskFileUser = "public_disk_user";
file1Written.diskFileGroup = "public_disk_group";
file1Written.diskFileRecoveryBlob = "opaque_disk_file_recovery_contents";
file1Written.size = archiveFileSize;
file1Written.checksumType = checksumType;
file1Written.checksumValue = checksumValue;
file1Written.storageClassName = storageClass.name;
file1Written.vid = vid1;
file1Written.fSeq = 1;
file1Written.blockId = 4321;
file1Written.compressedSize = 1;
file1Written.copyNb = 1;
file1Written.tapeDrive = tapeDrive;
m_catalogue->filesWrittenToTape(std::set<catalogue::TapeFileWritten>{file1Written});
{
catalogue::TapeSearchCriteria searchCriteria;
searchCriteria.vid = file1Written.vid;
std::list<common::dataStructures::Tape> tapes = m_catalogue->getTapes(searchCriteria);
ASSERT_EQ(1, tapes.size());
const common::dataStructures::Tape &tape = tapes.front();
ASSERT_EQ(1, tape.lastFSeq);
}
{
const common::dataStructures::ArchiveFile archiveFile = m_catalogue->getArchiveFileById(archiveFileId);
ASSERT_EQ(file1Written.archiveFileId, archiveFile.archiveFileID);
ASSERT_EQ(file1Written.diskFileId, archiveFile.diskFileId);
ASSERT_EQ(file1Written.size, archiveFile.fileSize);
ASSERT_EQ(file1Written.checksumType, archiveFile.checksumType);
ASSERT_EQ(file1Written.checksumValue, archiveFile.checksumValue);
ASSERT_EQ(file1Written.storageClassName, archiveFile.storageClass);
ASSERT_EQ(file1Written.diskInstance, archiveFile.diskInstance);
ASSERT_EQ(file1Written.diskFilePath, archiveFile.diskFileInfo.path);
ASSERT_EQ(file1Written.diskFileUser, archiveFile.diskFileInfo.owner);
ASSERT_EQ(file1Written.diskFileGroup, archiveFile.diskFileInfo.group);
ASSERT_EQ(file1Written.diskFileRecoveryBlob, archiveFile.diskFileInfo.recoveryBlob);
ASSERT_EQ(1, archiveFile.tapeFiles.size());
auto copyNbToTapeFile1Itor = archiveFile.tapeFiles.find(1);
ASSERT_FALSE(copyNbToTapeFile1Itor == archiveFile.tapeFiles.end());
const common::dataStructures::TapeFile &tapeFile1 = copyNbToTapeFile1Itor->second;
ASSERT_EQ(file1Written.vid, tapeFile1.vid);
ASSERT_EQ(file1Written.fSeq, tapeFile1.fSeq);
ASSERT_EQ(file1Written.blockId, tapeFile1.blockId);
ASSERT_EQ(file1Written.compressedSize, tapeFile1.compressedSize);
ASSERT_EQ(file1Written.checksumType, tapeFile1.checksumType);
ASSERT_EQ(file1Written.checksumValue, tapeFile1.checksumValue);
ASSERT_EQ(file1Written.copyNb, tapeFile1.copyNb);
}
catalogue::TapeFileWritten file2Written;
file2Written.archiveFileId = file1Written.archiveFileId;
file2Written.diskInstance = file1Written.diskInstance;
file2Written.diskFileId = file1Written.diskFileId;
file2Written.diskFilePath = file1Written.diskFilePath;
file2Written.diskFileUser = file1Written.diskFileUser;
file2Written.diskFileGroup = file1Written.diskFileGroup;
file2Written.diskFileRecoveryBlob = file1Written.diskFileRecoveryBlob;
file2Written.size = archiveFileSize;
file2Written.checksumType = checksumType;
file2Written.checksumValue = checksumValue;
file2Written.storageClassName = storageClass.name;
file2Written.vid = vid2;
file2Written.fSeq = 1;
file2Written.blockId = 4331;
file2Written.compressedSize = 1;
file2Written.copyNb = 1;
file2Written.tapeDrive = tapeDrive;
m_catalogue->filesWrittenToTape(std::set<catalogue::TapeFileWritten>{file2Written});
{
ASSERT_EQ(2, m_catalogue->getTapes().size());
catalogue::TapeSearchCriteria searchCriteria;
searchCriteria.vid = file2Written.vid;
std::list<common::dataStructures::Tape> tapes = m_catalogue->getTapes(searchCriteria);
ASSERT_EQ(1, tapes.size());
const common::dataStructures::Tape &tape = tapes.front();
ASSERT_EQ(1, tape.lastFSeq);
}
{
const common::dataStructures::ArchiveFile archiveFile = m_catalogue->getArchiveFileById(archiveFileId);
ASSERT_EQ(file2Written.archiveFileId, archiveFile.archiveFileID);
ASSERT_EQ(file2Written.diskFileId, archiveFile.diskFileId);
ASSERT_EQ(file2Written.size, archiveFile.fileSize);
ASSERT_EQ(file2Written.checksumType, archiveFile.checksumType);
ASSERT_EQ(file2Written.checksumValue, archiveFile.checksumValue);
ASSERT_EQ(file2Written.storageClassName, archiveFile.storageClass);
ASSERT_EQ(file2Written.diskInstance, archiveFile.diskInstance);
ASSERT_EQ(file2Written.diskFilePath, archiveFile.diskFileInfo.path);
ASSERT_EQ(file2Written.diskFileUser, archiveFile.diskFileInfo.owner);
ASSERT_EQ(file2Written.diskFileGroup, archiveFile.diskFileInfo.group);
ASSERT_EQ(file2Written.diskFileRecoveryBlob, archiveFile.diskFileInfo.recoveryBlob);
// If there are two or more tape copies with the same copy number then
// only the last one read out by the database is returned by
// m_catalogue->getArchiveFileById()
ASSERT_EQ(1, archiveFile.tapeFiles.size());
const auto &tapeFile = archiveFile.tapeFiles.begin()->second;
ASSERT_TRUE(file1Written.vid == tapeFile.vid || file2Written.vid == tapeFile.vid);
{
const auto &fileWritten = file1Written.vid == tapeFile.vid ? file1Written : file2Written;
ASSERT_EQ(fileWritten.vid, tapeFile.vid);
ASSERT_EQ(fileWritten.fSeq, tapeFile.fSeq);
ASSERT_EQ(fileWritten.blockId, tapeFile.blockId);
ASSERT_EQ(fileWritten.compressedSize, tapeFile.compressedSize);
ASSERT_EQ(fileWritten.checksumType, tapeFile.checksumType);
ASSERT_EQ(fileWritten.checksumValue, tapeFile.checksumValue);
ASSERT_EQ(fileWritten.copyNb, tapeFile.copyNb);
}
}
}
TEST_P(cta_catalogue_CatalogueTest, filesWrittenToTape_1_archive_file_2_tape_copies_same_copy_number_same_tape) {
using namespace cta;
const std::string vid1 = "VID123";
const std::string logicalLibraryName = "logical_library_name";
const std::string tapePoolName = "tape_pool_name";
const uint64_t capacityInBytes = (uint64_t)10 * 1000 * 1000 * 1000 * 1000;
const bool disabledValue = true;
const bool fullValue = false;
const std::string comment = "Create tape";
m_catalogue->createLogicalLibrary(m_admin, logicalLibraryName,
"Create logical library");
m_catalogue->createTapePool(m_admin, tapePoolName, 2, true, "Create tape pool");
m_catalogue->createTape(m_admin, vid1, logicalLibraryName, tapePoolName, capacityInBytes, disabledValue, fullValue,
comment);
{
const std::list<common::dataStructures::Tape> tapes = m_catalogue->getTapes();
ASSERT_EQ(1, tapes.size());
const std::map<std::string, common::dataStructures::Tape> vidToTape = tapeListToMap(tapes);
{
auto it = vidToTape.find(vid1);
const common::dataStructures::Tape &tape = it->second;
ASSERT_EQ(vid1, tape.vid);
ASSERT_EQ(logicalLibraryName, tape.logicalLibraryName);
ASSERT_EQ(tapePoolName, tape.tapePoolName);
ASSERT_EQ(capacityInBytes, tape.capacityInBytes);
ASSERT_TRUE(disabledValue == tape.disabled);
ASSERT_TRUE(fullValue == tape.full);
ASSERT_FALSE(tape.lbp);
ASSERT_EQ(comment, tape.comment);
ASSERT_FALSE(tape.labelLog);
ASSERT_FALSE(tape.lastReadLog);
ASSERT_FALSE(tape.lastWriteLog);
const common::dataStructures::EntryLog creationLog = tape.creationLog;
ASSERT_EQ(m_admin.username, creationLog.username);
ASSERT_EQ(m_admin.host, creationLog.host);
const common::dataStructures::EntryLog lastModificationLog =
tape.lastModificationLog;
ASSERT_EQ(creationLog, lastModificationLog);
}
}
const uint64_t archiveFileId = 1234;
ASSERT_FALSE(m_catalogue->getArchiveFiles().hasMore());
ASSERT_THROW(m_catalogue->getArchiveFileById(archiveFileId), exception::Exception);
common::dataStructures::StorageClass storageClass;
storageClass.diskInstance = "disk_instance";
storageClass.name = "storage_class";
storageClass.nbCopies = 2;
storageClass.comment = "Create storage class";
m_catalogue->createStorageClass(m_admin, storageClass);
const uint64_t archiveFileSize = 1;
const std::string checksumType = "checksum_type";
const std::string checksumValue = "checksum_value";
const std::string tapeDrive = "tape_drive";
catalogue::TapeFileWritten file1Written;
file1Written.archiveFileId = archiveFileId;
file1Written.diskInstance = storageClass.diskInstance;
file1Written.diskFileId = "5678";
file1Written.diskFilePath = "/public_dir/public_file";
file1Written.diskFileUser = "public_disk_user";
file1Written.diskFileGroup = "public_disk_group";
file1Written.diskFileRecoveryBlob = "opaque_disk_file_recovery_contents";
file1Written.size = archiveFileSize;
file1Written.checksumType = checksumType;
file1Written.checksumValue = checksumValue;
file1Written.storageClassName = storageClass.name;
file1Written.vid = vid1;
file1Written.fSeq = 1;
file1Written.blockId = 4321;
file1Written.compressedSize = 1;
file1Written.copyNb = 1;
file1Written.tapeDrive = tapeDrive;
m_catalogue->filesWrittenToTape(std::set<catalogue::TapeFileWritten>{file1Written});
{
catalogue::TapeSearchCriteria searchCriteria;
searchCriteria.vid = file1Written.vid;
std::list<common::dataStructures::Tape> tapes = m_catalogue->getTapes(searchCriteria);
ASSERT_EQ(1, tapes.size());
const common::dataStructures::Tape &tape = tapes.front();
ASSERT_EQ(1, tape.lastFSeq);
}
{
const common::dataStructures::ArchiveFile archiveFile = m_catalogue->getArchiveFileById(archiveFileId);
ASSERT_EQ(file1Written.archiveFileId, archiveFile.archiveFileID);
ASSERT_EQ(file1Written.diskFileId, archiveFile.diskFileId);
ASSERT_EQ(file1Written.size, archiveFile.fileSize);
ASSERT_EQ(file1Written.checksumType, archiveFile.checksumType);
ASSERT_EQ(file1Written.checksumValue, archiveFile.checksumValue);
ASSERT_EQ(file1Written.storageClassName, archiveFile.storageClass);
ASSERT_EQ(file1Written.diskInstance, archiveFile.diskInstance);
ASSERT_EQ(file1Written.diskFilePath, archiveFile.diskFileInfo.path);
ASSERT_EQ(file1Written.diskFileUser, archiveFile.diskFileInfo.owner);
ASSERT_EQ(file1Written.diskFileGroup, archiveFile.diskFileInfo.group);
ASSERT_EQ(file1Written.diskFileRecoveryBlob, archiveFile.diskFileInfo.recoveryBlob);
ASSERT_EQ(1, archiveFile.tapeFiles.size());
auto copyNbToTapeFile1Itor = archiveFile.tapeFiles.find(1);
ASSERT_FALSE(copyNbToTapeFile1Itor == archiveFile.tapeFiles.end());
const common::dataStructures::TapeFile &tapeFile1 = copyNbToTapeFile1Itor->second;
ASSERT_EQ(file1Written.vid, tapeFile1.vid);
ASSERT_EQ(file1Written.fSeq, tapeFile1.fSeq);
ASSERT_EQ(file1Written.blockId, tapeFile1.blockId);
ASSERT_EQ(file1Written.compressedSize, tapeFile1.compressedSize);
ASSERT_EQ(file1Written.checksumType, tapeFile1.checksumType);
ASSERT_EQ(file1Written.checksumValue, tapeFile1.checksumValue);
ASSERT_EQ(file1Written.copyNb, tapeFile1.copyNb);
}
catalogue::TapeFileWritten file2Written;
file2Written.archiveFileId = file1Written.archiveFileId;
file2Written.diskInstance = file1Written.diskInstance;
file2Written.diskFileId = file1Written.diskFileId;
file2Written.diskFilePath = file1Written.diskFilePath;
file2Written.diskFileUser = file1Written.diskFileUser;
file2Written.diskFileGroup = file1Written.diskFileGroup;
file2Written.diskFileRecoveryBlob = file1Written.diskFileRecoveryBlob;
file2Written.size = archiveFileSize;
file2Written.checksumType = checksumType;
file2Written.checksumValue = checksumValue;
file2Written.storageClassName = storageClass.name;
file2Written.vid = vid1;
file2Written.fSeq = 2;
file2Written.blockId = 4331;
file2Written.compressedSize = 1;
file2Written.copyNb = 1;
file2Written.tapeDrive = tapeDrive;
m_catalogue->filesWrittenToTape(std::set<catalogue::TapeFileWritten>{file2Written});
{
ASSERT_EQ(1, m_catalogue->getTapes().size());
catalogue::TapeSearchCriteria searchCriteria;
searchCriteria.vid = file2Written.vid;
std::list<common::dataStructures::Tape> tapes = m_catalogue->getTapes(searchCriteria);
ASSERT_EQ(1, tapes.size());
const common::dataStructures::Tape &tape = tapes.front();
ASSERT_EQ(2, tape.lastFSeq);
}
{
const common::dataStructures::ArchiveFile archiveFile = m_catalogue->getArchiveFileById(archiveFileId);
ASSERT_EQ(file2Written.archiveFileId, archiveFile.archiveFileID);
ASSERT_EQ(file2Written.diskFileId, archiveFile.diskFileId);
ASSERT_EQ(file2Written.size, archiveFile.fileSize);
ASSERT_EQ(file2Written.checksumType, archiveFile.checksumType);
ASSERT_EQ(file2Written.checksumValue, archiveFile.checksumValue);
ASSERT_EQ(file2Written.storageClassName, archiveFile.storageClass);
ASSERT_EQ(file2Written.diskInstance, archiveFile.diskInstance);
ASSERT_EQ(file2Written.diskFilePath, archiveFile.diskFileInfo.path);
ASSERT_EQ(file2Written.diskFileUser, archiveFile.diskFileInfo.owner);
ASSERT_EQ(file2Written.diskFileGroup, archiveFile.diskFileInfo.group);
ASSERT_EQ(file2Written.diskFileRecoveryBlob, archiveFile.diskFileInfo.recoveryBlob);
// If there are two or more tape copies with the same copy number then
// only the last one read out by the database is returned by
// m_catalogue->getArchiveFileById()
ASSERT_EQ(1, archiveFile.tapeFiles.size());
const auto &tapeFile = archiveFile.tapeFiles.begin()->second;
ASSERT_TRUE(file1Written.fSeq == tapeFile.fSeq || file2Written.fSeq == tapeFile.fSeq);
{
const auto &fileWritten = file1Written.fSeq == tapeFile.fSeq ? file1Written : file2Written;
ASSERT_EQ(fileWritten.vid, tapeFile.vid);
ASSERT_EQ(fileWritten.fSeq, tapeFile.fSeq);
ASSERT_EQ(fileWritten.blockId, tapeFile.blockId);
ASSERT_EQ(fileWritten.compressedSize, tapeFile.compressedSize);
ASSERT_EQ(fileWritten.checksumType, tapeFile.checksumType);
ASSERT_EQ(fileWritten.checksumValue, tapeFile.checksumValue);
ASSERT_EQ(fileWritten.copyNb, tapeFile.copyNb);
}
}
}
TEST_P(cta_catalogue_CatalogueTest, filesWrittenToTape_1_archive_file_2_tape_copies_different_sizes) {
using namespace cta;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment