tapeserverdTest.cpp 6.14 KB
Newer Older
1
/******************************************************************************
Eric Cano's avatar
Eric Cano committed
2
 *                      tapeserverdTest.cpp
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
 *
 * 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
 *****************************************************************************/

#include <gtest/gtest.h>
26
27
28
29
#define __STDC_CONSTANT_MACROS // For using stdint macros (stdint is included
// by inttypes.h, so we shoot first)
#include <stdint.h>
#include <inttypes.h>
30
31
32
#include "castor/tape/tapeserver/client/ClientSimulator.hpp"
#include "castor/tape/tapeserver/client/ClientSimSingleReply.hpp"
#include "castor/tape/tapeserver/client/ClientProxy.hpp"
33
#include "../threading/Threading.hpp"
Eric Cano's avatar
Eric Cano committed
34
35
#include "castor/log/StringLogger.hpp"
#include "MountSession.hpp"
36
37
#include "../system/Wrapper.hpp"
#include "Ctape.h"
38
39
40
41
#include "castor/tape/tapegateway/Volume.hpp"
#include "castor/tape/tapegateway/NoMoreFiles.hpp"
#include "castor/tape/tapegateway/EndNotificationErrorReport.hpp"
#include "castor/tape/tapegateway/NotificationAcknowledge.hpp"
42

43
using namespace castor::tape::tapeserver;
44
using namespace castor::tape::tapeserver::daemon;
45
46
47
48
namespace unitTest {

class clientRunner: public castor::tape::threading::Thread {
public:
49
  clientRunner(client::ClientSimulator &client): m_sim(client) {}
50
51
52
53
private:
  void run() {
    m_sim.sessionLoop();
  }
54
  client::ClientSimulator & m_sim;
55
56
57
};

  
Eric Cano's avatar
Eric Cano committed
58
TEST(tapeServer, MountSessionGoodday) {
59
60
61
62
  // TpcpClients only supports 32 bits session number
  // This number has to be less than 2^31 as in addition there is a mix
  // of signed and unsigned numbers
  // As the current ids in prod are ~30M, we are far from overflow (Feb 2013)
63
  // 1) prepare the client and run it in another thread
64
65
  uint32_t volReq = 0xBEEF;
  std::string vid = "V12345";
66
  std::string density = "8000GC";
67
68
  client::ClientSimulator sim(volReq, vid, density);
  client::ClientSimulator::ipPort clientAddr = sim.getCallbackAddress();
69
70
  clientRunner simRun(sim);
  simRun.start();
71
72
73
74
75
  
  // 2) Prepare the VDQM request
  castor::tape::legacymsg::RtcpJobRqstMsgBody VDQMjob;
  snprintf(VDQMjob.clientHost, CA_MAXHOSTNAMELEN+1, "%d.%d.%d.%d",
    clientAddr.a, clientAddr.b, clientAddr.c, clientAddr.d);
76
77
  snprintf(VDQMjob.driveUnit, CA_MAXUNMLEN+1, "T10D6116");
  snprintf(VDQMjob.dgn, CA_MAXDGNLEN+1, "LIBXX");
78
79
80
  VDQMjob.clientPort = clientAddr.port;
  VDQMjob.volReqId = volReq;
  
81
82
  // 3) Prepare the necessary environment (logger, plus system wrapper), 
  // construct and run the session.
Eric Cano's avatar
Eric Cano committed
83
  castor::log::StringLogger logger("tapeServerUnitTest");
84
  castor::tape::System::mockWrapper mockSys;
85
86
  mockSys.delegateToFake();
  mockSys.disableGMockCallsCounting();
87
88
89
90
91
92
93
  mockSys.fake.setupForVirtualDriveSLC6();
  utils::TpconfigLines tpConfig;
  // Actual TPCONFIG lifted from prod
  tpConfig.push_back(utils::TpconfigLine("T10D6116", "T10KD6", 
  "/dev/tape_T10D6116", "8000GC", "down", "acs0,1,1,6", "T10000"));
  tpConfig.push_back(utils::TpconfigLine("T10D6116", "T10KD6", 
  "/dev/tape_T10D6116", "5000GC", "down", "acs0,1,1,6", "T10000"));
94
95
96
  MountSession::CastorConf castorConf;
  castorConf.rtcopydBufsz = 1024;
  castorConf.rtcopydNbBufs = 10;
97
98
  castorConf.tapebridgeBulkRequestRecallMaxBytes = UINT64_C(100)*1000*1000*1000;
  castorConf.tapebridgeBulkRequestRecallMaxFiles = 1000;
99
  MountSession sess(VDQMjob, logger, mockSys, tpConfig, castorConf);
Eric Cano's avatar
Eric Cano committed
100
  sess.execute();
101
  simRun.wait();
Eric Cano's avatar
Eric Cano committed
102
103
  std::string temp = logger.getLog();
  temp += "";
104
  ASSERT_EQ("V12345", sess.getVid());
105
106
}

107
108
109
110
111
112
113
114
115
TEST(tapeServer, MountSessionNoSuchDrive) {
  // TpcpClients only supports 32 bits session number
  // This number has to be less than 2^31 as in addition there is a mix
  // of signed and unsigned numbers
  // As the current ids in prod are ~30M, we are far from overflow (Feb 2013)
  // 1) prepare the client and run it in another thread
  uint32_t volReq = 0xBEEF;
  std::string vid = "V12345";
  std::string density = "8000GC";
116
117
  client::ClientSimulator sim(volReq, vid, density);
  client::ClientSimulator::ipPort clientAddr = sim.getCallbackAddress();
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
  clientRunner simRun(sim);
  simRun.start();
  
  // 2) Prepare the VDQM request
  castor::tape::legacymsg::RtcpJobRqstMsgBody VDQMjob;
  snprintf(VDQMjob.clientHost, CA_MAXHOSTNAMELEN+1, "%d.%d.%d.%d",
    clientAddr.a, clientAddr.b, clientAddr.c, clientAddr.d);
  snprintf(VDQMjob.driveUnit, CA_MAXUNMLEN+1, "T10D6116");
  snprintf(VDQMjob.dgn, CA_MAXDGNLEN+1, "LIBXX");
  VDQMjob.clientPort = clientAddr.port;
  VDQMjob.volReqId = volReq;
  
  // 3) Prepare the necessary environment (logger, plus system wrapper), 
  // construct and run the session.
  castor::log::StringLogger logger("tapeServerUnitTest");
  castor::tape::System::mockWrapper mockSys;
  mockSys.delegateToFake();
  mockSys.disableGMockCallsCounting();
  mockSys.fake.setupForVirtualDriveSLC6();
  utils::TpconfigLines tpConfig;
  // Actual TPCONFIG lifted from prod
  tpConfig.push_back(utils::TpconfigLine("T10D6116", "T10KD6", 
  "/dev/noSuchTape", "8000GC", "down", "acs0,1,1,6", "T10000"));
  tpConfig.push_back(utils::TpconfigLine("T10D6116", "T10KD6", 
  "/dev/noSuchTape", "5000GC", "down", "acs0,1,1,6", "T10000"));
143
144
145
146
  MountSession::CastorConf castorConf;
  castorConf.rtcopydBufsz = 1024;
  castorConf.rtcopydNbBufs = 10;
  MountSession sess(VDQMjob, logger, mockSys, tpConfig, castorConf);
147
148
149
150
151
152
153
  sess.execute();
  simRun.wait();
  std::string temp = logger.getLog();
  temp += "";
  ASSERT_NE(std::string::npos, logger.getLog().find("Drive not found on this path"));
}

154
}