Commit 61253b15 authored by David COME's avatar David COME
Browse files

Aim : change WriteFile::WriteFile's test in case of Write_TP

To do so, we had to pass the VolumeInfo (which was already a bit propagated before)
and changed by a previous commit
parent 10f3edec
......@@ -115,8 +115,11 @@ TEST(tapeServer, MountSessionGooddayRecall) {
"V12345", true);
mockSys.fake.m_pathToDrive["/dev/nst0"]->rewind();
// And write to it
castor::tape::tapeserver::client::ClientInterface::VolumeInfo volInfo;
volInfo.vid="V12345";
volInfo.clientType=castor::tape::tapegateway::READ_TP;
castor::tape::tapeFile::WriteSession ws(*mockSys.fake.m_pathToDrive["/dev/nst0"],
"V12345", 0, true);
volInfo , 0, true);
// Write a few files on the virtual tape
// Prepare the data
uint8_t data[1000];
......
......@@ -67,7 +67,7 @@ public:
m_drive(drive), m_reportPacker(repPacker),
m_lastFseq(-1),
m_compress(true) {}
/**
*
* @param lastFseq
......@@ -108,7 +108,7 @@ private:
tape::utils::suppresUnusedVariable(sp);
try {
writeSession.reset(
new castor::tape::tapeFile::WriteSession(m_drive,m_vid,m_lastFseq,m_compress)
new castor::tape::tapeFile::WriteSession(m_drive,m_volInfo,m_lastFseq,m_compress)
);
m_logContext.log(LOG_INFO, "Tape Write session session successfully started");
}
......
......@@ -322,9 +322,13 @@ namespace castor {
return bytes_read;
}
WriteSession::WriteSession(drives::DriveInterface & drive, const std::string &volId, const uint32_t last_fseq, const bool compression) : m_drive(drive), m_vid(volId), m_compressionEnabled(compression), m_corrupted(false), m_locked(false) {
WriteSession::WriteSession(drives::DriveInterface & drive,
const tapeserver::client::ClientInterface::VolumeInfo& volInfo,
const uint32_t last_fseq, const bool compression)
: m_drive(drive), m_vid(volInfo.vid), m_compressionEnabled(compression),
m_corrupted(false), m_locked(false),m_volInfo(volInfo) {
if(!volId.compare("")) {
if(!m_vid.compare("")) {
throw castor::exception::InvalidArgument();
}
......@@ -336,7 +340,7 @@ namespace castor {
} catch (std::exception & e) {
throw TapeFormatError(e.what());
}
HeaderChecker::checkVOL1(vol1, volId); // now we know that we are going to write on the correct tape
HeaderChecker::checkVOL1(vol1, m_vid); // now we know that we are going to write on the correct tape
//if the tape is not empty let's move to the last trailer
if(last_fseq>0) {
uint32_t dst_filemark = last_fseq*3-1; // 3 file marks per file but we want to read the last trailer (hence the -1)
......@@ -408,7 +412,8 @@ namespace castor {
m_open(false), m_nonzeroFileWritten(false), m_numberOfBlocks(0)
{
// Check the sanity of the parameters. fSeq should be >= 1
if (0 == ftm.fileid() || ftm.fseq()<1) {
if ( ws->getVolumeInfo().clientType != castor::tape::tapegateway::WRITE_TP &&
(0 == ftm.fileid() || ftm.fseq()<1)) {
std::stringstream err;
err << "Unexpected fileId in WriteFile::WriteFile (expected != 0, got: "
<< ftm.fileid() << ") or fSeq (expected >=1, got: "
......
......@@ -275,7 +275,7 @@ namespace castor {
*/
PartOfFile m_currentFilePart;
tapeserver::client::ClientInterface::VolumeInfo m_volInfo;
const tapeserver::client::ClientInterface::VolumeInfo m_volInfo;
};
class ReadFile{
......@@ -365,7 +365,9 @@ namespace castor {
* @param last_fseq: fseq of the last active (undeleted) file on tape
* @param compression: set this to true in case the drive has compression enabled (x000GC)
*/
WriteSession(drives::DriveInterface & drive, const std::string &vid, const uint32_t last_fseq, const bool compression) ;
WriteSession(drives::DriveInterface & drive,
const tapeserver::client::ClientInterface::VolumeInfo& volInfo,
const uint32_t last_fseq, const bool compression) ;
/**
* DriveGeneric object referencing the drive used during this write session
......@@ -375,7 +377,7 @@ namespace castor {
/**
* Volume Serial Number
*/
std::string m_vid;
const std::string m_vid;
/**
* set to true if the drive has compression enabled
......@@ -415,6 +417,10 @@ namespace castor {
m_locked = false;
}
const tapeserver::client::ClientInterface::VolumeInfo&
getVolumeInfo() const {
return m_volInfo;
}
private:
/**
......@@ -446,6 +452,8 @@ namespace castor {
* Session lock to be sure that a read session is owned by maximum one WriteFile object
*/
bool m_locked;
const tapeserver::client::ClientInterface::VolumeInfo m_volInfo;
};
class WriteFile {
......
......@@ -67,7 +67,7 @@ namespace UnitTests {
std::string label;
castor::tape::tapegateway::FileToRecallStruct fileToRecall;
castor::tape::tapegateway::FileToMigrateStruct fileToMigrate;
castor::tape::tapeserver::client::ClientInterface::VolumeInfo volInfo;
castor::tape::tapeserver::client::ClientInterface::VolumeInfo volInfo;
};
TEST_F(castorTapeFileTest, throwsWhenLabelingANonEmptyTape) {
......@@ -86,7 +86,7 @@ namespace UnitTests {
TEST_F(castorTapeFileTest, throwsWhenUsingSessionTwice) {
const std::string testString("Hello World!");
castor::tape::tapeFile::WriteSession *ws;
ws = new castor::tape::tapeFile::WriteSession(d, label, 0, true);
ws = new castor::tape::tapeFile::WriteSession(d, volInfo, 0, true);
ASSERT_EQ(ws->m_compressionEnabled, true);
ASSERT_EQ(ws->m_vid.compare(label), 0);
ASSERT_EQ(ws->isCorrupted(), false);
......@@ -108,7 +108,7 @@ namespace UnitTests {
TEST_F(castorTapeFileTest, throwsWhenWritingAnEmptyFileOrSessionCorrupted) {
castor::tape::tapeFile::WriteSession *ws;
ws = new castor::tape::tapeFile::WriteSession(d, label, 0, true);
ws = new castor::tape::tapeFile::WriteSession(d, volInfo, 0, true);
ASSERT_EQ(ws->isCorrupted(), false);
{
castor::tape::tapeFile::WriteFile wf(ws, fileToMigrate, block_size);
......@@ -124,7 +124,7 @@ namespace UnitTests {
TEST_F(castorTapeFileTest, throwsWhenClosingTwice) {
const std::string testString("Hello World!");
castor::tape::tapeFile::WriteSession *ws;
ws = new castor::tape::tapeFile::WriteSession(d, label, 0, true);
ws = new castor::tape::tapeFile::WriteSession(d, volInfo, 0, true);
{
castor::tape::tapeFile::WriteFile wf(ws, fileToMigrate, block_size);
wf.write(testString.c_str(),testString.size());
......@@ -137,7 +137,7 @@ namespace UnitTests {
TEST_F(castorTapeFileTest, throwsWhenWrongBlockSizeOrEOF) {
const std::string testString("Hello World!");
castor::tape::tapeFile::WriteSession *ws;
ws = new castor::tape::tapeFile::WriteSession(d, label, 0, true);
ws = new castor::tape::tapeFile::WriteSession(d, volInfo, 0, true);
{
castor::tape::tapeFile::WriteFile wf(ws, fileToMigrate, block_size);
wf.write(testString.c_str(),testString.size());
......@@ -173,7 +173,7 @@ namespace UnitTests {
//Write AULFile with Hello World
const std::string testString("Hello World!");
castor::tape::tapeFile::WriteSession *ws;
ws = new castor::tape::tapeFile::WriteSession(d, label, 0, true);
ws = new castor::tape::tapeFile::WriteSession(d, volInfo, 0, true);
ASSERT_EQ(ws->m_compressionEnabled, true);
ASSERT_EQ(ws->m_vid.compare(label), 0);
ASSERT_EQ(ws->isCorrupted(), false);
......
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