Commit f2c15c79 authored by Daniele Kruse's avatar Daniele Kruse
Browse files

Fixed 2 more test cases of castor_tape_tapeserver_daemon_DataTransferSessionTest

parent 939a35fa
......@@ -87,7 +87,7 @@ castor::tape::tapeserver::daemon::Session::EndOfSessionAction
// Create a sticky thread name, which will be overridden by the other threads
lc.pushOrReplace(log::Param("thread", "MainThread"));
// 2a) Get initial information from the client
std::unique_ptr<cta::TapeMount> tapeMount(m_scheduler.getNextMount(m_driveConfig.getLogicalLibrary(), m_driveConfig.getUnitName())); //getNextMount throws not implemented exception, but can return NULL
std::unique_ptr<cta::TapeMount> tapeMount(m_scheduler.getNextMount(m_driveConfig.getLogicalLibrary(), m_driveConfig.getUnitName()));
// No mount to be done found, that was fast...
if (!tapeMount.get())
return MARK_DRIVE_AS_UP;
......
......@@ -278,7 +278,7 @@ TEST_F(castor_tape_tapeserver_daemon_DataTransferSessionTest, DataTransferSessio
// Schedule the retrieval of the file
std::list<std::string> archiveFilePaths;
archiveFilePaths.push_back(archiveFilePath.str());
/*ASSERT_NO_THROW*/(scheduler. queueRetrieveRequest(
ASSERT_NO_THROW(scheduler.queueRetrieveRequest(
requester,
archiveFilePaths,
remoteFilePath.str()));
......@@ -355,6 +355,20 @@ TEST_F(castor_tape_tapeserver_daemon_DataTransferSessionTest, DataTransferSessio
// 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", ""));
ASSERT_NO_THROW(scheduler.createTape(requester, "V12345", "T10KD6", "TapePool", 10*1000*1000, "8000GC", ""));
// 5) Prepare files for reading by writing them to the mock system
{
// Label the tape
......@@ -371,17 +385,18 @@ TEST_F(castor_tape_tapeserver_daemon_DataTransferSessionTest, DataTransferSessio
// so that it is in sync
uint8_t data[1000];
castor::tape::SCSI::Structures::zeroStruct(&data);
for (int fseq=1; fseq <= 10 ; fseq ++) {
int fseq=1;
{
// Create a path to a remote destination file
std::ostringstream remoteFilePath;
remoteFilePath << "file:" << m_tmpDir << "/test" << fseq;
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 = 256*1024;
const uint64_t archiveFileSize = 1000;
ASSERT_NO_THROW(ns.createFile(
requester,
archiveFilePath.str(),
......@@ -396,7 +411,7 @@ TEST_F(castor_tape_tapeserver_daemon_DataTransferSessionTest, DataTransferSessio
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.getPosition();
ftr->nameServerTapeFile.tapeFileLocation.blockId = wf.getBlockId();
ftr->remotePath = remoteFilePath.str();
// Write the data (one block)
wf.write(data, sizeof(data));
......@@ -408,7 +423,7 @@ TEST_F(castor_tape_tapeserver_daemon_DataTransferSessionTest, DataTransferSessio
cta::NameServerTapeFile tapeFile;
tapeFile.copyNb = 1;
tapeFile.tapeFileLocation.fSeq = fseq + 10000;
tapeFile.tapeFileLocation.blockId = wf.getPosition() + 10000;
tapeFile.tapeFileLocation.blockId = wf.getBlockId() + 10000;
tapeFile.tapeFileLocation.vid = volInfo.vid;
tapeFile.tapeFileLocation.copyNb = 1;
tapeFile.size = archiveFileSize;
......@@ -424,7 +439,7 @@ TEST_F(castor_tape_tapeserver_daemon_DataTransferSessionTest, DataTransferSessio
// Schedule the retrieval of the file
std::list<std::string> archiveFilePaths;
archiveFilePaths.push_back(archiveFilePath.str());
ASSERT_NO_THROW(scheduler. queueRetrieveRequest(
ASSERT_NO_THROW(scheduler.queueRetrieveRequest(
requester,
archiveFilePaths,
remoteFilePath.str()));
......@@ -455,14 +470,8 @@ TEST_F(castor_tape_tapeserver_daemon_DataTransferSessionTest, DataTransferSessio
ASSERT_EQ("V12345", sess.getVid());
// 9) Check the remote files exist and have the correct size
for(auto pathItor = remoteFilePaths.cbegin(); pathItor !=
remoteFilePaths.cend(); pathItor++) {
struct stat statBuf;
bzero(&statBuf, sizeof(statBuf));
const int statRc = stat(pathItor->c_str(), &statBuf);
ASSERT_EQ(0, statRc);
ASSERT_EQ(256*1024, statBuf.st_size);
}
std::string temp = logger.getLog();
ASSERT_NE(std::string::npos, logger.getLog().find("trying to position beyond the end of data"));
}
TEST_F(castor_tape_tapeserver_daemon_DataTransferSessionTest, DataTransferSessionNoSuchDrive) {
......@@ -494,7 +503,102 @@ TEST_F(castor_tape_tapeserver_daemon_DataTransferSessionTest, DataTransferSessio
// Always use the same requester
const cta::SecurityIdentity requester;
DriveConfig driveConfig("T10D6116", "T10KD6", "/dev/noSuchTape", "manual");
// 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", ""));
ASSERT_NO_THROW(scheduler.createTape(requester, "V12345", "T10KD6", "TapePool", 10*1000*1000, "8000GC", ""));
// 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,
archiveFileSize));
// Write the file to tape
std::unique_ptr<cta::RetrieveJob> ftr(new MockRetrieveJob());
std::unique_ptr<cta::ArchiveJob> ftm_temp(new MockArchiveJob());
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
cta::Checksum tapeFileChecksum(cta::Checksum::CHECKSUMTYPE_ADLER32,
cta::ByteArray(cta::Utils::getAdler32(data, sizeof data)));
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");
DataTransferConfig castorConf;
castorConf.bufsz = 1024;
castorConf.nbBufs = 10;
......@@ -508,7 +612,7 @@ TEST_F(castor_tape_tapeserver_daemon_DataTransferSessionTest, DataTransferSessio
driveConfig, mc, initialProcess, capUtils, castorConf, scheduler);
ASSERT_NO_THROW(sess.execute());
std::string temp = logger.getLog();
ASSERT_NE(std::string::npos, logger.getLog().find("Drive not found on this path"));
ASSERT_NE(std::string::npos, logger.getLog().find("Could not stat path: /dev/noSuchDrive"));
}
TEST_F(castor_tape_tapeserver_daemon_DataTransferSessionTest, DataTransferSessionFailtoMount) {
......
......@@ -68,6 +68,9 @@ std::string castor::tape::tapeserver::drive::FakeDrive::getSerialNumber() {
throw castor::exception::Exception("FakeDrive::getSerialNumber Not implemented");
}
void castor::tape::tapeserver::drive::FakeDrive::positionToLogicalObject(uint32_t blockId) {
if(blockId > m_tape.size()-1) {
throw castor::exception::Exception("FakeDrive::trying to position beyond the end of data");
}
m_currentPosition = blockId;
}
castor::tape::tapeserver::drive::positionInfo castor::tape::tapeserver::drive::FakeDrive::getPositionInfo() {
......@@ -161,9 +164,9 @@ void castor::tape::tapeserver::drive::FakeDrive::writeSyncFileMarks(size_t count
if(count==0) return;
m_tape.resize(m_currentPosition+count);
for(size_t i=0; i<count; ++i) {
m_tape[m_currentPosition].data = filemark;
m_tape.at(m_currentPosition).data = filemark;
// We consider the file mark takes "no space"
m_tape[m_currentPosition].remainingSpaceAfter = getRemaingSpace(m_currentPosition);
m_tape.at(m_currentPosition).remainingSpaceAfter = getRemaingSpace(m_currentPosition);
m_currentPosition++;
}
}
......@@ -185,15 +188,15 @@ void castor::tape::tapeserver::drive::FakeDrive::writeBlock(const void * data, s
remainingSpaceAfterBlock = getRemaingSpace(m_currentPosition) - count;
}
m_tape.resize(m_currentPosition+1);
m_tape[m_currentPosition].data.assign((const char *)data, count);
m_tape[m_currentPosition].remainingSpaceAfter = remainingSpaceAfterBlock;
m_tape.at(m_currentPosition).data.assign((const char *)data, count);
m_tape.at(m_currentPosition).remainingSpaceAfter = remainingSpaceAfterBlock;
m_currentPosition++;
}
ssize_t castor::tape::tapeserver::drive::FakeDrive::readBlock(void *data, size_t count) {
if(count < m_tape[m_currentPosition].data.size()) {
if(count < m_tape.at(m_currentPosition).data.size()) {
throw castor::exception::Exception("Block size too small in FakeDrive::readBlock");
}
size_t bytes_copied = m_tape[m_currentPosition].data.copy((char *)data, m_tape[m_currentPosition].data.size());
size_t bytes_copied = m_tape.at(m_currentPosition).data.copy((char *)data, m_tape.at(m_currentPosition).data.size());
m_currentPosition++;
return bytes_copied;
}
......@@ -213,19 +216,19 @@ void castor::tape::tapeserver::drive::FakeDrive::readExactBlock(void *data, size
if(count != m_tape.at(m_currentPosition).data.size()) {
std::stringstream exc;
exc << "Wrong block size in FakeDrive::readExactBlock. Expected: " << count
<< " Found: " << m_tape[m_currentPosition].data.size()
<< " Found: " << m_tape.at(m_currentPosition).data.size()
<< " Position: " << m_currentPosition
<< " String: " << m_tape[m_currentPosition].data << std::endl;
<< " String: " << m_tape.at(m_currentPosition).data << std::endl;
exc << contentToString();
throw castor::exception::Exception(exc.str());
}
if(count != m_tape[m_currentPosition].data.copy((char *)data, count)) {
if(count != m_tape.at(m_currentPosition).data.copy((char *)data, count)) {
throw castor::exception::Exception("Failed FakeDrive::readExactBlock");
}
m_currentPosition++;
}
void castor::tape::tapeserver::drive::FakeDrive::readFileMark(std::string context) {
if(m_tape[m_currentPosition].data.compare(filemark)) {
if(m_tape.at(m_currentPosition).data.compare(filemark)) {
throw castor::exception::Exception("Failed FakeDrive::readFileMark");
}
m_currentPosition++;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment