RecallTaskInjectorTest.cpp 5.54 KB
Newer Older
1
2
3
#include "castor/tape/tapeserver/daemon/RecallTaskInjector.hpp"
#include "castor/tape/tapeserver/daemon/TapeReadSingleThread.hpp"
#include "castor/log/StringLogger.hpp"
4
#include "castor/tape/tapeserver/drive/Drive.hpp"
5
#include <gtest/gtest.h>
6
#include "castor/tape/tapeserver/client/FakeClient.hpp"
7
#include "castor/tape/tapeserver/daemon/DiskWriteThreadPool.hpp"
8
9
#include "castor/legacymsg/RmcProxy.hpp"
#include "castor/legacymsg/RmcProxyDummy.hpp"
10
11
12
13
#include "castor/tape/tapeserver/daemon/GlobalStatusReporter.hpp"
#include "castor/legacymsg/VmgrProxyDummy.hpp"
#include "castor/legacymsg/VdqmProxyDummy.hpp"
#include "castor/legacymsg/TapeserverProxyDummy.hpp"
14
#include "castor/tape/utils/TpconfigLine.hpp"
15
#include "castor/tape/tapeserver/client/ClientInterface.hpp"
16
#include "castor/utils/utils.hpp"
17
#include "castor/tape/tapeserver/daemon/CapabilityUtilsDummy.hpp"
18
namespace unitTests
19
{
David COME's avatar
David COME committed
20
using namespace castor::tape::tapeserver::daemon;
21
22
23
using namespace castor::tape;
const int blockSize=4096;

24
class FakeDiskWriteThreadPool: public DiskWriteThreadPool
25
{
26
public:
27
28
  using DiskWriteThreadPool::m_tasks;
  FakeDiskWriteThreadPool(castor::log::LogContext & lc):
29
    DiskWriteThreadPool(1,*((RecallReportPacker*)NULL), lc){}
30
  virtual ~FakeDiskWriteThreadPool() {};
31
32
};
     
33
class FakeSingleTapeReadThread : public TapeSingleThreadInterface<TapeReadTask>
34
{
35
public:
36
  using TapeSingleThreadInterface<TapeReadTask>::m_tasks;
37
  
38
39
  FakeSingleTapeReadThread(castor::tape::drives::DriveInterface& drive,
    castor::legacymsg::RmcProxy & rmc,
40
    castor::tape::tapeserver::daemon::GlobalStatusReporter & gsr,
41
42
43
44
    const castor::tape::tapeserver::client::ClientInterface::VolumeInfo& volInfo, 
     castor::tape::tapeserver::daemon::CapabilityUtils& cap,
    castor::log::LogContext & lc):
  TapeSingleThreadInterface<TapeReadTask>(drive, rmc, gsr, volInfo,cap, lc){}
45
  
46
47
48
49
50
51
52
53
  ~FakeSingleTapeReadThread(){
    const unsigned int size= m_tasks.size();
    for(unsigned int i=0;i<size;++i){
      delete m_tasks.pop();
    }
  }
   virtual void run () 
  {
54
     m_tasks.push(NULL);
55
  }
56
  virtual void push(TapeReadTask* t){
57
    m_tasks.push(t);
58
59
60
  }
};

61
62
63
64
TEST(castor_tape_tapeserver_daemon, RecallTaskInjectorNominal) {
  const int nbCalls=2;
  castor::log::StringLogger log("castor_tape_tapeserver_daemon_RecallTaskInjectorTest");
  castor::log::LogContext lc(log);
65
  RecallMemoryManager mm(50U,50U,lc);
66
67
  castor::tape::drives::FakeDrive drive;
  FakeClient client(nbCalls);
68
  FakeDiskWriteThreadPool diskWrite(lc);
69
  castor::legacymsg::RmcProxyDummy rmc;
70
71
72
  castor::legacymsg::VmgrProxyDummy vmgr;
  castor::legacymsg::VdqmProxyDummy vdqm;
  castor::legacymsg::TapeserverProxyDummy initialProcess;
73
74
75
76
77
78
  castor::tape::tapeserver::client::ClientInterface::VolumeInfo volume;
  volume.clientType=castor::tape::tapegateway::READ_TP;
  volume.density="8000GC";
  volume.labelObsolete="AUL";
  volume.vid="V12345";
  volume.volumeMode=castor::tape::tapegateway::READ;
79
  castor::tape::tapeserver::daemon::GlobalStatusReporter gsr(initialProcess,
80
  utils::TpconfigLine("","","","","",""),"0.0.0.0",volume,lc);
81
82
  castor::tape::tapeserver::daemon::CapabilityUtilsDummy cap;
  FakeSingleTapeReadThread tapeRead(drive, rmc, gsr, volume, cap,lc);
83

84
  tapeserver::daemon::RecallReportPacker rrp(client,2,lc);
85
  tapeserver::daemon::RecallTaskInjector rti(mm,tapeRead,diskWrite,client,6,blockSize,lc);
86
  
87
  ASSERT_EQ(true,rti.synchronousInjection());
88
89
90
91
  ASSERT_EQ(nbFile,diskWrite.m_tasks.size());
  ASSERT_EQ(nbFile,tapeRead.m_tasks.size());
  
  rti.startThreads();
92
93
  rti.requestInjection(false);
  rti.requestInjection(true);
94
  rti.finish();
95
96
  rti.waitThreads();
  
97
  //pushed nbFile*2 files + 1 end of work
98
99
100
  ASSERT_EQ(nbFile*nbCalls+1,diskWrite.m_tasks.size());
  ASSERT_EQ(nbFile*nbCalls+1,tapeRead.m_tasks.size());
  
101
  for(unsigned int i=0;i<nbFile*nbCalls;++i)
102
103
104
105
106
107
108
  {
    delete diskWrite.m_tasks.pop();
    delete tapeRead.m_tasks.pop();
  }
  
  for(int i=0;i<1;++i)
  {
109
    DiskWriteTask* diskWriteTask=diskWrite.m_tasks.pop();
110
    TapeReadTask* tapeReadTask=tapeRead.m_tasks.pop();
111
    
112
    //static_cast is needed otherwise compilation fails on SL5 with a raw NULL
113
    ASSERT_EQ(static_cast<DiskWriteTask*>(NULL),diskWriteTask);
114
    ASSERT_EQ(static_cast<TapeReadTask*>(NULL),tapeReadTask);
115
116
117
118
119
    delete diskWriteTask;
    delete tapeReadTask;
  }
}
TEST(castor_tape_tapeserver_daemon, RecallTaskInjectorNoFiles) {
120
121
  castor::log::StringLogger log("castor_tape_tapeserver_daemon_RecallTaskInjectorTest");
  castor::log::LogContext lc(log);
122
  RecallMemoryManager mm(50U,50U,lc);
123
124
  castor::tape::drives::FakeDrive drive;
  FakeClient client(0);
125
  FakeDiskWriteThreadPool diskWrite(lc);
126
  castor::legacymsg::RmcProxyDummy rmc;
127
128
  castor::legacymsg::VmgrProxyDummy vmgr;
  castor::legacymsg::VdqmProxyDummy vdqm;
129
130
131
132
133
134
135
  castor::legacymsg::TapeserverProxyDummy initialProcess;  
  castor::tape::tapeserver::client::ClientInterface::VolumeInfo volume;
  volume.clientType=castor::tape::tapegateway::READ_TP;
  volume.density="8000GC";
  volume.labelObsolete="AUL";
  volume.vid="V12345";
  volume.volumeMode=castor::tape::tapegateway::READ;
136
  castor::tape::tapeserver::daemon::CapabilityUtilsDummy cap;
137
  castor::tape::tapeserver::daemon::GlobalStatusReporter gsr(initialProcess,  
138
  utils::TpconfigLine("","","","","",""),"0.0.0.0",volume,lc);  
139
  FakeSingleTapeReadThread tapeRead(drive, rmc, gsr, volume,cap, lc);
140
141
  
  tapeserver::daemon::RecallReportPacker rrp(client,2,lc);
142
  tapeserver::daemon::RecallTaskInjector rti(mm,tapeRead,diskWrite,client,6,blockSize,lc);
143
  
144
  ASSERT_EQ(false,rti.synchronousInjection());
145
146
147
  ASSERT_EQ(0U,diskWrite.m_tasks.size());
  ASSERT_EQ(0U,tapeRead.m_tasks.size());
}
148
}