From ccab469c577c31afed21c59e4109ec140564741a Mon Sep 17 00:00:00 2001 From: Jack Del Vecchio Date: Wed, 20 Nov 2024 15:33:03 -0500 Subject: [PATCH] Add tests for parseFileName to datest.cpp - Added the tests for constructPartFilename back and removed deprecated calls --- dali/datest/datest.cmake | 4 +- dali/datest/datest.cpp | 83 ++++++++++++++++++++++++++++++++- dali/dfuXRefLib/dfuxreflib.hpp | 1 + testing/unittests/dalitests.cpp | 1 + 4 files changed, 87 insertions(+), 2 deletions(-) diff --git a/dali/datest/datest.cmake b/dali/datest/datest.cmake index 60ae18153b6..05d41992772 100644 --- a/dali/datest/datest.cmake +++ b/dali/datest/datest.cmake @@ -38,6 +38,7 @@ include_directories ( ${HPCC_SOURCE_DIR}/fs/dafsstream ${HPCC_SOURCE_DIR}/rtl/include ${HPCC_SOURCE_DIR}/rtl/eclrtl + ${HPCC_SOURCE_DIR}/dali/dfuXRefLib ) HPCC_ADD_EXECUTABLE ( datest ${SRCS} ) @@ -50,7 +51,8 @@ target_link_libraries ( datest dafsstream eclrtl wsdfuaccess - dalibase + dalibase + dfuXRefLib ${CppUnit_LIBRARIES} ) diff --git a/dali/datest/datest.cpp b/dali/datest/datest.cpp index 62a0468da85..0547a739a4d 100644 --- a/dali/datest/datest.cpp +++ b/dali/datest/datest.cpp @@ -37,6 +37,8 @@ #include "rtlformat.hpp" +#include "dfuxreflib.hpp" + #include "jptree.hpp" #include "wsdfuaccess.hpp" @@ -78,6 +80,7 @@ static void addTestFile(const char *name,unsigned n) StringBuffer partmask; getPartMask(partmask,name,n); StringBuffer path; + IStoragePlane *plane = getDataStoragePlane("mystorageplane", true); for (unsigned m=0; merrorMessage(msg); + e->Release(); + assertex(strcmp(msg.str(), "Could not find matching prefix in plane definition for file /test/myname._1_of_3")==0); + } + + // A file with a storage plane that has numDevices>1 but no stripe number in the path throws an exception + try { + testParseFileName("/var/lib/HPCCSystems/hpcc-data-two/test/myname.42_of_100", mname.clear(), num, max, replicate); + assertex(false); + } catch (IException *e) { + StringBuffer msg; + e->errorMessage(msg); + e->Release(); + assertex(strcmp(msg.str(), "In storage plane definition numDevices>1, but no stripe sub-directory found in file /var/lib/HPCCSystems/hpcc-data-two/test/myname.42_of_100")==0); + } + + // A file where the dir-per-part number does not match the part number + try { + testParseFileName("/var/lib/HPCCSystems/hpcc-data-two/d1/test/42/myname._43_of_100", mname.clear(), num, max, replicate); + assertex(false); + } catch (IException *e) { + StringBuffer msg; + e->errorMessage(msg); + e->Release(); + assertex(strcmp(msg.str(), "Dir-per-part # does not match part # of file /var/lib/HPCCSystems/hpcc-data-two/d1/test/42/myname._43_of_100")==0); + } + + printf("All parseFileName tests passed\n"); +} + void usage(const char *error=NULL) { if (error) printf("%s\n", error); printf("usage: DATEST * [/test [] [/NITER ]\n"); - printf("where name = RANDTEST | DFS | QTEST | QTEST2 | SESSION | LOCKS | SDS1 | SDS2 | XPATHS| STRESS | STRESS2 | SHUTDOWN | EXTERNAL | SUBLOCKS | SUBSCRIPTION | CONNECTIONSUBS | MULTIFILE | NODESUBS | DFUSTREAMREAD | DFUSTREAMWRITE | DFUSTREAMCOPY\n"); + printf("where name = RANDTEST | DFS | QTEST | QTEST2 | SESSION | LOCKS | SDS1 | SDS2 | XPATHS| STRESS | STRESS2 | SHUTDOWN | EXTERNAL | SUBLOCKS | SUBSCRIPTION | CONNECTIONSUBS | MULTIFILE | NODESUBS | DFUSTREAMREAD | DFUSTREAMWRITE | DFUSTREAMCOPY | PARSEFILENAME\n"); printf("eg: datest . /test QTEST put -- one coven server running locally, running qtest with param \"put\"\n"); printf(" datest eq0001016 eq0001017 -- two coven servers, use default test %s\n", DEFAULT_TEST); } @@ -3336,6 +3410,10 @@ int main(int argc, char* argv[]) EnableSEHtoExceptionMapping(); try { + //NB: required initialization for anything that may call getGlobalConfig*() or getComponentConfig*() + Owned globals = loadConfiguration(defaultYaml, (const char **)argv, "datest", nullptr, nullptr, nullptr, nullptr, false); + initializeStorageGroups(true); + StringBuffer cmd; splitFilename(argv[0], NULL, NULL, &cmd, NULL); StringBuffer lf; @@ -3475,6 +3553,7 @@ int main(int argc, char* argv[]) case 10: TestSubLocks(); break; case 11: TestSDS3(group); break; case 12: TestNodeSubs(); break; + case 13: TestParseFileName(); break; } } else if (TEST("DFS")) @@ -3529,6 +3608,8 @@ int main(int argc, char* argv[]) testDfuStreamWrite(testParams.ordinality() ? testParams.item(0) : nullptr); else if (TEST("DFUSTREAMCOPY")) testDfuStreamCopy(testParams.ordinality() ? testParams.item(0) : nullptr); + else if (TEST("PARSEFILENAME")) + TestParseFileName(); // else if (TEST("DALILOG")) // testDaliLog(testParams.ordinality()&&0!=atoi(testParams.item(0))); else diff --git a/dali/dfuXRefLib/dfuxreflib.hpp b/dali/dfuXRefLib/dfuxreflib.hpp index 691aecca6c4..8bb88634a2f 100644 --- a/dali/dfuXRefLib/dfuxreflib.hpp +++ b/dali/dfuXRefLib/dfuxreflib.hpp @@ -42,5 +42,6 @@ extern DFUXREFLIB_API IPropertyTree * runXRefCluster(const char *cluster,IXRefN // this will use sasha if enabled extern DFUXREFLIB_API void testGetDir(); +extern DFUXREFLIB_API bool testParseFileName(const char *name,StringBuffer &mname,unsigned &num,unsigned &max,bool &replicate); #endif diff --git a/testing/unittests/dalitests.cpp b/testing/unittests/dalitests.cpp index fbc7c21478a..434e873d16d 100644 --- a/testing/unittests/dalitests.cpp +++ b/testing/unittests/dalitests.cpp @@ -477,6 +477,7 @@ class CDaliTestsStress : public CppUnit::TestFixture ClusterPartDiskMapSpec mspec; Owned grp = createIGroup("10.150.10.1-3"); RemoteFilename rfn; + IStoragePlane *plane = getDataStoragePlane("mystorageplane", true); for (unsigned i=0;i<3;i++) for (unsigned ic=0;ic