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

Improved catalogue::getTapes() unittest

parent e04c8a2a
......@@ -1011,6 +1011,133 @@ TEST_F(cta_catalogue_InMemoryCatalogueTest, createTape_same_twice) {
comment), catalogue::UserError);
}
TEST_F(cta_catalogue_InMemoryCatalogueTest, createTape_many_tapes) {
using namespace cta;
const std::string logicalLibrary = "logical_library_name";
const std::string tapePool = "tape_pool_name";
const std::string encryptionKey = "encryption_key";
const uint64_t capacityInBytes = (uint64_t) 10 * 1000 * 1000 * 1000 * 1000;
const bool disabled = true;
const bool full = false;
const std::string comment = "create tape";
ASSERT_TRUE(m_catalogue->getLogicalLibraries().empty());
m_catalogue->createLogicalLibrary(m_cliSI, logicalLibrary, "create logical library");
ASSERT_TRUE(m_catalogue->getTapePools().empty());
m_catalogue->createTapePool(m_cliSI, tapePool, 2, true, "create tape pool");
ASSERT_TRUE(m_catalogue->getTapes().empty());
const uint64_t nbTapes = 10;
for(uint64_t i = 1; i <= nbTapes; i++) {
std::ostringstream vid;
vid << "vid" << i;
m_catalogue->createTape(m_cliSI, vid.str(), logicalLibrary, tapePool, encryptionKey, capacityInBytes, disabled,
full, comment);
}
const std::list<common::dataStructures::Tape> tapes = m_catalogue->getTapes();
ASSERT_EQ(nbTapes, tapes.size());
const std::map<std::string, common::dataStructures::Tape> vidToTape = tapeListToMap(tapes);
ASSERT_EQ(nbTapes, vidToTape.size());
for(uint64_t i = 1; i <= nbTapes; i++) {
std::ostringstream vid;
vid << "vid" << i;
auto vidAndTapeItor = vidToTape.find(vid.str());
ASSERT_FALSE(vidToTape.end() == vidAndTapeItor);
const common::dataStructures::Tape tape = vidAndTapeItor->second;
ASSERT_EQ(vid.str(), tape.vid);
ASSERT_EQ(logicalLibrary, tape.logicalLibraryName);
ASSERT_EQ(tapePool, tape.tapePoolName);
ASSERT_EQ(encryptionKey, tape.encryptionKey);
ASSERT_EQ(capacityInBytes, tape.capacityInBytes);
ASSERT_TRUE(disabled == tape.disabled);
ASSERT_TRUE(full == 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);
}
{
catalogue::TapeSearchCriteria searchCriteria;
searchCriteria.vid = "vid1";
const std::list<common::dataStructures::Tape> tapes = m_catalogue->getTapes(searchCriteria);
ASSERT_EQ(1, tapes.size());
const std::map<std::string, common::dataStructures::Tape> vidToTape = tapeListToMap(tapes);
ASSERT_EQ(1, vidToTape.size());
ASSERT_EQ("vid1", vidToTape.begin()->first);
ASSERT_EQ("vid1", vidToTape.begin()->second.vid);
}
{
catalogue::TapeSearchCriteria searchCriteria;
searchCriteria.logicalLibrary = logicalLibrary;
const std::list<common::dataStructures::Tape> tapes = m_catalogue->getTapes(searchCriteria);
ASSERT_EQ(nbTapes, tapes.size());
const std::map<std::string, common::dataStructures::Tape> vidToTape = tapeListToMap(tapes);
ASSERT_EQ(nbTapes, vidToTape.size());
ASSERT_EQ(logicalLibrary, vidToTape.begin()->second.logicalLibraryName);
}
{
catalogue::TapeSearchCriteria searchCriteria;
searchCriteria.tapePool = tapePool;
const std::list<common::dataStructures::Tape> tapes = m_catalogue->getTapes(searchCriteria);
ASSERT_EQ(nbTapes, tapes.size());
const std::map<std::string, common::dataStructures::Tape> vidToTape = tapeListToMap(tapes);
ASSERT_EQ(nbTapes, vidToTape.size());
ASSERT_EQ(tapePool, vidToTape.begin()->second.tapePoolName);
}
{
catalogue::TapeSearchCriteria searchCriteria;
searchCriteria.capacityInBytes = "10000000000000";
const std::list<common::dataStructures::Tape> tapes = m_catalogue->getTapes(searchCriteria);
ASSERT_EQ(nbTapes, tapes.size());
const std::map<std::string, common::dataStructures::Tape> vidToTape = tapeListToMap(tapes);
ASSERT_EQ(nbTapes, vidToTape.size());
ASSERT_EQ(capacityInBytes, vidToTape.begin()->second.capacityInBytes);
}
{
catalogue::TapeSearchCriteria searchCriteria;
searchCriteria.disabled = "true";
const std::list<common::dataStructures::Tape> tapes = m_catalogue->getTapes(searchCriteria);
ASSERT_EQ(nbTapes, tapes.size());
const std::map<std::string, common::dataStructures::Tape> vidToTape = tapeListToMap(tapes);
ASSERT_EQ(nbTapes, vidToTape.size());
ASSERT_TRUE(vidToTape.begin()->second.disabled);
}
{
catalogue::TapeSearchCriteria searchCriteria;
searchCriteria.full = "false";
const std::list<common::dataStructures::Tape> tapes = m_catalogue->getTapes(searchCriteria);
ASSERT_EQ(nbTapes, tapes.size());
const std::map<std::string, common::dataStructures::Tape> vidToTape = tapeListToMap(tapes);
ASSERT_EQ(nbTapes, vidToTape.size());
ASSERT_FALSE(vidToTape.begin()->second.full);
}
{
catalogue::TapeSearchCriteria searchCriteria;
searchCriteria.vid = "non_existant_vid";
const std::list<common::dataStructures::Tape> tapes = m_catalogue->getTapes(searchCriteria);
ASSERT_TRUE(tapes.empty());
}
}
TEST_F(cta_catalogue_InMemoryCatalogueTest, deleteTape) {
using namespace cta;
......
......@@ -1266,9 +1266,9 @@ std::list<common::dataStructures::Tape> RdbmsCatalogue::getTapes(const TapeSearc
searchCriteria.logicalLibrary.empty() &&
searchCriteria.tapePool.empty() &&
searchCriteria.capacityInBytes.empty() &&
searchCriteria.isDisabled.empty() &&
searchCriteria.isFull.empty() &&
searchCriteria.lbpIsOn.empty())) {
searchCriteria.disabled.empty() &&
searchCriteria.full.empty() &&
searchCriteria.lbp.empty())) {
sql += " WHERE ";
}
......@@ -1295,21 +1295,21 @@ std::list<common::dataStructures::Tape> RdbmsCatalogue::getTapes(const TapeSearc
if(addedAWhereConstraint) sql += " AND ";
sql += " CAPACITY_IN_BYTES = :CAPACITY_IN_BYTES";
}
if(!searchCriteria.isDisabled.empty()) {
if(!isValidBool(searchCriteria.isDisabled)) {
throw UserError("Disabled tapes search criterion " + searchCriteria.isDisabled + " is not a valid boolean");
if(!searchCriteria.disabled.empty()) {
if(!isValidBool(searchCriteria.disabled)) {
throw UserError("Disabled tapes search criterion " + searchCriteria.disabled + " is not a valid boolean");
}
sql += " IS_DISABLED = :IS_DISABLED";
}
if(!searchCriteria.isFull.empty()) {
if(!isValidBool(searchCriteria.isFull)) {
throw UserError("Full tapes search criterion " + searchCriteria.isFull + " is not a valid boolean");
if(!searchCriteria.full.empty()) {
if(!isValidBool(searchCriteria.full)) {
throw UserError("Full tapes search criterion " + searchCriteria.full + " is not a valid boolean");
}
sql += " IS_FULL = :IS_FULL";
}
if(!searchCriteria.lbpIsOn.empty()) {
if(!isValidBool(searchCriteria.lbpIsOn)) {
throw UserError("LBP search criterion " + searchCriteria.lbpIsOn + " is not a valid boolean");
if(!searchCriteria.lbp.empty()) {
if(!isValidBool(searchCriteria.lbp)) {
throw UserError("LBP search criterion " + searchCriteria.lbp + " is not a valid boolean");
}
sql += " LBP_IS_ON = :LBP_IS_ON";
}
......@@ -1321,10 +1321,9 @@ std::list<common::dataStructures::Tape> RdbmsCatalogue::getTapes(const TapeSearc
if(!searchCriteria.tapePool.empty()) stmt->bindString(":TAPE_POOL_NAME", searchCriteria.tapePool);
if(!searchCriteria.capacityInBytes.empty()) stmt->bindUint64(":CAPACITY_IN_BYTES",
utils::toUint64(searchCriteria.capacityInBytes));
if(!searchCriteria.isDisabled.empty()) stmt->bindUint64(":IS_DISABLED",
toUpper(searchCriteria.isDisabled) == "TRUE");
if(!searchCriteria.isFull.empty()) stmt->bindUint64(":IS_FULL", toUpper(searchCriteria.isFull) == "TRUE");
if(!searchCriteria.lbpIsOn.empty()) stmt->bindUint64(":LBP_IS_ON", toUpper(searchCriteria.lbpIsOn) == "TRUE");
if(!searchCriteria.disabled.empty()) stmt->bindUint64(":IS_DISABLED", toUpper(searchCriteria.disabled) == "TRUE");
if(!searchCriteria.full.empty()) stmt->bindUint64(":IS_FULL", toUpper(searchCriteria.full) == "TRUE");
if(!searchCriteria.lbp.empty()) stmt->bindUint64(":LBP_IS_ON", toUpper(searchCriteria.lbp) == "TRUE");
std::unique_ptr<DbRset> rset(stmt->executeQuery());
while (rset->next()) {
......
......@@ -57,17 +57,17 @@ struct TapeSearchCriteria {
/**
* Set to true if searching for disabled tapes.
*/
std::string isDisabled;
std::string disabled;
/**
* Set to true if searching for full tapes.
*/
std::string isFull;
std::string full;
/**
* Set to true if searching for tapes with logical block protection enabled.
*/
std::string lbpIsOn;
std::string lbp;
}; // struct TapeSearchCriteria
......
......@@ -880,22 +880,22 @@ int XrdCtaFile::xCom_tape() {
}
cta::catalogue::TapeSearchCriteria searchCriteria;
if(hasOption("-e", "--enabled")) {
searchCriteria.isDisabled = "false";
searchCriteria.disabled = "false";
}
if(hasOption("-d", "--disabled")) {
searchCriteria.isDisabled = "true";
searchCriteria.disabled = "true";
}
if(hasOption("-f", "--free")) {
searchCriteria.isFull = "false";
searchCriteria.full = "false";
}
if(hasOption("-F", "--full")) {
searchCriteria.isFull = "true";
searchCriteria.full = "true";
}
if(hasOption("-p", "--lbp")) {
searchCriteria.lbpIsOn = "true";
searchCriteria.lbp = "true";
}
if(hasOption("-P", "--nolbp")) {
searchCriteria.lbpIsOn = "false";
searchCriteria.lbp = "false";
}
std::list<cta::common::dataStructures::Tape> list= m_catalogue->getTapes(searchCriteria);
if(list.size()>0) {
......
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