Skip to content

Commit

Permalink
TESTS: add XrdClVectorCache.cc test
Browse files Browse the repository at this point in the history
  • Loading branch information
apeters1971 committed Jun 6, 2024
1 parent a2b053b commit e1b5439
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
4 changes: 4 additions & 0 deletions tests/XrdCl/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ add_executable(xrdcl-unit-tests
XrdClPoller.cc
XrdClSocket.cc
XrdClUtilsTest.cc
XrdClVectorCache.cc
../../src/XrdApps/XrdClJCachePlugin/XrdClVectorCache.cc
../common/Server.cc
../common/Utils.cc
../common/TestEnv.cc
Expand All @@ -12,9 +14,11 @@ target_link_libraries(xrdcl-unit-tests
XrdCl
XrdXml
XrdUtils
stdc++fs
ZLIB::ZLIB
GTest::GTest
GTest::Main
OpenSSL::Crypto
)

target_include_directories(xrdcl-unit-tests
Expand Down
47 changes: 47 additions & 0 deletions tests/XrdCl/XrdClVectorCache.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#undef NDEBUG

#include "XrdApps/XrdClJCachePlugin/XrdClVectorCache.hh"
#include "XrdSys/XrdSysPlatform.hh"

#include <gtest/gtest.h>

#include <climits>
#include <cstdlib>

using namespace testing;

// Test the JCAche VectorCache class

class VectorCacheTest : public ::testing::Test {};

TEST(VectorCacheTest, Store)
{
XrdCl::ChunkList chunks;
std::string name = "root://localhost//dummy";
std::string prefix = "/tmp/";

char data[100]; // 100 bytes of fake data
char cdata[100]; // 100 bytes of zeroed data

for (auto i=0; i< 100; i++) {
XrdCl::ChunkInfo s(i,1);
chunks.push_back(s);
data[i] = i;
cdata[i] = 0;
}

EXPECT_TRUE(bcmp(data, cdata, 100) != 0) << "Data not zeroed" << std::endl;
VectorCache cacheout ( chunks, name, data, prefix);
EXPECT_TRUE(cacheout.store()) << "Failed to store vector read into cache" << std::endl;
VectorCache cachein ( chunks, name, cdata, prefix);
EXPECT_TRUE(cachein.retrieve()) << "Failed to retrieve vector read from cache" << std::endl;
EXPECT_TRUE(bcmp(data, cdata, 100) == 0) << "Cached data is wrong" << std::endl;
EXPECT_TRUE(truncate("/tmp/d1a4e9081bd37839e4b4f486ed8b13397ce9ffa0198edb586208d6b73e15b19a/3ec7dea73b7880fdce09e1c8f804054ae685e3dbda4d467c71ab2327ea5ad93e",99)==0) << "Failed to truncate cached file" << std::endl;
EXPECT_TRUE(!cachein.retrieve()) << "Truncate cache entry was not seen" << std::endl;
EXPECT_TRUE(unlink("/tmp/d1a4e9081bd37839e4b4f486ed8b13397ce9ffa0198edb586208d6b73e15b19a/3ec7dea73b7880fdce09e1c8f804054ae685e3dbda4d467c71ab2327ea5ad93e") == 0) << "Failed to unlink cached file" << std::endl;
EXPECT_TRUE(!cachein.retrieve()) << "Unlinked cache entry was not seen" << std::endl;
// re-cache the block an check if it is ok
EXPECT_TRUE(cacheout.store()) << "Failed to store vector read into cache" << std::endl;
EXPECT_TRUE(cachein.retrieve()) << "Failed to retrieve vector read from cache" << std::endl;
}

0 comments on commit e1b5439

Please sign in to comment.