Commit cc1bda8e authored by David COME's avatar David COME
Browse files

[WIP] Unit test for RecallTaskInjectorTest.cpp

We need to make sure the coverage of the UT is enough
parent 3d02cd63
......@@ -3,60 +3,154 @@
#include "castor/tape/tapeserver/daemon/ClientInterface.hpp"
#include "castor/tape/tapeserver/daemon/DiskThreadPoolInterface.hpp"
#include "castor/log/StringLogger.hpp"
using namespace castor::tape;
#include "castor/tape/tapeserver/drive/Drive.hpp"
namespace
{
using namespace castor::tape;
const int nbFile=5;
const int blockSize=4096;
class FakeClient : public tapeserver::daemon::ClientInterface
{
public:
FakeClient(int nbCalls):m_current(0){
for(int n=0;n<nbCalls;++n) {
std::auto_ptr<tapegateway::FilesToRecallList> ptr(new tapegateway::FilesToRecallList());
for(int i=0;i<nbFile;++i)
{
ptr->filesToRecall().push_back(new tapegateway::FileToRecallStruct);
ptr->filesToRecall().back()->setFileid(i);
ptr->filesToRecall().back()->setBlockId0(1*i);
ptr->filesToRecall().back()->setBlockId1(2*i);
ptr->filesToRecall().back()->setBlockId2(3*i);
ptr->filesToRecall().back()->setBlockId3(4*i);
ptr->filesToRecall().back()->setFseq(255+i);
ptr->filesToRecall().back()->setPath("rfio:///root/bidule");
ptr->filesToRecall().back()->setFileTransactionId(666+i);
ptr->filesToRecall().back()->setFilesToRecallList(ptr.get());
}
lists.push_back(ptr.release());
}
lists.push_back(NULL);
}
virtual tapegateway::FilesToRecallList * getFilesToRecall(uint64_t files,
uint64_t bytes, RequestReport &report)
throw (castor::tape::Exception)
{
std::auto_ptr<tapegateway::FilesToRecallList> ptr(new tapegateway::FilesToRecallList());
ptr->filesToRecall().push_back(new tapegateway::FileToRecallStruct);
ptr->filesToRecall().back()->setFileid(213);
ptr->filesToRecall().back()->setBlockId0(1);
ptr->filesToRecall().back()->setBlockId1(2);
ptr->filesToRecall().back()->setBlockId2(3);
ptr->filesToRecall().back()->setBlockId3(4);
ptr->filesToRecall().back()->setFseq(255);
ptr->filesToRecall().back()->setPath("rfio:///root/bidule");
ptr->filesToRecall().back()->setFileTransactionId(666);
ptr->filesToRecall().back()->setFilesToRecallList(ptr.get());
report.transactionId=666;
report.connectDuration=42;
report.sendRecvDuration=21;
return ptr.release();
return lists[m_current++];
}
private:
std::vector<tapegateway::FilesToRecallList*> lists;
int m_current;
};
class FakeDiskWriteThreadPool : public castor::tape::tapeserver::daemon::DiskThreadPoolInterface<DiskWriteTask>
class FakeDiskWriteThreadPool : public tapeserver::daemon::DiskThreadPoolInterface<DiskWriteTask>
{
virtual void push(DiskWriteTask* t){
public:
using tapeserver::daemon::DiskThreadPoolInterface<DiskWriteTask>::m_tasks;
virtual void finish()
{
m_tasks.push(new endOfSession);
}
virtual void push(DiskWriteTask* t){
m_tasks.push(t);
}
~FakeDiskWriteThreadPool(){
const unsigned int size= m_tasks.size();
for(unsigned int i=0;i<size;++i){
delete m_tasks.pop();
}
}
};
class FakeSingleTapeReadThread : public TapeSingleThreadInterface<TapeReadTask>
{
virtual void push(TapeReadTask* t){
public:
using TapeSingleThreadInterface<TapeReadTask>::m_tasks;
FakeSingleTapeReadThread(castor::tape::drives::DriveInterface& drive):
TapeSingleThreadInterface<TapeReadTask>(drive){}
~FakeSingleTapeReadThread(){
const unsigned int size= m_tasks.size();
for(unsigned int i=0;i<size;++i){
delete m_tasks.pop();
}
}
virtual void run ()
{
m_tasks.push(new endOfSession);
}
virtual void push(TapeReadTask* t){
m_tasks.push(t);
}
};
TEST(castor_tape_tapeserver_daemon, RecallTaskInjectorTest) {
TEST(castor_tape_tapeserver_daemon, RecallTaskInjectorNominal) {
MemoryManager mm(50U,50U);
const int nbCalls=2;
castor::log::StringLogger log("castor_tape_tapeserver_daemon_RecallTaskInjectorTest");
castor::log::LogContext lc(log);
castor::tape::drives::FakeDrive drive;
FakeClient client(nbCalls);
FakeDiskWriteThreadPool diskWrite;
FakeSingleTapeReadThread tapeRead(drive);
tapeserver::daemon::RecallTaskInjector rti(mm,tapeRead,diskWrite,client,lc);
ASSERT_EQ(true,rti.synchronousInjection(6,blockSize));
ASSERT_EQ(nbFile,diskWrite.m_tasks.size());
ASSERT_EQ(nbFile,tapeRead.m_tasks.size());
rti.startThreads();
rti.requestInjection(6,blockSize,false);
rti.requestInjection(6,blockSize,true);
rti.waitThreads();
//pushed nbFile*2 files + 1 end of Work task
ASSERT_EQ(nbFile*nbCalls+1,diskWrite.m_tasks.size());
ASSERT_EQ(nbFile*nbCalls+1,tapeRead.m_tasks.size());
for(int i=0;i<nbFile*nbCalls;++i)
{
delete diskWrite.m_tasks.pop();
delete tapeRead.m_tasks.pop();
}
for(int i=0;i<1;++i)
{
DiskWriteTask* diskWriteTask=diskWrite.m_tasks.pop();
TapeReadTask* tapeReadTask=tapeRead.m_tasks.pop();
ASSERT_EQ(diskWriteTask->endOfWork(),true);
ASSERT_EQ(tapeReadTask->endOfWork(),true);
delete diskWriteTask;
delete tapeReadTask;
}
}
TEST(castor_tape_tapeserver_daemon, RecallTaskInjectorNoFiles) {
MemoryManager mm(50U,50U);
castor::log::StringLogger log("castor_tape_tapeserver_daemon_RecallTaskInjectorTest");
castor::log::LogContext lc(log);
FakeClient client;
castor::tape::drives::FakeDrive drive;
FakeClient client(0);
FakeDiskWriteThreadPool diskWrite;
FakeSingleTapeReadThread tapeRead;
FakeSingleTapeReadThread tapeRead(drive);
tapeserver::daemon::RecallTaskInjector rti(mm,tapeRead,diskWrite,client,lc);
ASSERT_EQ(false,rti.synchronousInjection(6,blockSize));
ASSERT_EQ(0,diskWrite.m_tasks.size());
ASSERT_EQ(0,tapeRead.m_tasks.size());
}
}
\ No newline at end of file
......@@ -100,6 +100,7 @@ add_executable(castorUnitTests
../castor/tape/tapeserver/daemon/Vdqm.cpp
../castor/tape/tapeserver/daemon/VdqmAcceptHandler.cpp
../castor/tape/tapeserver/daemon/VdqmConnectionHandler.cpp
../castor/tape/tapeserver/daemon/RecallTaskInjectorTest.cpp
../castor/tape/tapeserver/drive/DriveTest.cpp
../castor/tape/tapeserver/exception/ExceptionTest.cpp
../castor/tape/tapeserver/file/StructuresTest.cpp
......
Markdown is supported
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