RecallTaskInjectorTest.cpp 6.48 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
/****************************************************************************** 
 *
 * This file is part of the Castor project.
 * See http://castor.web.cern.ch/castor
 *
 * Copyright (C) 2003  CERN
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 *
 * 
 *
 * @author Castor Dev team, castor-dev@cern.ch
 *****************************************************************************/
23
24

#include "castor/legacymsg/RmcProxyDummy.hpp"
25
#include "castor/log/StringLogger.hpp"
26
27
28
#include "castor/mediachanger/MediaChangerFacade.hpp"
#include "castor/mediachanger/MmcProxyDummy.hpp"
#include "castor/messages/AcsProxyDummy.hpp"
29
#include "castor/messages/TapeserverProxyDummy.hpp"
30
#include "castor/server/ProcessCapDummy.hpp"
31
32
33
34
#include "castor/tape/tapeserver/daemon/DiskWriteThreadPool.hpp"
#include "castor/tape/tapeserver/daemon/RecallTaskInjector.hpp"
#include "castor/tape/tapeserver/daemon/TapeServerReporter.hpp"
#include "castor/tape/tapeserver/daemon/TapeReadSingleThread.hpp"
35
#include "castor/tape/tapeserver/daemon/TpconfigLine.hpp"
36
#include "castor/tape/tapeserver/drive/FakeDrive.hpp"
37
#include "castor/utils/utils.hpp"
38
39
40

#include <gtest/gtest.h>

41
namespace unitTests
42
{
David COME's avatar
David COME committed
43
using namespace castor::tape::tapeserver::daemon;
44
45
46
using namespace castor::tape;
const int blockSize=4096;

47
class FakeDiskWriteThreadPool: public DiskWriteThreadPool
48
{
49
public:
50
51
  using DiskWriteThreadPool::m_tasks;
  FakeDiskWriteThreadPool(castor::log::LogContext & lc):
52
    DiskWriteThreadPool(1,*((RecallReportPacker*)NULL),
53
    *((RecallWatchDog*)NULL),lc, "RFIO","/dev/null",0){}
54
  virtual ~FakeDiskWriteThreadPool() {};
55
56
};
     
57
class FakeSingleTapeReadThread : public TapeSingleThreadInterface<TapeReadTask>
58
{
59
public:
60
  using TapeSingleThreadInterface<TapeReadTask>::m_tasks;
61
  
62
  FakeSingleTapeReadThread(castor::tape::tapeserver::drive::DriveInterface& drive,
63
    castor::mediachanger::MediaChangerFacade & mc,
64
    castor::tape::tapeserver::daemon::TapeServerReporter & tsr,
65
    const castor::tape::tapeserver::client::ClientInterface::VolumeInfo& volInfo, 
66
     castor::server::ProcessCap& cap,
67
    castor::log::LogContext & lc):
68
  TapeSingleThreadInterface<TapeReadTask>(drive, mc, tsr, volInfo,cap, lc){}
69
  
70
71
72
73
74
75
76
77
  ~FakeSingleTapeReadThread(){
    const unsigned int size= m_tasks.size();
    for(unsigned int i=0;i<size;++i){
      delete m_tasks.pop();
    }
  }
   virtual void run () 
  {
78
     m_tasks.push(NULL);
79
  }
80
  virtual void push(TapeReadTask* t){
81
    m_tasks.push(t);
82
  }
83
84
  
  virtual void countTapeLogError(const std::string & error) {};
85
86
};

87
88
89
90
TEST(castor_tape_tapeserver_daemon, RecallTaskInjectorNominal) {
  const int nbCalls=2;
  castor::log::StringLogger log("castor_tape_tapeserver_daemon_RecallTaskInjectorTest");
  castor::log::LogContext lc(log);
91
  RecallMemoryManager mm(50U,50U,lc);
92
  castor::tape::tapeserver::drive::FakeDrive drive;
93
  FakeClient client(nbCalls);
94
  FakeDiskWriteThreadPool diskWrite(lc);
95
96
97
98
  castor::messages::AcsProxyDummy acs;
  castor::mediachanger::MmcProxyDummy mmc;
  castor::legacymsg::RmcProxyDummy rmc;
  castor::mediachanger::MediaChangerFacade mc(acs, mmc, rmc);
99
  castor::messages::TapeserverProxyDummy initialProcess;
100
101
102
103
  castor::tape::tapeserver::client::ClientInterface::VolumeInfo volume;
  volume.density="8000GC";
  volume.labelObsolete="AUL";
  volume.vid="V12345";
104
  volume.mountType=cta::MountType::RETRIEVE;
David COME's avatar
David COME committed
105
  castor::tape::tapeserver::daemon::TapeServerReporter gsr(initialProcess,
106
    DriveConfig(),"0.0.0.0",volume,lc);
107
  castor::server::ProcessCapDummy cap;
108
  FakeSingleTapeReadThread tapeRead(drive, mc, gsr, volume, cap,lc);
109

110
  //tapeserver::daemon::RecallReportPacker rrp(client,2,lc);
111
  tapeserver::daemon::RecallTaskInjector rti(mm,tapeRead,diskWrite,client,6,blockSize,lc);
112
  
113
  ASSERT_EQ(true,rti.synchronousInjection());
114
115
116
117
  ASSERT_EQ(nbFile,diskWrite.m_tasks.size());
  ASSERT_EQ(nbFile,tapeRead.m_tasks.size());
  
  rti.startThreads();
118
119
  rti.requestInjection(false);
  rti.requestInjection(true);
120
  rti.finish();
121
122
  rti.waitThreads();
  
123
  //pushed nbFile*2 files + 1 end of work
124
125
126
  ASSERT_EQ(nbFile*nbCalls+1,diskWrite.m_tasks.size());
  ASSERT_EQ(nbFile*nbCalls+1,tapeRead.m_tasks.size());
  
127
  for(unsigned int i=0;i<nbFile*nbCalls;++i)
128
129
130
131
132
133
134
  {
    delete diskWrite.m_tasks.pop();
    delete tapeRead.m_tasks.pop();
  }
  
  for(int i=0;i<1;++i)
  {
135
    DiskWriteTask* diskWriteTask=diskWrite.m_tasks.pop();
136
    TapeReadTask* tapeReadTask=tapeRead.m_tasks.pop();
137
    
138
    //static_cast is needed otherwise compilation fails on SL5 with a raw NULL
139
    ASSERT_EQ(static_cast<DiskWriteTask*>(NULL),diskWriteTask);
140
    ASSERT_EQ(static_cast<TapeReadTask*>(NULL),tapeReadTask);
141
142
143
144
145
    delete diskWriteTask;
    delete tapeReadTask;
  }
}
TEST(castor_tape_tapeserver_daemon, RecallTaskInjectorNoFiles) {
146
147
  castor::log::StringLogger log("castor_tape_tapeserver_daemon_RecallTaskInjectorTest");
  castor::log::LogContext lc(log);
148
  RecallMemoryManager mm(50U,50U,lc);
149
  castor::tape::tapeserver::drive::FakeDrive drive;
150
  FakeClient client(0);
151
  FakeDiskWriteThreadPool diskWrite(lc);
152
153
154
155
  castor::messages::AcsProxyDummy acs;
  castor::mediachanger::MmcProxyDummy mmc;
  castor::legacymsg::RmcProxyDummy rmc;
  castor::mediachanger::MediaChangerFacade mc(acs, mmc, rmc);
156
  castor::messages::TapeserverProxyDummy initialProcess;  
157
158
159
160
  castor::tape::tapeserver::client::ClientInterface::VolumeInfo volume;
  volume.density="8000GC";
  volume.labelObsolete="AUL";
  volume.vid="V12345";
161
  volume.mountType=cta::MountType::RETRIEVE;
162
  castor::server::ProcessCapDummy cap;
163
  castor::tape::tapeserver::daemon::TapeServerReporter tsr(initialProcess,  
164
  DriveConfig(),"0.0.0.0",volume,lc);  
165
  FakeSingleTapeReadThread tapeRead(drive, mc, tsr, volume,cap, lc);
166
  
167
  //tapeserver::daemon::RecallReportPacker rrp(client,2,lc);
168
  tapeserver::daemon::RecallTaskInjector rti(mm,tapeRead,diskWrite,client,6,blockSize,lc);
169
  
170
  ASSERT_EQ(false,rti.synchronousInjection());
171
172
173
  ASSERT_EQ(0U,diskWrite.m_tasks.size());
  ASSERT_EQ(0U,tapeRead.m_tasks.size());
}
174
}