From a3789bbe5c17683fa20be031cf33ec22956a539e Mon Sep 17 00:00:00 2001 From: Patrick LeBlanc Date: Thu, 4 Apr 2019 12:43:59 -0500 Subject: [PATCH] Added add'l copyFile tests, fixed a bug. --- src/IOCoordinator.cpp | 6 ++++++ src/unit_tests.cpp | 50 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+) diff --git a/src/IOCoordinator.cpp b/src/IOCoordinator.cpp index 4f2ca9328..f3b75ee4e 100755 --- a/src/IOCoordinator.cpp +++ b/src/IOCoordinator.cpp @@ -608,6 +608,12 @@ int IOCoordinator::copyFile(const char *filename1, const char *filename2) int err; char errbuf[80]; + if (!bf::exists(metaFile1)) + { + errno = ENOENT; + return -1; + } + if (bf::exists(metaFile2)) deleteMetaFile(metaFile2); // since we don't implement mkdir(), assume the caller did that and diff --git a/src/unit_tests.cpp b/src/unit_tests.cpp index 8de2fa668..4afec7edf 100755 --- a/src/unit_tests.cpp +++ b/src/unit_tests.cpp @@ -1339,6 +1339,19 @@ void IOCCopyFile1() void IOCCopyFile2() { // call IOC::copyFile() with non-existant file + IOCoordinator *ioc = IOCoordinator::get(); + + bf::path metaPath = ioc->getMetadataPath(); + bf::remove(metaPath/"not-there.meta"); + bf::remove(metaPath/"not-there2.meta"); + + int err = ioc->copyFile("not-there", "not-there2"); + assert(err); + assert(errno == ENOENT); + assert(!bf::exists(metaPath/"not-there.meta")); + assert(!bf::exists(metaPath/"not-there2.meta")); + + cout << "IOC copy file 2 OK" << endl; } void IOCCopyFile3() @@ -1349,6 +1362,40 @@ void IOCCopyFile3() call ioc::copyFile() verify dest file exists */ + IOCoordinator *ioc = IOCoordinator::get(); + Cache *cache = Cache::get(); + CloudStorage *cs = CloudStorage::get(); + + bf::path metaPath = ioc->getMetadataPath(); + bf::path journalPath = ioc->getJournalPath(); + bf::path cachePath = ioc->getCachePath(); + bf::path sourcePath = metaPath/"copyfile1"/"source.meta"; + bf::path destPath = metaPath/"copyfile2"/"dest.meta"; + const char *l_sourceFile = "copyfile1/source"; + const char *l_destFile = "copyfile2/dest"; + + cache->reset(); + + bf::create_directories(sourcePath.parent_path()); + makeTestMetadata(sourcePath.string().c_str()); + makeTestObject((cachePath/testObjKey).string().c_str()); + makeTestJournal((journalPath/(string(testObjKey) + ".journal")).string().c_str()); + cache->newObject(testObjKey, bf::file_size(cachePath/testObjKey)); + cache->newJournalEntry(bf::file_size(journalPath/(string(testObjKey) + ".journal"))); + + int err = ioc->copyFile("copyfile1/source", "copyfile2/dest"); + assert(!err); + uint8_t buf1[8192], buf2[8192]; + err = ioc->read(l_sourceFile, buf1, 0, 8192); + assert(err == 8192); + err = ioc->read(l_destFile, buf2, 0, 8192); + assert(err == 8192); + assert(memcmp(buf1, buf2, 8192) == 0); + + ioc->unlink("copyfile1"); + ioc->unlink("copyfile2"); + assert(cache->getCurrentCacheSize() == 0); + cout << "IOC copy file 3 OK" << endl; } void IOCCopyFile() @@ -1367,6 +1414,9 @@ int main() cout << "connected" << endl; scoped_closer sc1(serverSock), sc2(sessionSock), sc3(clientSock); + IOCCopyFile(); + return 0; + opentask(); metadataUpdateTest(); // requires 8K object size to test boundries