Skip to content

Commit

Permalink
[XrdCl] Add xattr tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
simonmichal authored and osschar committed Oct 10, 2019
1 parent a463d33 commit e188dde
Show file tree
Hide file tree
Showing 2 changed files with 198 additions and 0 deletions.
97 changes: 97 additions & 0 deletions tests/XrdClTests/FileSystemTest.cc
Expand Up @@ -51,6 +51,7 @@ class FileSystemTest: public CppUnit::TestCase
CPPUNIT_TEST( DirListTest );
CPPUNIT_TEST( SendInfoTest );
CPPUNIT_TEST( PrepareTest );
CPPUNIT_TEST( XAttrTest );
CPPUNIT_TEST( PlugInTest );
CPPUNIT_TEST_SUITE_END();
void LocateTest();
Expand All @@ -67,6 +68,7 @@ class FileSystemTest: public CppUnit::TestCase
void DirListTest();
void SendInfoTest();
void PrepareTest();
void XAttrTest();
void PlugInTest();
};

Expand Down Expand Up @@ -630,6 +632,101 @@ void FileSystemTest::PrepareTest()
delete id;
}

//------------------------------------------------------------------------------
// Extended attributes test
//------------------------------------------------------------------------------
void FileSystemTest::XAttrTest()
{
using namespace XrdCl;

//----------------------------------------------------------------------------
// Get the environment variables
//----------------------------------------------------------------------------
Env *testEnv = TestEnv::GetEnv();

std::string address;
std::string remoteFile;

CPPUNIT_ASSERT( testEnv->GetString( "DiskServerURL", address ) );
CPPUNIT_ASSERT( testEnv->GetString( "RemoteFile", remoteFile ) );

URL url( address );
CPPUNIT_ASSERT( url.IsValid() );

FileSystem fs( url );

std::map<std::string, std::string> attributes
{
std::make_pair( "version", "v1.2.3-45" ),
std::make_pair( "checksum", "2ccc0e85556a6cd193dd8d2b40aab50c" ),
std::make_pair( "index", "4" )
};

//----------------------------------------------------------------------------
// Test SetXAttr
//----------------------------------------------------------------------------
std::vector<xattr_t> attrs;
for( auto &a : attributes )
attrs.push_back( std::make_tuple( a.first, a.second ) );

std::vector<XAttrStatus> *result1 = 0;
CPPUNIT_ASSERT_XRDST( fs.SetXAttr( remoteFile, attrs, result1 ) );

for( auto &xst : *result1 )
CPPUNIT_ASSERT_XRDST( xst.status );

delete result1;
result1 = 0;

//----------------------------------------------------------------------------
// Test GetXAttr
//----------------------------------------------------------------------------
std::vector<std::string> names;
for( auto &a : attributes )
names.push_back( a.first );

std::vector<XAttr> *result2 = 0;
CPPUNIT_ASSERT_XRDST( fs.GetXAttr( remoteFile, names, result2 ) );

for( auto &xa : *result2 )
{
CPPUNIT_ASSERT_XRDST( xa.status );
auto match = attributes.find( xa.name );
CPPUNIT_ASSERT( match != attributes.end() );
CPPUNIT_ASSERT( match->second == xa.value );
}

delete result2;
result2 = 0;

//----------------------------------------------------------------------------
// Test ListXAttr
//----------------------------------------------------------------------------
CPPUNIT_ASSERT_XRDST( fs.ListXAttr( remoteFile, result2 ) );

for( auto &xa : *result2 )
{
CPPUNIT_ASSERT_XRDST( xa.status );
auto match = attributes.find( xa.name );
CPPUNIT_ASSERT( match != attributes.end() );
CPPUNIT_ASSERT( match->second == xa.value );
}

delete result2;
result2 = 0;

//----------------------------------------------------------------------------
// Test DelXAttr
//----------------------------------------------------------------------------
CPPUNIT_ASSERT_XRDST( fs.DelXAttr( remoteFile, names, result1 ) );

for( auto &xst : *result1 )
CPPUNIT_ASSERT_XRDST( xst.status );

delete result1;
result1 = 0;
}

//------------------------------------------------------------------------------
// Plug-in test
//------------------------------------------------------------------------------
Expand Down
101 changes: 101 additions & 0 deletions tests/XrdClTests/FileTest.cc
Expand Up @@ -51,6 +51,7 @@ class FileTest: public CppUnit::TestCase
CPPUNIT_TEST( VectorReadTest );
CPPUNIT_TEST( VectorWriteTest );
CPPUNIT_TEST( VirtualRedirectorTest );
CPPUNIT_TEST( XAttrTest );
CPPUNIT_TEST( PlugInTest );
CPPUNIT_TEST_SUITE_END();
void RedirectReturnTest();
Expand All @@ -60,6 +61,7 @@ class FileTest: public CppUnit::TestCase
void VectorReadTest();
void VectorWriteTest();
void VirtualRedirectorTest();
void XAttrTest();
void PlugInTest();
};

Expand Down Expand Up @@ -707,6 +709,105 @@ void FileTest::VirtualRedirectorTest()
CPPUNIT_ASSERT_XRDST( process.Run(0) );
}

void FileTest::XAttrTest()
{
using namespace XrdCl;

//----------------------------------------------------------------------------
// Get the environment variables
//----------------------------------------------------------------------------
Env *testEnv = TestEnv::GetEnv();

std::string address;
std::string dataPath;

CPPUNIT_ASSERT( testEnv->GetString( "DiskServerURL", address ) );
CPPUNIT_ASSERT( testEnv->GetString( "DataPath", dataPath ) );

std::string filePath = dataPath + "/a048e67f-4397-4bb8-85eb-8d7e40d90763.dat";
std::string fileUrl = address + "/" + filePath;

URL url( address );
CPPUNIT_ASSERT( url.IsValid() );


File file;
CPPUNIT_ASSERT_XRDST( file.Open( fileUrl, OpenFlags::Update ) );

std::map<std::string, std::string> attributes
{
std::make_pair( "version", "v1.2.3-45" ),
std::make_pair( "checksum", "2ccc0e85556a6cd193dd8d2b40aab50c" ),
std::make_pair( "index", "4" )
};

//----------------------------------------------------------------------------
// Test SetXAttr
//----------------------------------------------------------------------------
std::vector<xattr_t> attrs;
for( auto &a : attributes )
attrs.push_back( std::make_tuple( a.first, a.second ) );

std::vector<XAttrStatus> *result1 = 0;
CPPUNIT_ASSERT_XRDST( file.SetXAttr( attrs, result1 ) );

for( auto &xst : *result1 )
CPPUNIT_ASSERT_XRDST( xst.status );

delete result1;
result1 = 0;

//----------------------------------------------------------------------------
// Test GetXAttr
//----------------------------------------------------------------------------
std::vector<std::string> names;
for( auto &a : attributes )
names.push_back( a.first );

std::vector<XAttr> *result2 = 0;
CPPUNIT_ASSERT_XRDST( file.GetXAttr( names, result2 ) );

for( auto &xa : *result2 )
{
CPPUNIT_ASSERT_XRDST( xa.status );
auto match = attributes.find( xa.name );
CPPUNIT_ASSERT( match != attributes.end() );
CPPUNIT_ASSERT( match->second == xa.value );
}

delete result2;
result2 = 0;

//----------------------------------------------------------------------------
// Test ListXAttr
//----------------------------------------------------------------------------
CPPUNIT_ASSERT_XRDST( file.ListXAttr( result2 ) );

for( auto &xa : *result2 )
{
CPPUNIT_ASSERT_XRDST( xa.status );
auto match = attributes.find( xa.name );
CPPUNIT_ASSERT( match != attributes.end() );
CPPUNIT_ASSERT( match->second == xa.value );
}

delete result2;
result2 = 0;

//----------------------------------------------------------------------------
// Test DelXAttr
//----------------------------------------------------------------------------
CPPUNIT_ASSERT_XRDST( file.DelXAttr( names, result1 ) );

for( auto &xst : *result1 )
CPPUNIT_ASSERT_XRDST( xst.status );

delete result1;
result1 = 0;

CPPUNIT_ASSERT_XRDST( file.Close() );
}

//------------------------------------------------------------------------------
// Plug-in test
//------------------------------------------------------------------------------
Expand Down

0 comments on commit e188dde

Please sign in to comment.