Commit eabec107 authored by Eric Cano's avatar Eric Cano
Browse files

Created basic unit test for objectstore::ArchiveToFileRequest

parent 4bb73f9a
......@@ -57,23 +57,42 @@ void cta::objectstore::ArchiveToFileRequest::setArchiveFile(
m_payload.set_archivefile(archiveFile);
}
std::string cta::objectstore::ArchiveToFileRequest::getArchiveFile() {
checkPayloadReadable();
return m_payload.archivefile();
}
void cta::objectstore::ArchiveToFileRequest::setRemoteFile(
const std::string& remoteFile) {
checkHeaderReadable();
checkPayloadWritable();
m_payload.set_remotefile(remoteFile);
}
std::string cta::objectstore::ArchiveToFileRequest::getRemoteFile() {
checkPayloadReadable();
return m_payload.remotefile();
}
void cta::objectstore::ArchiveToFileRequest::setPriority(uint64_t priority) {
checkPayloadWritable();
m_payload.set_priority(priority);
}
void cta::objectstore::ArchiveToFileRequest::setLog(
void cta::objectstore::ArchiveToFileRequest::setCreationLog(
const objectstore::CreationLog& creationLog) {
checkPayloadReadable();
checkPayloadWritable();
creationLog.serialize(*m_payload.mutable_log());
}
auto cta::objectstore::ArchiveToFileRequest::getCreationLog() -> CreationLog {
checkPayloadReadable();
CreationLog ret;
ret.deserialize(m_payload.log());
return ret;
}
void cta::objectstore::ArchiveToFileRequest::setArchiveToDirRequestAddress(
const std::string& dirRequestAddress) {
checkPayloadWritable();
......@@ -94,7 +113,7 @@ auto cta::objectstore::ArchiveToFileRequest::dumpJobs() -> std::list<JobDump> {
}
uint64_t cta::objectstore::ArchiveToFileRequest::getSize() {
checkPayloadWritable();
checkPayloadReadable();
return m_payload.size();
}
......@@ -104,4 +123,3 @@ void cta::objectstore::ArchiveToFileRequest::setSize(uint64_t size) {
}
......@@ -41,7 +41,8 @@ public:
void setRemoteFile (const std::string & remoteFile);
std::string getRemoteFile();
void setPriority (uint64_t priority);
void setLog (const objectstore::CreationLog& creationLog);
void setCreationLog (const objectstore::CreationLog& creationLog);
CreationLog getCreationLog();
void setArchiveToDirRequestAddress(const std::string & dirRequestAddress);
void setSize(uint64_t size);
uint64_t getSize();
......
......@@ -20,6 +20,8 @@
#include "ArchiveToFileRequest.hpp"
#include "BackendVFS.hpp"
#include "Agent.hpp"
#include "CreationLog.hpp"
#include "UserIdentity.hpp"
namespace unitTests {
......@@ -27,6 +29,7 @@ TEST(ObjectStore, ArchiveToFileRequestBasicAccess) {
cta::objectstore::BackendVFS be;
cta::objectstore::Agent agent(be);
agent.generateName("unitTest");
time_t now;
std::string tapeAddress = agent.nextId("ArchiveToFileRequest");
{
// Try to create the ArchiveToFileRequest entry
......@@ -35,8 +38,8 @@ TEST(ObjectStore, ArchiveToFileRequestBasicAccess) {
atfr.setArchiveFile("cta://dir/file");
atfr.setRemoteFile("eos://dir2/file2");
atfr.setSize(12345678);
atfr.setLog(cta::CreationLog(cta::UserIdentity(123,456),"testHost",
time(NULL), "Comment"));
atfr.setCreationLog(cta::CreationLog(cta::UserIdentity(123,456),"testHost",
now=time(NULL), "Comment"));
atfr.setPriority(12);
atfr.insert();
}
......@@ -45,7 +48,15 @@ TEST(ObjectStore, ArchiveToFileRequestBasicAccess) {
cta::objectstore::ArchiveToFileRequest atfr(tapeAddress, be);
cta::objectstore::ScopedSharedLock atfrl(atfr);
atfr.fetch();
ASSERT_EQ("cta://dir/file", atfr.getARchiveFile());
ASSERT_EQ("cta://dir/file", atfr.getArchiveFile());
ASSERT_EQ("eos://dir2/file2", atfr.getRemoteFile());
ASSERT_EQ(12345678, atfr.getSize());
cta::objectstore::CreationLog log(atfr.getCreationLog());
ASSERT_EQ(123, log.user.uid);
ASSERT_EQ(456, log.user.gid);
ASSERT_EQ("testHost", log.host);
ASSERT_EQ(now, log.time);
ASSERT_EQ("Comment", log.comment);
}
}
......
......@@ -34,6 +34,7 @@ set(ObjectStoreUnitTests
RootEntryTest.cpp
TapeTest.cpp
GarbageCollectorTest.cpp
ArchiveToFileRequestTest.cpp
)
add_library(ctaobjectstoreunittests SHARED ${ObjectStoreUnitTests})
......
......@@ -409,7 +409,7 @@ void OStoreDB::queue(const cta::ArchiveToFileRequest& rqst) {
atfr.setArchiveFile(rqst.getArchiveFile());
atfr.setRemoteFile(rqst.getRemoteFile());
atfr.setPriority(rqst.getPriority());
atfr.setLog(rqst.getCreationLog());
atfr.setCreationLog(rqst.getCreationLog());
// We will need to identity tapepools is order to construct the request
RootEntry re(m_objectStore);
ScopedSharedLock rel(re);
......
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