Commit 56a66b96 authored by Steven Murray's avatar Steven Murray
Browse files

Added unit-tests createArchiveRoute createArchiveRouteTapePool_same_twice

parent e2ba69f7
......@@ -109,6 +109,31 @@ void cta::catalogue::SqliteCatalogue::createDbSchema() {
"LAST_MOD_TIME INTEGER,"
"PRIMARY KEY(TAPE_POOL_NAME)"
");"
"CREATE TABLE ARCHIVE_ROUTE("
"STORAGE_CLASS_NAME TEXT,"
"COPY_NB INTEGER,"
"TAPE_POOL_NAME TEXT,"
"COMMENT TEXT,"
"CREATION_LOG_USER_NAME TEXT,"
"CREATION_LOG_GROUP_NAME TEXT,"
"CREATION_LOG_HOST_NAME TEXT,"
"CREATION_LOG_TIME INTEGER,"
"LAST_MOD_USER_NAME TEXT,"
"LAST_MOD_GROUP_NAME TEXT,"
"LAST_MOD_HOST_NAME TEXT,"
"LAST_MOD_TIME INTEGER,"
"PRIMARY KEY(STORAGE_CLASS_NAME, COPY_NB),"
"FOREIGN KEY(STORAGE_CLASS_NAME) REFERENCES "
"STORAGE_CLASS(STORAGE_CLASS_NAME),"
"FOREIGN KEY(TAPE_POOL_NAME) REFERENCES "
"TAPE_POOL(TAPE_POOL_NAME)"
");";
m_conn.enableForeignKeys();
m_conn.execNonQuery(sql);
......@@ -662,7 +687,61 @@ void cta::catalogue::SqliteCatalogue::setTapePoolEncryption(const cta::common::d
//------------------------------------------------------------------------------
// createArchiveRoute
//------------------------------------------------------------------------------
void cta::catalogue::SqliteCatalogue::createArchiveRoute(const common::dataStructures::SecurityIdentity &cliIdentity, const std::string &storageClassName, const uint64_t copyNb, const std::string &tapePoolName, const std::string &comment) {}
void cta::catalogue::SqliteCatalogue::createArchiveRoute(
const common::dataStructures::SecurityIdentity &cliIdentity,
const std::string &storageClassName,
const uint64_t copyNb,
const std::string &tapePoolName,
const std::string &comment) {
const time_t now = time(NULL);
const char *const sql =
"INSERT INTO ARCHIVE_ROUTE("
"STORAGE_CLASS_NAME,"
"COPY_NB,"
"TAPE_POOL_NAME,"
"COMMENT,"
"CREATION_LOG_USER_NAME,"
"CREATION_LOG_GROUP_NAME,"
"CREATION_LOG_HOST_NAME,"
"CREATION_LOG_TIME,"
"LAST_MOD_USER_NAME,"
"LAST_MOD_GROUP_NAME,"
"LAST_MOD_HOST_NAME,"
"LAST_MOD_TIME)"
"VALUES("
":STORAGE_CLASS_NAME,"
":COPY_NB,"
":TAPE_POOL_NAME,"
":COMMENT,"
":CREATION_LOG_USER_NAME,"
":CREATION_LOG_GROUP_NAME,"
":CREATION_LOG_HOST_NAME,"
":CREATION_LOG_TIME,"
":CREATION_LOG_USER_NAME,"
":CREATION_LOG_GROUP_NAME,"
":CREATION_LOG_HOST_NAME,"
":CREATION_LOG_TIME);";
SqliteStmt stmt(m_conn, sql);
stmt.bind(":STORAGE_CLASS_NAME", storageClassName);
stmt.bind(":COPY_NB", copyNb);
stmt.bind(":TAPE_POOL_NAME", tapePoolName);
stmt.bind(":COMMENT", comment);
stmt.bind(":CREATION_LOG_USER_NAME", cliIdentity.user.name);
stmt.bind(":CREATION_LOG_GROUP_NAME", cliIdentity.user.group);
stmt.bind(":CREATION_LOG_HOST_NAME", cliIdentity.host);
stmt.bind(":CREATION_LOG_TIME", now);
stmt.step();
}
//------------------------------------------------------------------------------
// deleteArchiveRoute
......@@ -672,7 +751,68 @@ void cta::catalogue::SqliteCatalogue::deleteArchiveRoute(const std::string &stor
//------------------------------------------------------------------------------
// getArchiveRoutes
//------------------------------------------------------------------------------
std::list<cta::common::dataStructures::ArchiveRoute> cta::catalogue::SqliteCatalogue::getArchiveRoutes() const { return std::list<cta::common::dataStructures::ArchiveRoute>();}
std::list<cta::common::dataStructures::ArchiveRoute>
cta::catalogue::SqliteCatalogue::getArchiveRoutes() const {
std::list<common::dataStructures::ArchiveRoute> routes;
const char *const sql =
"SELECT "
"STORAGE_CLASS_NAME AS STORAGE_CLASS_NAME,"
"COPY_NB AS COPY_NB,"
"TAPE_POOL_NAME AS TAPE_POOL_NAME,"
"COMMENT AS COMMENT,"
"CREATION_LOG_USER_NAME AS CREATION_LOG_USER_NAME,"
"CREATION_LOG_GROUP_NAME AS CREATION_LOG_GROUP_NAME,"
"CREATION_LOG_HOST_NAME AS CREATION_LOG_HOST_NAME,"
"CREATION_LOG_TIME AS CREATION_LOG_TIME,"
"LAST_MOD_USER_NAME AS LAST_MOD_USER_NAME,"
"LAST_MOD_GROUP_NAME AS LAST_MOD_GROUP_NAME,"
"LAST_MOD_HOST_NAME AS LAST_MOD_HOST_NAME,"
"LAST_MOD_TIME AS LAST_MOD_TIME "
"FROM ARCHIVE_ROUTE";
SqliteStmt stmt(m_conn, sql);
ColumnNameToIdx nameToIdx;
while(SQLITE_ROW == stmt.step()) {
if(nameToIdx.empty()) {
nameToIdx = stmt.getColumnNameToIdx();
}
common::dataStructures::ArchiveRoute route;
route.storageClassName = stmt.columnText(nameToIdx["STORAGE_CLASS_NAME"]);
route.copyNb = stmt.columnUint64(nameToIdx["COPY_NB"]);
route.tapePoolName = stmt.columnText(nameToIdx["TAPE_POOL_NAME"]);
route.comment = stmt.columnText(nameToIdx["COMMENT"]);
common::dataStructures::UserIdentity creatorUI;
creatorUI.name = stmt.columnText(nameToIdx["CREATION_LOG_USER_NAME"]);
creatorUI.group = stmt.columnText(nameToIdx["CREATION_LOG_GROUP_NAME"]);
common::dataStructures::EntryLog creationLog;
creationLog.user = creatorUI;
creationLog.host = stmt.columnText(nameToIdx["CREATION_LOG_HOST_NAME"]);
creationLog.time = stmt.columnUint64(nameToIdx["CREATION_LOG_TIME"]);
route.creationLog = creationLog;
common::dataStructures::UserIdentity updaterUI;
updaterUI.name = stmt.columnText(nameToIdx["LAST_MOD_USER_NAME"]);
updaterUI.group = stmt.columnText(nameToIdx["LAST_MOD_GROUP_NAME"]);
common::dataStructures::EntryLog updateLog;
updateLog.user = updaterUI;
updateLog.host = stmt.columnText(nameToIdx["LAST_MOD_HOST_NAME"]);
updateLog.time = stmt.columnUint64(nameToIdx["LAST_MOD_TIME"]);
route.lastModificationLog = updateLog;
routes.push_back(route);
}
return routes;
}
//------------------------------------------------------------------------------
// modifyArchiveRouteTapePoolName
......
......@@ -444,4 +444,71 @@ TEST_F(cta_catalogue_SqliteCatalogueTest, createTapePool_same_name_twice) {
exception::Exception);
}
TEST_F(cta_catalogue_SqliteCatalogueTest, createArchiveRoute) {
using namespace cta;
catalogue::SqliteCatalogue catalogue;
const std::string storageClassName = "storage_class";
const uint64_t nbCopies = 2;
ASSERT_NO_THROW(catalogue.createStorageClass(m_cliSI,
storageClassName, nbCopies, "create storage class"));
const std::string tapePoolName = "tape_pool";
const uint64_t nbPartialTapes = 2;
const bool is_encrypted = true;
ASSERT_NO_THROW(catalogue.createTapePool(m_cliSI,
tapePoolName, nbPartialTapes, is_encrypted, "create tape pool"));
const uint64_t copyNb = 1;
const std::string comment = "create archive route";
ASSERT_NO_THROW(catalogue.createArchiveRoute(m_cliSI,
storageClassName, copyNb, tapePoolName, comment));
const std::list<common::dataStructures::ArchiveRoute> routes =
catalogue.getArchiveRoutes();
ASSERT_EQ(1, routes.size());
const common::dataStructures::ArchiveRoute route = routes.front();
ASSERT_EQ(storageClassName, route.storageClassName);
ASSERT_EQ(copyNb, route.copyNb);
ASSERT_EQ(tapePoolName, route.tapePoolName);
ASSERT_EQ(comment, route.comment);
const common::dataStructures::EntryLog creationLog = route.creationLog;
ASSERT_EQ(m_cliSI.user.name, creationLog.user.name);
ASSERT_EQ(m_cliSI.user.group, creationLog.user.group);
ASSERT_EQ(m_cliSI.host, creationLog.host);
const common::dataStructures::EntryLog lastModificationLog =
route.lastModificationLog;
ASSERT_EQ(creationLog, lastModificationLog);
}
TEST_F(cta_catalogue_SqliteCatalogueTest, createArchiveRouteTapePool_same_twice) {
using namespace cta;
catalogue::SqliteCatalogue catalogue;
const std::string storageClassName = "storage_class";
const uint64_t nbCopies = 2;
ASSERT_NO_THROW(catalogue.createStorageClass(m_cliSI,
storageClassName, nbCopies, "create storage class"));
const std::string tapePoolName = "tape_pool";
const uint64_t nbPartialTapes = 2;
const bool is_encrypted = true;
ASSERT_NO_THROW(catalogue.createTapePool(m_cliSI,
tapePoolName, nbPartialTapes, is_encrypted, "create tape pool"));
const uint64_t copyNb = 1;
const std::string comment = "create archive route";
ASSERT_NO_THROW(catalogue.createArchiveRoute(m_cliSI,
storageClassName, copyNb, tapePoolName, comment));
ASSERT_THROW(catalogue.createArchiveRoute(m_cliSI,
storageClassName, copyNb, tapePoolName, comment),
exception::Exception);
}
} // namespace unitTests
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