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