DiskWriteTaskTest.cpp 2.17 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
#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"
11
12
#include "castor/tape/tapeserver/daemon/MigrationMemoryManager.hpp"
#include "castor/tape/tapeserver/daemon/MemBlock.hpp"
13
14
15
16
17
#include <gtest/gtest.h>

namespace unitTests{
  using namespace castor::tape::tapeserver::daemon;
  using namespace castor::tape::tapeserver::client;
18
  struct MockRecallReportPacker : public RecallReportPacker {
David COME's avatar
David COME committed
19
    MOCK_METHOD2(reportCompletedJob,void(const FileStruct&,unsigned long));
20
21
22
23
    MOCK_METHOD3(reportFailedJob, void(const FileStruct& ,const std::string&,int));
    MOCK_METHOD0(reportEndOfSession, void());
    MOCK_METHOD2(reportEndOfSessionWithErrors, void(const std::string,int));
    MockRecallReportPacker(ClientInterface& client,castor::log::LogContext lc):
24
     RecallReportPacker(client,1,lc){}
25
26
27
28
29
30
31
32
33
34
35
  };
  
  TEST(castor_tape_tapeserver_daemon, DiskWriteTaskFailledBlock){
    using ::testing::_;
    
    MockClient client;
    castor::log::StringLogger log("castor_tape_tapeserver_daemon_DiskWriteTaskFailledBlock");
    castor::log::LogContext lc(log);
    
    MockRecallReportPacker report(client,lc);
    EXPECT_CALL(report,reportFailedJob(_,_,_));
36
    RecallMemoryManager mm(10,100,lc);
37
38
39
40
41
42
43
44
45
        
    castor::tape::tapegateway::FileToRecallStruct file;
    file.setPath("/dev/null");
    file.setFileid(0);
    DiskWriteTask t(dynamic_cast<tapegateway::FileToRecallStruct*>(file.clone()),mm);
    for(int i=0;i<6;++i){
      MemBlock* mb=mm.getFreeBlock();
      mb->m_fileid=0;
      mb->m_fileBlock=i;
Eric Cano's avatar
Eric Cano committed
46
      mb->m_failed = (i==5) ? true : false;
47
48
49
50
51
52
53
54
55
56
      t.pushDataBlock(mb);
    }    
    MemBlock* mb=mm.getFreeBlock();

    t.pushDataBlock(mb);
    t.pushDataBlock(NULL);
    t.execute(report,lc);
  }
}