tapeserverdTest.cpp 5.46 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
#include "ClientSimulator.hpp"
27
#include "ClientSimSingleReply.hpp"
28
#include "ClientProxy.hpp"
29
#include "../threading/Threading.hpp"
Eric Cano's avatar
Eric Cano committed
30
31
#include "castor/log/StringLogger.hpp"
#include "MountSession.hpp"
32
33
#include "../system/Wrapper.hpp"
#include "Ctape.h"
34
35
36
37
#include "castor/tape/tapegateway/Volume.hpp"
#include "castor/tape/tapegateway/NoMoreFiles.hpp"
#include "castor/tape/tapegateway/EndNotificationErrorReport.hpp"
#include "castor/tape/tapegateway/NotificationAcknowledge.hpp"
38

39
using namespace castor::tape::tapeserver::daemon;
40
41
42
43
44

namespace unitTest {

class clientRunner: public castor::tape::threading::Thread {
public:
45
  clientRunner(ClientSimulator &client): m_sim(client) {}
46
47
48
49
private:
  void run() {
    m_sim.sessionLoop();
  }
50
  ClientSimulator & m_sim;
51
52
53
};

  
Eric Cano's avatar
Eric Cano committed
54
TEST(tapeServer, MountSessionGoodday) {
55
56
57
58
  // 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)
59
  // 1) prepare the client and run it in another thread
60
61
  uint32_t volReq = 0xBEEF;
  std::string vid = "V12345";
62
63
  std::string density = "8000GC";
  ClientSimulator sim(volReq, vid, density);
64
  struct ClientSimulator::ipPort clientAddr = sim.getCallbackAddress();
65
66
  clientRunner simRun(sim);
  simRun.start();
67
68
69
70
71
  
  // 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);
72
73
  snprintf(VDQMjob.driveUnit, CA_MAXUNMLEN+1, "T10D6116");
  snprintf(VDQMjob.dgn, CA_MAXDGNLEN+1, "LIBXX");
74
75
76
  VDQMjob.clientPort = clientAddr.port;
  VDQMjob.volReqId = volReq;
  
77
78
  // 3) Prepare the necessary environment (logger, plus system wrapper), 
  // construct and run the session.
Eric Cano's avatar
Eric Cano committed
79
  castor::log::StringLogger logger("tapeServerUnitTest");
80
  castor::tape::System::mockWrapper mockSys;
81
82
  mockSys.delegateToFake();
  mockSys.disableGMockCallsCounting();
83
84
85
86
87
88
89
90
  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"));
  MountSession sess(VDQMjob, logger, mockSys, tpConfig);
Eric Cano's avatar
Eric Cano committed
91
  sess.execute();
92
  simRun.wait();
Eric Cano's avatar
Eric Cano committed
93
94
  std::string temp = logger.getLog();
  temp += "";
95
  ASSERT_EQ("V12345", sess.getVid());
96
97
}

98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
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";
  ClientSimulator sim(volReq, vid, density);
  struct ClientSimulator::ipPort clientAddr = sim.getCallbackAddress();
  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"));
  MountSession sess(VDQMjob, logger, mockSys, tpConfig);
  sess.execute();
  simRun.wait();
  std::string temp = logger.getLog();
  temp += "";
  ASSERT_NE(std::string::npos, logger.getLog().find("Drive not found on this path"));
}

142
}