DiskWriteThreadPoolTest.cpp 2.46 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
#include "castor/tape/tapeserver/daemon/DiskWriteThreadPool.hpp"
#include "castor/tape/tapeserver/daemon/RecallTaskInjector.hpp"
#include "castor/tape/tapeserver/daemon/RecallReportPacker.hpp"
#include "castor/tape/tapegateway/FileToRecallStruct.hpp"
#include "castor/tape/tapeserver/daemon/ReportPackerInterface.hpp"
#include "castor/tape/tapeserver/client/ClientInterface.hpp"
#include "castor/tape/tapeserver/client/FakeClient.hpp"
#include "castor/tape/tapeserver/client/ClientInterface.hpp"
#include "castor/log/LogContext.hpp"
#include "castor/log/StringLogger.hpp"
#include "castor/tape/tapeserver/daemon/MemManager.hpp"
#include <gtest/gtest.h>

namespace unitTests{
15
16
17
  using namespace castor::tape::tapeserver::daemon;
  using namespace castor::tape::tapeserver::client;
  struct MockRecallReportPacker : public ReportPackerInterface<detail::Recall>{
David COME's avatar
David COME committed
18
    MOCK_METHOD2(reportCompletedJob,void(const FileStruct&,unsigned long));
19
20
21
    MOCK_METHOD3(reportFailedJob, void(const FileStruct& ,const std::string&,int));
    MOCK_METHOD0(reportEndOfSession, void());
    MOCK_METHOD2(reportEndOfSessionWithErrors, void(const std::string,int));
22
23
    MockRecallReportPacker(ClientInterface& client,castor::log::LogContext lc):
      ReportPackerInterface<detail::Recall>(client,lc){}
24
25
  };
  
26
  struct MockTaskInjector : public TaskInjector{
27
28
29
30
31
32
33
34
35
36
    MOCK_METHOD3(requestInjection, void(int maxFiles, int maxBlocks, bool lastCall));
  };
  
  TEST(castor_tape_tapeserver_daemon, DiskWriteThreadPoolTest){
    using ::testing::_;
    MockClient client;
    castor::log::StringLogger log("castor_tape_tapeserver_daemon_DiskWriteThreadPoolTest");
    castor::log::LogContext lc(log);
    
    MockRecallReportPacker report(client,lc);
David COME's avatar
David COME committed
37
    EXPECT_CALL(report,reportCompletedJob(_,_)).Times(5);
38
39
40
    //EXPECT_CALL(tskInjectorl,requestInjection(_,_,_)).Times(2);
    EXPECT_CALL(report,reportEndOfSession()).Times(1);     
    
41
    RecallMemoryManager mm(10,100);
42
    
43
    DiskWriteThreadPool dwtp(2,5,500,report,lc);
44
45
    dwtp.startThreads();
    
46
    castor::tape::tapegateway::FileToRecallStruct file;
47
48
49
50
    file.setPath("/dev/null");
    file.setBlockId3(1);
       
     for(int i=0;i<5;++i){
51
52
       DiskWriteTask* t=new DiskWriteTask(dynamic_cast<tapegateway::FileToRecallStruct*>(file.clone()),mm);
       MemBlock* mb=mm.getFreeBlock();
53
54
55
56
57
58
59
60
61
62
63
64
       mb->m_fileid=0;
       mb->m_fileBlock=0;
       t->pushDataBlock(mb);
       t->pushDataBlock(NULL);
       dwtp.push(t);
     }
     
    dwtp.finish();
    dwtp.waitThreads(); 
  }
}