Commit e7f20708 authored by Steven Murray's avatar Steven Murray
Browse files

Added the unit test named cta_MockNameServerTest.adding_and_getting_tapeFiles

Please note that this test does not pass because the functionality
being tested has not yet been implemented.
parent e638e710
......@@ -41,3 +41,13 @@ cta::TapeFileLocation::TapeFileLocation(
vid(vid),
copyNb(copyNb) {
}
//------------------------------------------------------------------------------
// operator==
//------------------------------------------------------------------------------
bool cta::TapeFileLocation::operator==(const TapeFileLocation &rhs) const {
return fSeq == rhs.fSeq &&
blockId == rhs.blockId &&
vid == rhs.vid &&
copyNb == rhs.copyNb;
}
......@@ -43,6 +43,13 @@ struct TapeFileLocation {
*/
TapeFileLocation(const uint64_t fSeq, const uint64_t blockId, const std::string &vid, const uint8_t copyNb);
/**
* Equality operator.
*
* @param ths The right hand side of the operator.
*/
bool operator==(const TapeFileLocation &rhs) const;
/**
* The sequence number of the file.
*/
......
......@@ -46,6 +46,13 @@ cta::Checksum::Checksum(const ChecksumType &type, const ByteArray &byteArray):
m_byteArray(byteArray) {
}
//------------------------------------------------------------------------------
// operator==
//------------------------------------------------------------------------------
bool cta::Checksum::operator==(const Checksum &rhs) const {
return m_type == rhs.m_type && m_byteArray == rhs.m_byteArray;
}
//------------------------------------------------------------------------------
// getType
//------------------------------------------------------------------------------
......
......@@ -60,6 +60,13 @@ public:
*/
Checksum(const ChecksumType &type, const ByteArray &byteArray);
/**
* Equality operator.
*
* @param ths The right hand side of the operator.
*/
bool operator==(const Checksum &rhs) const;
/**
* Returns the type of the checksum.
*
......
......@@ -26,3 +26,14 @@ cta::NameServerTapeFile::NameServerTapeFile():
size(0),
compressedSize(0) {
}
//------------------------------------------------------------------------------
// operator==
//------------------------------------------------------------------------------
bool cta::NameServerTapeFile::operator==(const NameServerTapeFile &rhs) const {
return copyNb == rhs.copyNb &&
tapeFileLocation == rhs.tapeFileLocation &&
size == rhs.size &&
compressedSize == rhs.compressedSize &&
checksum == rhs.checksum;
}
......@@ -35,6 +35,13 @@ struct NameServerTapeFile {
*/
NameServerTapeFile();
/**
* Equality operator.
*
* @param ths The right hand side of the operator.
*/
bool operator==(const NameServerTapeFile &rhs) const;
/**
* The copy number of the tape file where copy numbers start from 1.
* Please note that copy number 0 is an ivalid copy number.
......
......@@ -201,4 +201,62 @@ TEST_F(cta_MockNameServerTest, storageClass_inheritance) {
}
}
TEST_F(cta_MockNameServerTest, adding_and_getting_tapeFiles) {
using namespace cta;
std::unique_ptr<MockNameServer> ns;
ASSERT_NO_THROW(ns.reset(new MockNameServer()));
const std::string archiveFileName = "file1";
const std::string archiveFilePath = std::string("/") + archiveFileName;
const uint64_t archiveFileSize = 256 * 1024;
const std::string vid = "V12345";
const uint8_t copyNb = 1;
const uint64_t fseq = 1;
// block 0: VOL
// block 1: HDR1
// block 2: HDR2
// block 3: UHL1
// block 4: File mark
// block 5: First block of user file
const uint64_t blockId = 5;
const uint32_t adlerChecksum = 0x11223344;
// Create a file entry in the archive namespace
ASSERT_NO_THROW(ns->setOwner(s_adminOnAdminHost, "/", s_user));
ASSERT_NO_THROW(ns->createFile(s_userOnUserHost, "/file1", 0666,
archiveFileSize));
{
ArchiveDirIterator itor;
ASSERT_NO_THROW(itor = ns->getDirContents(s_userOnUserHost, "/"));
ASSERT_EQ(itor.hasMore(), true);
ASSERT_EQ(itor.next().name, archiveFileName);
ASSERT_EQ(itor.hasMore(), false);
}
// Add a tape file entry to the file entry in the archive namespace
NameServerTapeFile tapeFile;
tapeFile.copyNb = copyNb;
tapeFile.tapeFileLocation.fSeq = fseq;
tapeFile.tapeFileLocation.blockId = blockId;
tapeFile.tapeFileLocation.vid = vid;
tapeFile.tapeFileLocation.copyNb = copyNb;
tapeFile.size = archiveFileSize;
tapeFile.compressedSize = archiveFileSize; // No compression
cta::Checksum tapeFileChecksum(Checksum::CHECKSUMTYPE_ADLER32,
cta::ByteArray(adlerChecksum));
tapeFile.checksum = tapeFileChecksum;
ASSERT_NO_THROW(ns->addTapeFile(
s_userOnUserHost,
archiveFilePath,
tapeFile));
// Get back the tape file entry
std::list<NameServerTapeFile> tapeFiles;
ASSERT_NO_THROW(tapeFiles = ns->getTapeFiles(s_userOnUserHost,
archiveFilePath));
ASSERT_EQ(1, tapeFiles.size());
ASSERT_TRUE(tapeFile == tapeFiles.front());
}
} // namespace unitTests
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