Commit 2bde18cc authored by Steven Murray's avatar Steven Murray
Browse files

Added catalogue unit-test fileWrittenToTape_many_archive_files

parent bbc54335
......@@ -261,10 +261,17 @@ public:
/**
* Returns an iterator over the list of archive files that meet the specified
* search criteria. Please note that the list is ordered by archive file ID.
* search criteria.
*
* Please note that the list is ordered by archive file ID.
*
* Please note that this method will throw an exception if the
* nbArchiveFilesToPrefetch parameter is set to 0. The parameter must be set
* to a value greater than or equal to 1.
*
* @param searchCriteria The search criteria.
* @param nbArchiveFilesToPrefetch The number of archive files to prefetch.
* This parameter must be set to a value equal to or greater than 1.
* @return An iterator over the list of archive files.
*/
virtual std::unique_ptr<ArchiveFileItor> getArchiveFileItor(
......@@ -357,8 +364,9 @@ public:
virtual bool isAdmin(const common::dataStructures::SecurityIdentity &cliIdentity) const = 0;
/**
* Returns the list of tapes that can be written to be a tape drive in the
* specified logical library.
* Returns the list of tapes that can be written to by a tape drive in the
* specified logical library, in other words tapes that are not disabled, not
* full and are in the specified logical library.
*
* @param logicalLibraryName The name of the logical library.
*/
......
......@@ -2038,6 +2038,145 @@ TEST_F(cta_catalogue_InMemoryCatalogueTest, prepareToRetrieveFile) {
ASSERT_EQ(maxDrivesAllowed, queueCriteria.mountPolicy.maxDrivesAllowed);
}
TEST_F(cta_catalogue_InMemoryCatalogueTest, getArchiveFileItor_zero_prefetch) {
using namespace cta;
ASSERT_THROW(m_catalogue->getArchiveFileItor(catalogue::ArchiveFileSearchCriteria(), 0), exception::Exception);
}
TEST_F(cta_catalogue_InMemoryCatalogueTest, fileWrittenToTape_many_archive_files) {
using namespace cta;
const std::string vid = "VID123";
const std::string logicalLibraryName = "logical_library_name";
const std::string tapePoolName = "tape_pool_name";
const std::string encryptionKey = "encryption_key";
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_cliSI, logicalLibraryName, "create logical library");
m_catalogue->createTapePool(m_cliSI, tapePoolName, 2, true, "create tape pool");
m_catalogue->createTape(m_cliSI, vid, logicalLibraryName, tapePoolName, encryptionKey, 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(vid);
const common::dataStructures::Tape &tape = it->second;
ASSERT_EQ(vid, tape.vid);
ASSERT_EQ(logicalLibraryName, tape.logicalLibraryName);
ASSERT_EQ(tapePoolName, tape.tapePoolName);
ASSERT_EQ(encryptionKey, tape.encryptionKey);
ASSERT_EQ(capacityInBytes, tape.capacityInBytes);
ASSERT_TRUE(disabledValue == tape.disabled);
ASSERT_TRUE(fullValue == tape.full);
ASSERT_EQ(comment, tape.comment);
const common::dataStructures::EntryLog creationLog = tape.creationLog;
ASSERT_EQ(m_cliSI.username, creationLog.username);
ASSERT_EQ(m_cliSI.host, creationLog.host);
const common::dataStructures::EntryLog lastModificationLog =
tape.lastModificationLog;
ASSERT_EQ(creationLog, lastModificationLog);
}
const std::string storageClassName = "storage_class";
const uint64_t nbCopies = 1;
m_catalogue->createStorageClass(m_cliSI, storageClassName, nbCopies, "create storage class");
ASSERT_FALSE(m_catalogue->getArchiveFileItor()->hasMore());
const uint64_t nbArchiveFiles = 100;
for(uint64_t i = 1; i <= nbArchiveFiles; i++) {
const uint64_t archiveFileSize = 1;
std::ostringstream diskFileId;
diskFileId << (12345677 + i);
std::ostringstream diskFilePath;
diskFilePath << "/public_dir/public_file_" << i;
catalogue::TapeFileWritten fileWritten;
fileWritten.archiveFileId = i;
fileWritten.diskInstance = "PUBLIC";
fileWritten.diskFileId = diskFileId.str();
fileWritten.diskFilePath = diskFilePath.str();
fileWritten.diskFileUser = "public_disk_user";
fileWritten.diskFileGroup = "public_disk_group";
fileWritten.diskFileRecoveryBlob = "opaque_disk_file_recovery_contents";
fileWritten.size = archiveFileSize;
fileWritten.storageClassName = storageClassName;
fileWritten.vid = vid;
fileWritten.fSeq = i;
fileWritten.blockId = i * 100;
fileWritten.compressedSize = 1;
fileWritten.copyNb = 1;
m_catalogue->fileWrittenToTape(fileWritten);
const std::list<common::dataStructures::Tape> tapes = m_catalogue->getTapes("", "", "", "", "", "", "", "");
ASSERT_EQ(1, tapes.size());
const common::dataStructures::Tape &tape = tapes.front();
ASSERT_EQ(vid, tape.vid);
ASSERT_EQ(i, tape.lastFSeq);
}
std::list<uint64_t> prefetches = {1, 2, 3, nbArchiveFiles - 1, nbArchiveFiles, nbArchiveFiles+1, nbArchiveFiles*2};
for(auto prefetch: prefetches) {
std::unique_ptr<catalogue::ArchiveFileItor> archiveFileItor =
m_catalogue->getArchiveFileItor(catalogue::ArchiveFileSearchCriteria(), prefetch);
std::map<uint64_t, common::dataStructures::ArchiveFile> m = archiveFileItorToMap(*archiveFileItor);
ASSERT_EQ(nbArchiveFiles, m.size());
for(uint64_t i = 1; i <= nbArchiveFiles; i++) {
const uint64_t archiveFileSize = 1;
std::ostringstream diskFileId;
diskFileId << (12345677 + i);
std::ostringstream diskFilePath;
diskFilePath << "/public_dir/public_file_" << i;
catalogue::TapeFileWritten fileWritten;
fileWritten.archiveFileId = i;
fileWritten.diskInstance = "PUBLIC";
fileWritten.diskFileId = diskFileId.str();
fileWritten.diskFilePath = diskFilePath.str();
fileWritten.diskFileUser = "public_disk_user";
fileWritten.diskFileGroup = "public_disk_group";
fileWritten.diskFileRecoveryBlob = "opaque_disk_file_recovery_contents";
fileWritten.size = archiveFileSize;
fileWritten.storageClassName = storageClassName;
fileWritten.vid = vid;
fileWritten.fSeq = i;
fileWritten.blockId = i * 100;
fileWritten.compressedSize = 1;
fileWritten.copyNb = 1;
const auto idAndFile = m.find(i);
ASSERT_FALSE(m.end() == idAndFile);
const common::dataStructures::ArchiveFile archiveFile = idAndFile->second;
ASSERT_EQ(fileWritten.archiveFileId, archiveFile.archiveFileID);
ASSERT_EQ(fileWritten.diskInstance, archiveFile.diskInstance);
ASSERT_EQ(fileWritten.diskFileId, archiveFile.diskFileId);
ASSERT_EQ(fileWritten.diskFilePath, archiveFile.drData.drPath);
ASSERT_EQ(fileWritten.diskFileUser, archiveFile.drData.drOwner);
ASSERT_EQ(fileWritten.diskFileGroup, archiveFile.drData.drGroup);
ASSERT_EQ(fileWritten.diskFileRecoveryBlob, archiveFile.drData.drBlob);
ASSERT_EQ(fileWritten.size, archiveFile.fileSize);
ASSERT_EQ(fileWritten.storageClassName, archiveFile.storageClass);
ASSERT_EQ(1, archiveFile.tapeFiles.size());
ASSERT_EQ(fileWritten.vid, archiveFile.tapeFiles.begin()->second.vid);
ASSERT_EQ(fileWritten.fSeq, archiveFile.tapeFiles.begin()->second.fSeq);
ASSERT_EQ(fileWritten.blockId, archiveFile.tapeFiles.begin()->second.blockId);
ASSERT_EQ(fileWritten.compressedSize, archiveFile.tapeFiles.begin()->second.compressedSize);
ASSERT_EQ(fileWritten.copyNb, archiveFile.tapeFiles.begin()->first);
ASSERT_EQ(fileWritten.copyNb, archiveFile.tapeFiles.begin()->second.copyNb);
}
}
}
TEST_F(cta_catalogue_InMemoryCatalogueTest, fileWrittenToTape_2_tape_files_different_tapes) {
using namespace cta;
......@@ -2229,7 +2368,7 @@ TEST_F(cta_catalogue_InMemoryCatalogueTest, fileWrittenToTape_2_tape_files_diffe
}
}
TEST_F(cta_catalogue_InMemoryCatalogueTest, fileWrittenToTape_2_tape_files_same_tape) {
TEST_F(cta_catalogue_InMemoryCatalogueTest, fileWrittenToTape_2_tape_files_same_archive_file_same_tape) {
using namespace cta;
const std::string vid = "VID123";
......
......@@ -2315,6 +2315,12 @@ RdbmsCatalogue::ArchiveFileItorImpl::ArchiveFileItorImpl(
m_searchCriteria(searchCriteria),
m_nextArchiveFileId(1) {
try {
if(1 > m_nbArchiveFilesToPrefetch) {
exception::Exception ex;
ex.getMessage() << "nbArchiveFilesToPrefetch must equal to or greater than 1: actual=" <<
m_nbArchiveFilesToPrefetch;
throw ex;
}
m_prefechedArchiveFiles = m_catalogue.getArchiveFilesForItor(m_nextArchiveFileId, m_nbArchiveFilesToPrefetch,
m_searchCriteria);
if(!m_prefechedArchiveFiles.empty()) {
......
......@@ -240,10 +240,17 @@ public:
/**
* Returns an iterator over the list of archive files that meet the specified
* search criteria. Please note that the list is ordered by archive file ID.
* search criteria.
*
* Please note that the list is ordered by archive file ID.
*
* Please note that this method will throw an exception if the
* nbArchiveFilesToPrefetch parameter is set to 0. The parameter must be set
* to a value greater than or equal to 1.
*
* @param searchCriteria The search criteria.
* @param nbArchiveFilesToPrefetch The number of archive files to prefetch.
* This parameter must be set to a value equal to or greater than 1.
* @return An iterator over the list of archive files.
*/
virtual std::unique_ptr<ArchiveFileItor> getArchiveFileItor(const ArchiveFileSearchCriteria &searchCriteria,
......@@ -324,8 +331,9 @@ public:
virtual bool isAdmin(const common::dataStructures::SecurityIdentity &cliIdentity) const;
/**
* Returns the list of tapes that can be written to be a tape drive in the
* specified logical library.
* Returns the list of tapes that can be written to by a tape drive in the
* specified logical library, in other words tapes that are not disabled, not
* full and are in the specified logical library.
*
* @param logicalLibraryName The name of the logical library.
*/
......
......@@ -180,6 +180,5 @@ CREATE TABLE TAPE_FILE(
CONSTRAINT TAPE_FILE_ARCHIVE_FILE_FK FOREIGN KEY(ARCHIVE_FILE_ID)
REFERENCES ARCHIVE_FILE(ARCHIVE_FILE_ID),
CONSTRAINT TAPE_FILE_VID_BLOCK_ID_UN UNIQUE(VID, BLOCK_ID),
CONSTRAINT TAPE_FILE_VID_COPY_NB_UN UNIQUE(VID, COPY_NB),
CONSTRAINT TAPE_FILE_VID_ARCHIVE_FILE_UN UNIQUE(VID, ARCHIVE_FILE_ID)
CONSTRAINT TAPE_FILE_VID_ARCH_FILE_ID_UN UNIQUE(VID, ARCHIVE_FILE_ID)
);
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