Commit 51b7a1c7 authored by Steven Murray's avatar Steven Murray
Browse files

Added MockNameServer unit test for double copy tape files

parent d364600a
......@@ -201,8 +201,8 @@ TEST_F(cta_MockNameServerTest, storageClass_inheritance) {
}
}
TEST_F(cta_MockNameServerTest, adding_and_getting_tapeFiles) {
using namespace cta;
TEST_F(cta_MockNameServerTest, add_and_get_1_tapeFile) {
using namespace cta;
std::unique_ptr<MockNameServer> ns;
ASSERT_NO_THROW(ns.reset(new MockNameServer()));
......@@ -210,17 +210,61 @@ TEST_F(cta_MockNameServerTest, adding_and_getting_tapeFiles) {
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;
const Checksum checksum = cta::Checksum(Checksum::CHECKSUMTYPE_ADLER32,
ByteArray((uint32_t)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 tapeFile1;
tapeFile1.copyNb = 1;
tapeFile1.tapeFileLocation.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;
tapeFile1.tapeFileLocation.blockId = 5;
tapeFile1.tapeFileLocation.vid = "V12345";
tapeFile1.tapeFileLocation.copyNb = 1;
tapeFile1.size = archiveFileSize;
tapeFile1.compressedSize = archiveFileSize; // No compression
tapeFile1.checksum = checksum;
ASSERT_NO_THROW(ns->addTapeFile(
s_userOnUserHost,
archiveFilePath,
tapeFile1));
// 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(tapeFile1 == tapeFiles.front());
}
TEST_F(cta_MockNameServerTest, add_and_get_2_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 Checksum checksum = cta::Checksum(Checksum::CHECKSUMTYPE_ADLER32,
ByteArray((uint32_t)0x11223344));
// Create a file entry in the archive namespace
ASSERT_NO_THROW(ns->setOwner(s_adminOnAdminHost, "/", s_user));
......@@ -235,28 +279,55 @@ TEST_F(cta_MockNameServerTest, adding_and_getting_tapeFiles) {
}
// 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;
NameServerTapeFile tapeFile1;
tapeFile1.copyNb = 1;
tapeFile1.tapeFileLocation.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
tapeFile1.tapeFileLocation.blockId = 5;
tapeFile1.tapeFileLocation.vid = "V12345";
tapeFile1.tapeFileLocation.copyNb = 1;
tapeFile1.size = archiveFileSize;
tapeFile1.compressedSize = archiveFileSize; // No compression
tapeFile1.checksum = checksum;
ASSERT_NO_THROW(ns->addTapeFile(
s_userOnUserHost,
archiveFilePath,
tapeFile1));
// Add another tape file entry to the file entry in the archive namespace
NameServerTapeFile tapeFile2;
tapeFile2.copyNb = 2;
tapeFile2.tapeFileLocation.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
tapeFile2.tapeFileLocation.blockId = 5;
tapeFile2.tapeFileLocation.vid = "V67890";
tapeFile2.tapeFileLocation.copyNb = 2;
tapeFile2.size = archiveFileSize;
tapeFile2.compressedSize = archiveFileSize; // No compression
tapeFile2.checksum = checksum;
ASSERT_NO_THROW(ns->addTapeFile(
s_userOnUserHost,
archiveFilePath,
tapeFile));
tapeFile2));
// 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());
ASSERT_EQ(2, tapeFiles.size());
ASSERT_TRUE(tapeFile1 == tapeFiles.front());
tapeFiles.pop_front();
ASSERT_TRUE(tapeFile2 == 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