DataTransferSessionTest.cpp 51.8 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
23
/******************************************************************************
 *
 * 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
 *****************************************************************************/

24
25
26
27
#define __STDC_CONSTANT_MACROS // For using stdint macros (stdint is included
// by inttypes.h, so we shoot first)
#include <stdint.h>
#include <inttypes.h>
28
#include <gtest/gtest.h>
29

30
#include "castor/legacymsg/RmcProxyDummy.hpp"
31
#include "castor/log/StringLogger.hpp"
32
33
34
#include "castor/mediachanger/MediaChangerFacade.hpp"
#include "castor/mediachanger/MmcProxyDummy.hpp"
#include "castor/messages/AcsProxyDummy.hpp"
35
#include "castor/messages/TapeserverProxyDummy.hpp"
36
#include "castor/server/ProcessCapDummy.hpp"
37
#include "castor/server/Threading.hpp"
38
#include "castor/tape/tapeserver/daemon/DataTransferSession.hpp"
39
#include "castor/tape/tapeserver/daemon/VolumeInfo.hpp"
40
41
#include "castor/tape/tapeserver/system/Wrapper.hpp"
#include "castor/tape/tapeserver/file/File.hpp"
42
#include "castor/tape/tapeserver/drive/FakeDrive.hpp"
43
44
#include "common/exception/Exception.hpp"
#include "common/Utils.hpp"
45
#include "Ctape.h"
46
#include "scheduler/Scheduler.hpp"
47
#include "smc_struct.h"
48
49
#include "nameserver/mockNS/MockNameServer.hpp"
#include "remotens/MockRemoteNS.hpp"
50
#include "remotens/MockRemoteFullFS.hpp"
51
#include "scheduler/DummyScheduler.hpp"
52
#include "scheduler/OStoreDB/OStoreDBFactory.hpp"
53
#include "scheduler/MountType.hpp"
54
55
56
57
#include "nameserver/NameServer.hpp"
#include "scheduler/testingMocks/MockRetrieveMount.hpp"
#include "scheduler/testingMocks/MockArchiveJob.hpp"
#include "scheduler/testingMocks/MockArchiveMount.hpp"
58

59
#include <dirent.h>
60
#include <fcntl.h>
61
#include <stdexcept>
Eric Cano's avatar
Eric Cano committed
62
63
64
#include <sys/mman.h>
#include <sys/types.h>
#include <sys/stat.h>
65
66
#include <unistd.h>
#include <zlib.h>
Eric Cano's avatar
Eric Cano committed
67

68
using namespace castor::tape::tapeserver;
69
using namespace castor::tape::tapeserver::daemon;
Eric Cano's avatar
Eric Cano committed
70
namespace unitTests {
71

72
73
class castor_tape_tapeserver_daemon_DataTransferSessionTest: public
  ::testing::Test {
74
75
76
protected:

  void SetUp() {
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
    strncpy(m_tmpDir, "/tmp/DataTransferSessionTestXXXXXX", sizeof(m_tmpDir));
    if(!mkdtemp(m_tmpDir)) {
      const std::string errMsg = cta::Utils::errnoToString(errno);
      std::ostringstream msg;
      msg << "Failed to create directory with template"
        " /tmp/DataTransferSessionTestXXXXXX: " << errMsg;
      bzero(m_tmpDir, sizeof(m_tmpDir));
      throw cta::exception::Exception(msg.str());
    }

    struct stat statBuf;
    bzero(&statBuf, sizeof(statBuf));
    if(stat(m_tmpDir, &statBuf)) {
      const std::string errMsg = cta::Utils::errnoToString(errno);
      std::ostringstream msg;
      msg << "Failed to stat directory " << m_tmpDir << ": " << errMsg;
      throw cta::exception::Exception(msg.str());
    }

    std::ostringstream cmd;
    cmd << "touch " << m_tmpDir << "/hello";
    system(cmd.str().c_str());
99
100
101
  }

  void TearDown() {
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
    // If Setup() created a temporary directory
    if(m_tmpDir) {

      // Openn the directory
      std::unique_ptr<DIR, std::function<int(DIR*)>>
        dir(opendir(m_tmpDir), closedir);
      if(NULL == dir.get()) {
        const std::string errMsg = cta::Utils::errnoToString(errno);
        std::ostringstream msg;
        msg << "Failed to open directory " << m_tmpDir << ": " << errMsg;
        throw cta::exception::Exception(msg.str());
      }

      // Delete each of the files within the directory
      struct dirent *entry = NULL;
      while((entry = readdir(dir.get()))) {
        const std::string entryName(entry->d_name);
        if(entryName != "." && entryName != "..") {
          const std::string entryPath = std::string(m_tmpDir) + "/" + entryName;
          if(unlink(entryPath.c_str())) {
            const std::string errMsg = cta::Utils::errnoToString(errno);
            std::ostringstream msg;
            msg << "Failed to unlink " << entryPath;
            throw cta::exception::Exception(msg.str());
          }
        }
      }

      // Delete the now empty directory
      if(rmdir(m_tmpDir)) {
        const std::string errMsg = cta::Utils::errnoToString(errno);
        std::ostringstream msg;
        msg << "Failed to delete directory " << m_tmpDir << ": " << errMsg;
        throw cta::exception::Exception(msg.str());
      }
    }
138
  }
139

140
141
142
143
144
145
146
  /**
   * Temporary directory created with mkdtemp that will be used to contain the
   * destination remote files of the tests that need to create them.
   *
   * Please note that a new temporary directory is created and deleted for each
   * test by the Setup() and TearDown() methods.
   */
147
  char m_tmpDir[100];
148
149
};

150
TEST_F(castor_tape_tapeserver_daemon_DataTransferSessionTest, DataTransferSessionGooddayRecall) {
Eric Cano's avatar
Eric Cano committed
151
152
153
  // 0) Prepare the logger for everyone
  castor::log::StringLogger logger("tapeServerUnitTest");
  
154
  // 1) prepare the fake scheduler
155
  std::string vid = "V12345";
156
157
  // cta::MountType::Enum mountType = cta::MountType::RETRIEVE;

158
159
  // 3) Prepare the necessary environment (logger, plus system wrapper), 
  castor::tape::System::mockWrapper mockSys;
160
161
  mockSys.delegateToFake();
  mockSys.disableGMockCallsCounting();
162
  mockSys.fake.setupForVirtualDriveSLC6();
163
164
165
  //delete is unnecessary
  //pointer with ownership will be passed to the application,
  //which will do the delete 
166
  mockSys.fake.m_pathToDrive["/dev/nst0"] = new castor::tape::tapeserver::drive::FakeDrive;
167
168
169
170

  // 4) Create the scheduler
  cta::MockNameServer ns;
  cta::MockRemoteNS rns;
171
  cta::OStoreDBWrapper<cta::objectstore::BackendVFS> db("Unittest");
172
173
174
175
176
177
178
179
  cta::Scheduler scheduler(ns, db, rns);

  // Always use the same requester
  const cta::SecurityIdentity requester;

  // List to remember the path of each remote file so that the existance of the
  // files can be tested for at the end of the test
  std::list<std::string> remoteFilePaths;
180
  
181
182
183
184
185
186
187
188
189
190
191
192
  // 5) Create the tapepool, library and tape for the scheduler.
  // Make mounts immediate.
  ASSERT_NO_THROW(scheduler.createAdminUserWithoutAuthorizingRequester(requester, requester.getUser(), ""));
  ASSERT_NO_THROW(scheduler.createAdminHostWithoutAuthorizingRequester(requester, requester.getHost(), ""));
  ASSERT_NO_THROW(scheduler.createTapePool(requester, "TapePool", 1, ""));
  cta::MountCriteria immediateMount;
  immediateMount.maxAge = 0;
  immediateMount.maxBytesQueued = 1;
  immediateMount.maxFilesQueued = 1;
  immediateMount.quota = 10;
  ASSERT_NO_THROW(scheduler.setTapePoolMountCriteria("TapePool", cta::MountCriteriaByDirection(immediateMount, immediateMount)));                   
  ASSERT_NO_THROW(scheduler.createLogicalLibrary(requester, "T10KD6", ""));
193
  ASSERT_NO_THROW(scheduler.createTape(requester, "V12345", "T10KD6", "TapePool", 10*1000*1000, ""));
194
  
195
  // 5) Prepare files for reading by writing them to the mock system
196
197
198
  {
    // Label the tape
    castor::tape::tapeFile::LabelSession ls(*mockSys.fake.m_pathToDrive["/dev/nst0"], 
199
        "V12345");
200
201
    mockSys.fake.m_pathToDrive["/dev/nst0"]->rewind();
    // And write to it
202
    castor::tape::tapeserver::daemon::VolumeInfo volInfo;
203
    volInfo.vid="V12345";
204
    castor::tape::tapeFile::WriteSession ws(*mockSys.fake.m_pathToDrive["/dev/nst0"],
205
       volInfo , 0, true);
206
207
208

    // Write a few files on the virtual tape and modify the archive name space
    // so that it is in sync
209
210
211
    uint8_t data[1000];
    castor::tape::SCSI::Structures::zeroStruct(&data);
    for (int fseq=1; fseq <= 10 ; fseq ++) {
212
213
      // Create a path to a remote destination file
      std::ostringstream remoteFilePath;
214
      remoteFilePath << "file://" << m_tmpDir << "/test" << fseq;
215
216
      remoteFilePaths.push_back(remoteFilePath.str());

217
      // Create an archive file entry in the archive namespace
218
219
220
221
      std::ostringstream archiveFilePath;
      archiveFilePath << "/test" << fseq;
      const mode_t archiveFileMode = 0655;
      const uint64_t archiveFileSize = 256*1024;
222
      ASSERT_NO_THROW(ns.createFile(
223
224
225
        requester,
        archiveFilePath.str(),
        archiveFileMode,
226
        cta::Checksum(cta::Checksum::CHECKSUMTYPE_ADLER32, cta::Utils::getAdler32(data, sizeof data)),
227
        archiveFileSize));
228
      std::unique_ptr<cta::ArchiveFileStatus> status = ns.statFile(requester, archiveFilePath.str());
229
      
230
      // Write the file to tape
231
232
233
234
235
      cta::MockRetrieveMount mrm;
      cta::MockNameServer mns;
      cta::MockArchiveMount mam(mns);
      std::unique_ptr<cta::RetrieveJob> ftr(new cta::MockRetrieveJob(mrm));
      std::unique_ptr<cta::ArchiveJob> ftm(new cta::MockArchiveJob(mam, mns));
236
      ftr->nameServerTapeFile.tapeFileLocation.fSeq = fseq;
237
      ftm->nameServerTapeFile.tapeFileLocation.fSeq = fseq;
238
239
      ftr->archiveFile.fileId = status->fileId;
      ftm->archiveFile.fileId = status->fileId;
240
      castor::tape::tapeFile::WriteFile wf(&ws, *ftm, archiveFileSize);
241
      ftr->nameServerTapeFile.tapeFileLocation.blockId = wf.getBlockId();
242
      ftr->remotePath = remoteFilePath.str();
243
244
245
246
      // Write the data (one block)
      wf.write(data, sizeof(data));
      // Close the file
      wf.close();
247

248
249
250
251
      // Create tape file entry in the archive namespace
      cta::NameServerTapeFile tapeFile;
      tapeFile.copyNb = 1;
      tapeFile.tapeFileLocation.fSeq = fseq;
252
      tapeFile.tapeFileLocation.blockId = wf.getBlockId();
253
254
255
256
      tapeFile.tapeFileLocation.vid = volInfo.vid;
      tapeFile.tapeFileLocation.copyNb = 1;
      tapeFile.size = archiveFileSize;
      tapeFile.compressedSize = archiveFileSize; // No compression
257
      cta::Checksum tapeFileChecksum(cta::Checksum::CHECKSUMTYPE_ADLER32, cta::Utils::getAdler32(data, sizeof data));
258
259
260
261
262
263
      tapeFile.checksum = tapeFileChecksum;
      ASSERT_NO_THROW(ns.addTapeFile(
        requester,
        archiveFilePath.str(),
        tapeFile));

264
265
266
      // Schedule the retrieval of the file
      std::list<std::string> archiveFilePaths;
      archiveFilePaths.push_back(archiveFilePath.str());
267
      ASSERT_NO_THROW(scheduler.queueRetrieveRequest(
268
269
        requester,
        archiveFilePaths,
270
        remoteFilePath.str()));
271
272
    }
  }
273
274

  // 6) Create the data transfer session
275
  DriveConfig driveConfig("T10D6116", "T10KD6", "/dev/tape_T10D6116", "manual");
276
277
278
279
280
281
  DataTransferConfig castorConf;
  castorConf.bufsz = 1024*1024; // 1 MB memory buffers
  castorConf.nbBufs = 10;
  castorConf.bulkRequestRecallMaxBytes = UINT64_C(100)*1000*1000*1000;
  castorConf.bulkRequestRecallMaxFiles = 1000;
  castorConf.nbDiskThreads = 1;
282
283
284
285
  castor::messages::AcsProxyDummy acs;
  castor::mediachanger::MmcProxyDummy mmc;
  castor::legacymsg::RmcProxyDummy rmc;
  castor::mediachanger::MediaChangerFacade mc(acs, mmc, rmc);
286
  castor::server::ProcessCap capUtils;
287
  castor::messages::TapeserverProxyDummy initialProcess;
288
  DataTransferSession sess("tapeHost", logger, mockSys,
289
    driveConfig, mc, initialProcess, capUtils, castorConf, scheduler);
290
291

  // 7) Run the data transfer session
292
  ASSERT_NO_THROW(sess.execute());
293
294

  // 8) Check the session git the correct VID
295
  ASSERT_EQ("V12345", sess.getVid());
296

297
  // 9) Check the remote files exist and have the correct size
298
299
300
301
  for(auto pathItor = remoteFilePaths.cbegin(); pathItor !=
    remoteFilePaths.cend(); pathItor++) {
    struct stat statBuf;
    bzero(&statBuf, sizeof(statBuf));
302
    const int statRc = stat(pathItor->substr(7).c_str(), &statBuf); //remove the "file://" for stat-ing
303
    ASSERT_EQ(0, statRc);
304
    ASSERT_EQ(1000, statBuf.st_size); //same size of data
305
  }
306
}
307

308
TEST_F(castor_tape_tapeserver_daemon_DataTransferSessionTest, DataTransferSessionWrongRecall) {
309
310
311
  // This test is the same as the previous one, with 
  // wrong parameters set for the recall, so that we fail 
  // to recall the first file and cancel the second.
312
313

  // 0) Prepare the logger for everyone
314
315
  castor::log::StringLogger logger("tapeServerUnitTest");
  
316
  // 1) prepare the fake scheduler
317
  std::string vid = "V12345";
318
319
  // cta::MountType::Enum mountType = cta::MountType::RETRIEVE;

320
321
322
323
324
325
326
327
  // 3) Prepare the necessary environment (logger, plus system wrapper), 
  castor::tape::System::mockWrapper mockSys;
  mockSys.delegateToFake();
  mockSys.disableGMockCallsCounting();
  mockSys.fake.setupForVirtualDriveSLC6();
  //delete is unnecessary
  //pointer with ownership will be passed to the application,
  //which will do the delete 
328
  mockSys.fake.m_pathToDrive["/dev/nst0"] = new castor::tape::tapeserver::drive::FakeDrive;
329
330
331
332

  // 4) Create the scheduler
  cta::MockNameServer ns;
  cta::MockRemoteNS rns;
333
  cta::OStoreDBWrapper<cta::objectstore::BackendVFS> db("Unittest");
334
335
336
337
338
339
340
341
  cta::Scheduler scheduler(ns, db, rns);

  // Always use the same requester
  const cta::SecurityIdentity requester;

  // List to remember the path of each remote file so that the existance of the
  // files can be tested for at the end of the test
  std::list<std::string> remoteFilePaths;
342
  
343
344
345
346
347
348
349
350
351
352
353
354
  // 5) Create the tapepool, library and tape for the scheduler.
  // Make mounts immediate.
  ASSERT_NO_THROW(scheduler.createAdminUserWithoutAuthorizingRequester(requester, requester.getUser(), ""));
  ASSERT_NO_THROW(scheduler.createAdminHostWithoutAuthorizingRequester(requester, requester.getHost(), ""));
  ASSERT_NO_THROW(scheduler.createTapePool(requester, "TapePool", 1, ""));
  cta::MountCriteria immediateMount;
  immediateMount.maxAge = 0;
  immediateMount.maxBytesQueued = 1;
  immediateMount.maxFilesQueued = 1;
  immediateMount.quota = 10;
  ASSERT_NO_THROW(scheduler.setTapePoolMountCriteria("TapePool", cta::MountCriteriaByDirection(immediateMount, immediateMount)));                   
  ASSERT_NO_THROW(scheduler.createLogicalLibrary(requester, "T10KD6", ""));
355
  ASSERT_NO_THROW(scheduler.createTape(requester, "V12345", "T10KD6", "TapePool", 10*1000*1000, ""));
356
  
357
  // 5) Prepare files for reading by writing them to the mock system
358
359
360
  {
    // Label the tape
    castor::tape::tapeFile::LabelSession ls(*mockSys.fake.m_pathToDrive["/dev/nst0"], 
361
        "V12345");
362
363
    mockSys.fake.m_pathToDrive["/dev/nst0"]->rewind();
    // And write to it
364
    castor::tape::tapeserver::daemon::VolumeInfo volInfo;
365
366
367
    volInfo.vid="V12345";
    castor::tape::tapeFile::WriteSession ws(*mockSys.fake.m_pathToDrive["/dev/nst0"],
       volInfo , 0, true);
368
369
370

    // Write a few files on the virtual tape and modify the archive name space
    // so that it is in sync
371
372
    uint8_t data[1000];
    castor::tape::SCSI::Structures::zeroStruct(&data);
373
374
    int fseq=1;
    {
375
376
      // Create a path to a remote destination file
      std::ostringstream remoteFilePath;
377
      remoteFilePath << "file://" << m_tmpDir << "/test" << fseq;
378
379
      remoteFilePaths.push_back(remoteFilePath.str());

380
      // Create an archive file entry in the archive namespace
381
382
383
      std::ostringstream archiveFilePath;
      archiveFilePath << "/test" << fseq;
      const mode_t archiveFileMode = 0655;
384
      const uint64_t archiveFileSize = 1000;
385
      ASSERT_NO_THROW(ns.createFile(
386
387
388
        requester,
        archiveFilePath.str(),
        archiveFileMode,
389
        cta::Checksum(cta::Checksum::CHECKSUMTYPE_ADLER32, cta::Utils::getAdler32(data, sizeof data)),
390
        archiveFileSize));
391
392

      // Write the file to tape
393
394
395
396
397
      cta::MockNameServer mns;
      cta::MockArchiveMount mam(mns);
      cta::MockRetrieveMount mrm;
      std::unique_ptr<cta::RetrieveJob> ftr(new cta::MockRetrieveJob(mrm));
      std::unique_ptr<cta::ArchiveJob> ftm_temp(new cta::MockArchiveJob(mam, mns));
398
      ftr->nameServerTapeFile.tapeFileLocation.fSeq = fseq;
399
      ftm_temp->nameServerTapeFile.tapeFileLocation.fSeq = fseq;
400
401
      ftr->archiveFile.fileId = 1000 + fseq;
      ftm_temp->archiveFile.fileId = 1000 + fseq;
402
      castor::tape::tapeFile::WriteFile wf(&ws, *ftm_temp, archiveFileSize);
403
      ftr->nameServerTapeFile.tapeFileLocation.blockId = wf.getBlockId();
404
      ftr->remotePath = remoteFilePath.str();
405
406
407
408
      // Write the data (one block)
      wf.write(data, sizeof(data));
      // Close the file
      wf.close();
409

410
411
412
413
414
      // Create tape file entry in the archive namespace that is beyond the end
      // of data
      cta::NameServerTapeFile tapeFile;
      tapeFile.copyNb = 1;
      tapeFile.tapeFileLocation.fSeq = fseq + 10000;
415
      tapeFile.tapeFileLocation.blockId = wf.getBlockId() + 10000;
416
417
418
419
      tapeFile.tapeFileLocation.vid = volInfo.vid;
      tapeFile.tapeFileLocation.copyNb = 1;
      tapeFile.size = archiveFileSize;
      tapeFile.compressedSize = archiveFileSize; // No compression
420
      cta::Checksum tapeFileChecksum(cta::Checksum::CHECKSUMTYPE_ADLER32, cta::Utils::getAdler32(data, sizeof data));
421
422
423
424
425
426
      tapeFile.checksum = tapeFileChecksum;
      ASSERT_NO_THROW(ns.addTapeFile(
        requester,
        archiveFilePath.str(),
        tapeFile));

427
428
429
      // Schedule the retrieval of the file
      std::list<std::string> archiveFilePaths;
      archiveFilePaths.push_back(archiveFilePath.str());
430
      ASSERT_NO_THROW(scheduler.queueRetrieveRequest(
431
432
        requester,
        archiveFilePaths,
433
        remoteFilePath.str()));
434
435
    }
  }
436
437

  // 6) Create the data transfer session
438
  DriveConfig driveConfig("T10D6116", "T10KD6", "/dev/tape_T10D6116", "manual");
439
440
441
442
443
444
  DataTransferConfig castorConf;
  castorConf.bufsz = 1024*1024; // 1 MB memory buffers
  castorConf.nbBufs = 10;
  castorConf.bulkRequestRecallMaxBytes = UINT64_C(100)*1000*1000*1000;
  castorConf.bulkRequestRecallMaxFiles = 1000;
  castorConf.nbDiskThreads = 1;
445
446
447
448
  castor::messages::AcsProxyDummy acs;
  castor::mediachanger::MmcProxyDummy mmc;
  castor::legacymsg::RmcProxyDummy rmc;
  castor::mediachanger::MediaChangerFacade mc(acs, mmc, rmc);
449
450
  castor::server::ProcessCap capUtils;
  castor::messages::TapeserverProxyDummy initialProcess;
451
  DataTransferSession sess("tapeHost", logger, mockSys,
452
    driveConfig, mc, initialProcess, capUtils, castorConf, scheduler);
453
454
455
456
457

  // 7) Run the data transfer session
  ASSERT_NO_THROW(sess.execute());

  // 8) Check the session git the correct VID
458
  ASSERT_EQ("V12345", sess.getVid());
459
460

  // 9) Check the remote files exist and have the correct size
461
462
  std::string temp = logger.getLog();
  ASSERT_NE(std::string::npos, logger.getLog().find("trying to position beyond the end of data"));
463
}
464

465
TEST_F(castor_tape_tapeserver_daemon_DataTransferSessionTest, DataTransferSessionNoSuchDrive) {
466
467
468
469
470
  
  // 0) Prepare the logger for everyone
  castor::log::StringLogger logger("tapeServerUnitTest");
  
  // 1) prepare the fake scheduler
471
  std::string vid = "V12345";
472
473
  // cta::MountType::Enum mountType = cta::MountType::RETRIEVE;

474
475
476
477
478
  // 3) Prepare the necessary environment (logger, plus system wrapper), 
  castor::tape::System::mockWrapper mockSys;
  mockSys.delegateToFake();
  mockSys.disableGMockCallsCounting();
  mockSys.fake.setupForVirtualDriveSLC6();
479
480
481
482
483
484
485
486
  //delete is unnecessary
  //pointer with ownership will be passed to the application,
  //which will do the delete 
  mockSys.fake.m_pathToDrive["/dev/nst0"] = new castor::tape::tapeserver::drive::FakeDrive;

  // 4) Create the scheduler
  cta::MockNameServer ns;
  cta::MockRemoteNS rns;
487
  cta::OStoreDBWrapper<cta::objectstore::BackendVFS> db("Unittest");
488
489
490
491
492
  cta::Scheduler scheduler(ns, db, rns);

  // Always use the same requester
  const cta::SecurityIdentity requester;
  
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
  // List to remember the path of each remote file so that the existance of the
  // files can be tested for at the end of the test
  std::list<std::string> remoteFilePaths;
  
  // 5) Create the tapepool, library and tape for the scheduler.
  // Make mounts immediate.
  ASSERT_NO_THROW(scheduler.createAdminUserWithoutAuthorizingRequester(requester, requester.getUser(), ""));
  ASSERT_NO_THROW(scheduler.createAdminHostWithoutAuthorizingRequester(requester, requester.getHost(), ""));
  ASSERT_NO_THROW(scheduler.createTapePool(requester, "TapePool", 1, ""));
  cta::MountCriteria immediateMount;
  immediateMount.maxAge = 0;
  immediateMount.maxBytesQueued = 1;
  immediateMount.maxFilesQueued = 1;
  immediateMount.quota = 10;
  ASSERT_NO_THROW(scheduler.setTapePoolMountCriteria("TapePool", cta::MountCriteriaByDirection(immediateMount, immediateMount)));                   
  ASSERT_NO_THROW(scheduler.createLogicalLibrary(requester, "T10KD6", ""));
509
  ASSERT_NO_THROW(scheduler.createTape(requester, "V12345", "T10KD6", "TapePool", 10*1000*1000, ""));
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
  
  // 5) Prepare files for reading by writing them to the mock system
  {
    // Label the tape
    castor::tape::tapeFile::LabelSession ls(*mockSys.fake.m_pathToDrive["/dev/nst0"], 
        "V12345");
    mockSys.fake.m_pathToDrive["/dev/nst0"]->rewind();
    // And write to it
    castor::tape::tapeserver::daemon::VolumeInfo volInfo;
    volInfo.vid="V12345";
    castor::tape::tapeFile::WriteSession ws(*mockSys.fake.m_pathToDrive["/dev/nst0"],
       volInfo , 0, true);

    // Write a few files on the virtual tape and modify the archive name space
    // so that it is in sync
    uint8_t data[1000];
    castor::tape::SCSI::Structures::zeroStruct(&data);
    int fseq=1;
    {
      // Create a path to a remote destination file
      std::ostringstream remoteFilePath;
      remoteFilePath << "file://" << m_tmpDir << "/test" << fseq;
      remoteFilePaths.push_back(remoteFilePath.str());

      // Create an archive file entry in the archive namespace
      std::ostringstream archiveFilePath;
      archiveFilePath << "/test" << fseq;
      const mode_t archiveFileMode = 0655;
      const uint64_t archiveFileSize = 1000;
      ASSERT_NO_THROW(ns.createFile(
        requester,
        archiveFilePath.str(),
        archiveFileMode,
543
        cta::Checksum(cta::Checksum::CHECKSUMTYPE_ADLER32, cta::Utils::getAdler32(data, sizeof data)),
544
545
546
        archiveFileSize));

      // Write the file to tape
547
548
549
550
551
      cta::MockNameServer mns;
      cta::MockArchiveMount mam(mns);
      cta::MockRetrieveMount mrm;
      std::unique_ptr<cta::RetrieveJob> ftr(new cta::MockRetrieveJob(mrm));
      std::unique_ptr<cta::ArchiveJob> ftm_temp(new cta::MockArchiveJob(mam, mns));
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
      ftr->nameServerTapeFile.tapeFileLocation.fSeq = fseq;
      ftm_temp->nameServerTapeFile.tapeFileLocation.fSeq = fseq;
      ftr->archiveFile.fileId = 1000 + fseq;
      ftm_temp->archiveFile.fileId = 1000 + fseq;
      castor::tape::tapeFile::WriteFile wf(&ws, *ftm_temp, archiveFileSize);
      ftr->nameServerTapeFile.tapeFileLocation.blockId = wf.getBlockId();
      ftr->remotePath = remoteFilePath.str();
      // Write the data (one block)
      wf.write(data, sizeof(data));
      // Close the file
      wf.close();

      // Create tape file entry in the archive namespace that is beyond the end
      // of data
      cta::NameServerTapeFile tapeFile;
      tapeFile.copyNb = 1;
      tapeFile.tapeFileLocation.fSeq = fseq + 1000;
      tapeFile.tapeFileLocation.blockId = wf.getBlockId();
      tapeFile.tapeFileLocation.vid = volInfo.vid;
      tapeFile.tapeFileLocation.copyNb = 1;
      tapeFile.size = archiveFileSize;
      tapeFile.compressedSize = archiveFileSize; // No compression
574
      cta::Checksum tapeFileChecksum(cta::Checksum::CHECKSUMTYPE_ADLER32, cta::Utils::getAdler32(data, sizeof data));
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
      tapeFile.checksum = tapeFileChecksum;
      ASSERT_NO_THROW(ns.addTapeFile(
        requester,
        archiveFilePath.str(),
        tapeFile));

      // Schedule the retrieval of the file
      std::list<std::string> archiveFilePaths;
      archiveFilePaths.push_back(archiveFilePath.str());
      ASSERT_NO_THROW(scheduler.queueRetrieveRequest(
        requester,
        archiveFilePaths,
        remoteFilePath.str()));
    }
  }
  
  DriveConfig driveConfig("T10D6116", "T10KD6", "/dev/noSuchDrive", "manual");
592
593
594
  DataTransferConfig castorConf;
  castorConf.bufsz = 1024;
  castorConf.nbBufs = 10;
595
596
597
598
  castor::messages::AcsProxyDummy acs;
  castor::mediachanger::MmcProxyDummy mmc;
  castor::legacymsg::RmcProxyDummy rmc;
  castor::mediachanger::MediaChangerFacade mc(acs, mmc, rmc);
599
  castor::messages::TapeserverProxyDummy initialProcess;
600
  castor::server::ProcessCapDummy capUtils;
601
  DataTransferSession sess("tapeHost", logger, mockSys,
602
    driveConfig, mc, initialProcess, capUtils, castorConf, scheduler);
603
  ASSERT_NO_THROW(sess.execute());
604
  std::string temp = logger.getLog();
605
  ASSERT_NE(std::string::npos, logger.getLog().find("Could not stat path: /dev/noSuchDrive"));
606
607
}

608
TEST_F(castor_tape_tapeserver_daemon_DataTransferSessionTest, DataTransferSessionFailtoMount) {
609
610
  
  // 0) Prepare the logger for everyone
611
612
  castor::log::StringLogger logger("tapeServerUnitTest");
  
613
  // 1) prepare the fake scheduler
614
  std::string vid = "V12345";
615
616
  // cta::MountType::Enum mountType = cta::MountType::RETRIEVE;

617
618
619
620
621
  // 3) Prepare the necessary environment (logger, plus system wrapper), 
  castor::tape::System::mockWrapper mockSys;
  mockSys.delegateToFake();
  mockSys.disableGMockCallsCounting();
  mockSys.fake.setupForVirtualDriveSLC6();
622
623
624
625

  // 4) Create the scheduler
  cta::MockNameServer ns;
  cta::MockRemoteNS rns;
626
  cta::OStoreDBWrapper<cta::objectstore::BackendVFS> db("Unittest");
627
628
629
630
631
632
633
634
  cta::Scheduler scheduler(ns, db, rns);

  // Always use the same requester
  const cta::SecurityIdentity requester;
  
  // List to remember the path of each remote file so that the existance of the
  // files can be tested for at the end of the test
  std::list<std::string> remoteFilePaths;
635
636
637
638
639
640
641
642
643
644
645
646
647
  
  // 5) Create the tapepool, library and tape for the scheduler.
  // Make mounts immediate.
  ASSERT_NO_THROW(scheduler.createAdminUserWithoutAuthorizingRequester(requester, requester.getUser(), ""));
  ASSERT_NO_THROW(scheduler.createAdminHostWithoutAuthorizingRequester(requester, requester.getHost(), ""));
  ASSERT_NO_THROW(scheduler.createTapePool(requester, "TapePool", 1, ""));
  cta::MountCriteria immediateMount;
  immediateMount.maxAge = 0;
  immediateMount.maxBytesQueued = 1;
  immediateMount.maxFilesQueued = 1;
  immediateMount.quota = 10;
  ASSERT_NO_THROW(scheduler.setTapePoolMountCriteria("TapePool", cta::MountCriteriaByDirection(immediateMount, immediateMount)));                   
  ASSERT_NO_THROW(scheduler.createLogicalLibrary(requester, "T10KD6", ""));
648
  ASSERT_NO_THROW(scheduler.createTape(requester, "V12345", "T10KD6", "TapePool", 10*1000*1000, ""));
649
650
651
652
653
654
655
656
657

  //delete is unnecessary
  //pointer with ownership will be passed to the application,
  //which will do the delete 
  const bool failOnMount=true;
  mockSys.fake.m_pathToDrive["/dev/nst0"] = new castor::tape::tapeserver::drive::FakeDrive(failOnMount);
  
  // We can prepare files for reading on the drive
  {
658
    
659
660
    // Label the tape
    castor::tape::tapeFile::LabelSession ls(*mockSys.fake.m_pathToDrive["/dev/nst0"], 
661
        "V12345");
662
663
    mockSys.fake.m_pathToDrive["/dev/nst0"]->rewind();
    // And write to it
664
    castor::tape::tapeserver::daemon::VolumeInfo volInfo;
665
    volInfo.vid="V12345";
666
667
668
669
670
671
672
    castor::tape::tapeFile::WriteSession ws(*mockSys.fake.m_pathToDrive["/dev/nst0"],
       volInfo , 0, true);

    // Write a few files on the virtual tape and modify the archive name space
    // so that it is in sync
    uint8_t data[1000];
    castor::tape::SCSI::Structures::zeroStruct(&data);
673
    for (int fseq=1; fseq <= 10 ; fseq ++) {
674
675
      // Create a path to a remote destination file
      std::ostringstream remoteFilePath;
676
      remoteFilePath << "file://" << m_tmpDir << "/test" << fseq;
677
678
      remoteFilePaths.push_back(remoteFilePath.str());

679
      // Create an archive file entry in the archive namespace
680
681
682
      std::ostringstream archiveFilePath;
      archiveFilePath << "/test" << fseq;
      const mode_t archiveFileMode = 0655;
683
      const uint64_t archiveFileSize = 1000;
684
      ASSERT_NO_THROW(ns.createFile(
685
686
687
        requester,
        archiveFilePath.str(),
        archiveFileMode,
688
        cta::Checksum(),
689
        archiveFileSize));
690
691

      // Write the file to tape
692
693
694
695
696
      cta::MockNameServer  mns;
      cta::MockArchiveMount mam(mns);
      cta::MockRetrieveMount mrm;
      std::unique_ptr<cta::RetrieveJob> ftr(new cta::MockRetrieveJob(mrm));
      std::unique_ptr<cta::ArchiveJob> ftm_temp(new cta::MockArchiveJob(mam, mns));
697
      ftr->nameServerTapeFile.tapeFileLocation.fSeq = fseq;
698
      ftm_temp->nameServerTapeFile.tapeFileLocation.fSeq = fseq;
699
      ftr->archiveFile.fileId = 1000 + fseq;
700
701
      ftm_temp->archiveFile.fileId = 1000 + fseq;
      castor::tape::tapeFile::WriteFile wf(&ws, *ftm_temp, archiveFileSize);
702
703
      ftr->nameServerTapeFile.tapeFileLocation.blockId = wf.getPosition();
      ftr->remotePath = remoteFilePath.str();
704
705
706
707
708
      // Write the data (one block)
      wf.write(data, sizeof(data));
      // Close the file
      wf.close();

709
710
711
712
713
714
715
716
717
      // Create tape file entry in the archive namespace
      cta::NameServerTapeFile tapeFile;
      tapeFile.copyNb = 1;
      tapeFile.tapeFileLocation.fSeq = fseq;
      tapeFile.tapeFileLocation.blockId = wf.getPosition();
      tapeFile.tapeFileLocation.vid = volInfo.vid;
      tapeFile.tapeFileLocation.copyNb = 1;
      tapeFile.size = archiveFileSize;
      tapeFile.compressedSize = archiveFileSize; // No compression
718
      cta::Checksum tapeFileChecksum(cta::Checksum::CHECKSUMTYPE_ADLER32, cta::Utils::getAdler32(data, sizeof data));
719
720
721
722
723
724
      tapeFile.checksum = tapeFileChecksum;
      ASSERT_NO_THROW(ns.addTapeFile(
        requester,
        archiveFilePath.str(),
        tapeFile));

725
726
727
      // Schedule the retrieval of the file
      std::list<std::string> archiveFilePaths;
      archiveFilePaths.push_back(archiveFilePath.str());
728
      ASSERT_NO_THROW(scheduler.queueRetrieveRequest(
729
730
        requester,
        archiveFilePaths,
731
        remoteFilePath.str()));
732
733
    }
  }
734
  DriveConfig driveConfig("T10D6116", "T10KD6", "/dev/tape_T10D6116", "manual");
735
736
737
738
739
740
741
742
743
744
745
746
  DataTransferConfig castorConf;
  castorConf.bufsz = 1024*1024; // 1 MB memory buffers
  castorConf.nbBufs = 10;
  castorConf.bulkRequestRecallMaxBytes = UINT64_C(100)*1000*1000*1000;
  castorConf.bulkRequestRecallMaxFiles = 1000;
  castorConf.nbDiskThreads = 3;
  castor::messages::AcsProxyDummy acs;
  castor::mediachanger::MmcProxyDummy mmc;
  castor::legacymsg::RmcProxyDummy rmc;
  castor::mediachanger::MediaChangerFacade mc(acs, mmc, rmc);
  castor::server::ProcessCap capUtils;
  castor::messages::TapeserverProxyDummy initialProcess;
747
  DataTransferSession sess("tapeHost", logger, mockSys,
748
    driveConfig, mc, initialProcess, capUtils, castorConf, scheduler);
749
  ASSERT_NO_THROW(sess.execute());
750
  std::string temp = logger.getLog();
751
  ASSERT_NE(std::string::npos, logger.getLog().find("Failed to mount the tape"));
752
753
}

754
TEST_F(castor_tape_tapeserver_daemon_DataTransferSessionTest, DataTransferSessionEmptyOnVolReq) {
755
756
  
  // 0) Prepare the logger for everyone
757
758
  castor::log::StringLogger logger("tapeServerUnitTest");
  
759
  // 1) prepare the fake scheduler
760
  std::string vid = "V12345";
761
762
  // cta::MountType::Enum mountType = cta::MountType::RETRIEVE;

763
764
765
766
767
  // 3) Prepare the necessary environment (logger, plus system wrapper), 
  castor::tape::System::mockWrapper mockSys;
  mockSys.delegateToFake();
  mockSys.disableGMockCallsCounting();
  mockSys.fake.setupForVirtualDriveSLC6();
768
  
769
770
771
  // The drive will not even be opened. so no need for one.
  mockSys.fake.m_pathToDrive["/dev/nst0"] = NULL;
  
772
773
774
  // 4) Create the scheduler
  cta::MockNameServer ns;
  cta::MockRemoteNS rns;
775
  cta::OStoreDBWrapper<cta::objectstore::BackendVFS> db("Unittest");
776
777
778
779
780
  cta::Scheduler scheduler(ns, db, rns);

  // Always use the same requester
  const cta::SecurityIdentity requester;
  
781
  DriveConfig driveConfig("T10D6116", "T10KD6", "/dev/tape_T10D6116", "manual");
782
783
784
785
786
787
788
789
790
791
792
793
  DataTransferConfig castorConf;
  castorConf.bufsz = 1024*1024; // 1 MB memory buffers
  castorConf.nbBufs = 10;
  castorConf.bulkRequestRecallMaxBytes = UINT64_C(100)*1000*1000*1000;
  castorConf.bulkRequestRecallMaxFiles = 1000;
  castorConf.nbDiskThreads = 3;
  castor::messages::AcsProxyDummy acs;
  castor::mediachanger::MmcProxyDummy mmc;
  castor::legacymsg::RmcProxyDummy rmc;
  castor::mediachanger::MediaChangerFacade mc(acs, mmc, rmc);
  castor::server::ProcessCap capUtils;
  castor::messages::TapeserverProxyDummy initialProcess;
794
  DataTransferSession sess("tapeHost", logger, mockSys,
795
    driveConfig, mc, initialProcess, capUtils, castorConf, scheduler);
796
  ASSERT_NO_THROW(sess.execute());
797
798
799
800
801
802
  std::string temp = logger.getLog();
  temp += "";
  ASSERT_EQ("", sess.getVid());
  // We should not have logged any error
  ASSERT_EQ(std::string::npos, logger.getLog().find("LVL=E"));
}
803

804
TEST_F(castor_tape_tapeserver_daemon_DataTransferSessionTest, DataTransferSessionGooddayMigration) {
805
  
Eric Cano's avatar
Eric Cano committed
806
807
808
  // 0) Prepare the logger for everyone
  castor::log::StringLogger logger("tapeServerUnitTest");
  
809
  // 1) prepare the fake scheduler
Eric Cano's avatar
Eric Cano committed
810
  std::string vid = "V12345";
811

Eric Cano's avatar
Eric Cano committed
812
813
814
815
816
  // 3) Prepare the necessary environment (logger, plus system wrapper), 
  castor::tape::System::mockWrapper mockSys;
  mockSys.delegateToFake();
  mockSys.disableGMockCallsCounting();
  mockSys.fake.setupForVirtualDriveSLC6();
817
818
819

  // 4) Create the scheduler
  cta::MockNameServer ns;
820
  cta::MockRemoteFullFS rns;
821
822
823
824
825
826
827
828
829
  cta::OStoreDBWrapper<cta::objectstore::BackendVFS> db("Unittest");
  cta::Scheduler scheduler(ns, db, rns);

  // Always use the same requester
  const cta::SecurityIdentity requester;
  
  // Create the bootstrap admin user and host
  ASSERT_NO_THROW(scheduler.createAdminUserWithoutAuthorizingRequester(requester, requester.getUser(), "admin user"));
  ASSERT_NO_THROW(scheduler.createAdminHostWithoutAuthorizingRequester(requester, requester.getHost(), "admin host"));
Eric Cano's avatar
Eric Cano committed
830
  
831
832
  // create a single copy storage class
  ASSERT_NO_THROW(scheduler.createStorageClass(requester, "SINGLE", 1, 1, "comment"));
Eric Cano's avatar
Eric Cano committed
833
  
834
835
836
837
  // assign it to the root directory
  ASSERT_NO_THROW(scheduler.setDirStorageClass(requester, "/", "SINGLE"));
  
  // create the logical library
838
  ASSERT_NO_THROW(scheduler.createLogicalLibrary(requester, "T10KD6", "the illogical library"));
839
840
841
842
  
  // create the tape pool
  ASSERT_NO_THROW(scheduler.createTapePool(requester, "swimmingpool", 2, "the swimming pool"));
  
843
844
845
846
847
848
849
  cta::MountCriteria immediateMount;
  immediateMount.maxAge = 0;
  immediateMount.maxBytesQueued = 1;
  immediateMount.maxFilesQueued = 1;
  immediateMount.quota = 10;
  ASSERT_NO_THROW(scheduler.setTapePoolMountCriteria("swimmingpool", cta::MountCriteriaByDirection(immediateMount, immediateMount)));
  
850
851
852
853
  // create the route
  ASSERT_NO_THROW(scheduler.createArchiveRoute(requester, "SINGLE", 1, "swimmingpool", "iArchive"));
  
  // create the tape
854
  std::string comment = "the magic tape";
855
  ASSERT_NO_THROW(scheduler.createTape(requester, "V12345", "T10KD6", "swimmingpool", 100000, comment));
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
  
  // List to remember the path of each remote file so that the existence of the
  // files can be tested for at the end of the test
  std::list<std::string> remoteFilePaths;

  //delete is unnecessary
  //pointer with ownership will be passed to the application,
  //which will do the delete
  mockSys.fake.m_pathToDrive["/dev/nst0"] = new castor::tape::tapeserver::drive::FakeDrive();
  
  // We can prepare files for writing on the drive
  {    
    // Label the tape
    castor::tape::tapeFile::LabelSession ls(*mockSys.fake.m_pathToDrive["/dev/nst0"], "V12345");
    mockSys.fake.m_pathToDrive["/dev/nst0"]->rewind();
    
    // schedule the archivals
873
    for(int fseq=1; fseq <= 10 ; fseq ++) { 
874
      // Create a path to a remote source file
875
876
877
      std::ostringstream fileName;
      fileName << "/test" << fseq;
      remoteFilePaths.push_back(fileName.str());
878
      
879
880
881
      // Create the file to be migrated in the fake remote NS
      cta::RemotePath rpath(rns.createFullURL(fileName.str()));
      rns.createFile(rpath.getRaw(), 1000);
882
883
884

      // Schedule the archival of the file
      std::list<std::string> remoteFilePathList;
885
886
      remoteFilePathList.push_back(rns.createFullURL(fileName.str()));
      ASSERT_NO_THROW(scheduler.queueArchiveRequest(requester, remoteFilePathList, fileName.str()));
887
    }
Eric Cano's avatar
Eric Cano committed
888
  }
889
  DriveConfig driveConfig("T10D6116", "T10KD6", "/dev/tape_T10D6116", "manual");
890
891
892
  DataTransferConfig castorConf;
  castorConf.bufsz = 1024*1024; // 1 MB memory buffers
  castorConf.nbBufs = 10;
893
894
  castorConf.bulkRequestRecallMaxBytes = UINT64_C(100)*1000*1000*1000;
  castorConf.bulkRequestRecallMaxFiles = 1000;
895
  castorConf.nbDiskThreads = 1;
896
897
898
899
  castor::messages::AcsProxyDummy acs;
  castor::mediachanger::MmcProxyDummy mmc;
  castor::legacymsg::RmcProxyDummy rmc;
  castor::mediachanger::MediaChangerFacade mc(acs, mmc, rmc);
900
  castor::server::ProcessCap capUtils;
901
  castor::messages::TapeserverProxyDummy initialProcess;
902
  DataTransferSession sess("tapeHost", logger, mockSys, driveConfig, mc, initialProcess, capUtils, castorConf, scheduler);
903
  ASSERT_NO_THROW(sess.execute());
904
905
906
907
  std::string temp = logger.getLog();
  temp += "";
  ASSERT_EQ("V12345", sess.getVid());
  for(auto i=remoteFilePaths.begin(); i!=remoteFilePaths.end(); i++) {
908
    ASSERT_NO_THROW(ns.statFile(requester, *i));
909
    std::unique_ptr<cta::ArchiveFileStatus> stat(ns.statFile(requester, *i));
910
911
912
    ASSERT_NE(NULL, (uint64_t)(stat.get()));
    ASSERT_EQ(0100777, stat->mode);
    ASSERT_EQ(1000, stat->size);
913
  }
Eric Cano's avatar
Eric Cano committed
914
915
}

916
917
918
919
//
// This test is the same as the previous one, except that the files are deleted
// from filesystem immediately. The disk tasks will then fail on open.
///
920
TEST_F(castor_tape_tapeserver_daemon_DataTransferSessionTest, DataTransferSessionMissingFilesMigration) {
921
  
922
923
924
  // 0) Prepare the logger for everyone
  castor::log::StringLogger logger("tapeServerUnitTest");
  
925
  // 1) prepare the fake scheduler
926
  std::string vid = "V12345";
927

928
929
930
931
932
  // 3) Prepare the necessary environment (logger, plus system wrapper), 
  castor::tape::System::mockWrapper mockSys;
  mockSys.delegateToFake();
  mockSys.disableGMockCallsCounting();
  mockSys.fake.setupForVirtualDriveSLC6();
933
934
935

  // 4) Create the scheduler
  cta::MockNameServer ns;
936
  cta::MockRemoteFullFS rns;
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
  cta::OStoreDBWrapper<cta::objectstore::BackendVFS> db("Unittest");
  cta::Scheduler scheduler(ns, db, rns);

  // Always use the same requester
  const cta::SecurityIdentity requester;
  
  // Create the bootstrap admin user and host
  ASSERT_NO_THROW(scheduler.createAdminUserWithoutAuthorizingRequester(requester, requester.getUser(), "admin user"));
  ASSERT_NO_THROW(scheduler.createAdminHostWithoutAuthorizingRequester(requester, requester.getHost(), "admin host"));
  
  // create a single copy storage class
  ASSERT_NO_THROW(scheduler.createStorageClass(requester, "SINGLE", 1, 1, "comment"));
  
  // assign it to the root directory
  ASSERT_NO_THROW(scheduler.setDirStorageClass(requester, "/", "SINGLE"));
  
  // create the logical library
954
  ASSERT_NO_THROW(scheduler.createLogicalLibrary(requester, "T10KD6", "the illogical library"));
955
956
957
  
  // create the tape pool
  ASSERT_NO_THROW(scheduler.createTapePool(requester, "swimmingpool", 2, "the swimming pool"));
958
959
960
961
962
963
964
965

  // Make the pool mount immediately
  cta::MountCriteria immediateMount;
  immediateMount.maxAge = 0;
  immediateMount.maxBytesQueued = 1;
  immediateMount.maxFilesQueued = 1;
  immediateMount.quota = 10;
  ASSERT_NO_THROW(scheduler.setTapePoolMountCriteria("swimmingpool", cta::MountCriteriaByDirection(immediateMount, immediateMount)));
966
967
968
  
  // create the route
  ASSERT_NO_THROW(scheduler.createArchiveRoute(requester, "SINGLE", 1, "swimmingpool", "iArchive"));
969
  
970
  // create the tape
971
  std::string comment = "the magic tape";
972
  ASSERT_NO_THROW(scheduler.createTape(requester, "V12345", "T10KD6", "swimmingpool", 100000, comment));
973
  
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
  // List to remember the path of each remote file so that the existence of the
  // files can be tested for at the end of the test
  std::list<std::string> remoteFilePaths;

  //delete is unnecessary
  //pointer with ownership will be passed to the application,
  //which will do the delete
  mockSys.fake.m_pathToDrive["/dev/nst0"] = new castor::tape::tapeserver::drive::FakeDrive();
  
  // We can prepare files for writing on the drive
  {    
    // Label the tape
    castor::tape::tapeFile::LabelSession ls(*mockSys.fake.m_pathToDrive["/dev/nst0"], "V12345");
    mockSys.fake.m_pathToDrive["/dev/nst0"]->rewind();
    
    // schedule the archivals
    for(int fseq=1; fseq <= 10 ; fseq ++) {      
      // Create a path to a remote destination file
992
993
994
      std::ostringstream fileName;
      fileName << "/test" << fseq;
      remoteFilePaths.push_back(fileName.str());
995
      
996
997
998
999
      // create the file in the remote file system (to be deleted after queueing
      // the request)
      cta::RemotePath rpath(rns.createFullURL(fileName.str()));
      rns.createFile(rpath.getRaw(), 1000);
1000