From fe2c5b64d0a76121171d9c729850054a1b57c4bb Mon Sep 17 00:00:00 2001 From: Patrick LeBlanc Date: Thu, 4 Apr 2019 11:06:17 -0500 Subject: [PATCH] Added a couple assertions in Cache to keep us honest during testing. Added a 'real' test for IOC::copyFile(). Looks good, will merge it. --- src/Cache.cpp | 2 ++ src/unit_tests.cpp | 76 +++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 77 insertions(+), 1 deletion(-) diff --git a/src/Cache.cpp b/src/Cache.cpp index accfa1118..02ca621bb 100644 --- a/src/Cache.cpp +++ b/src/Cache.cpp @@ -303,12 +303,14 @@ void Cache::newJournalEntry(size_t size) void Cache::deletedJournal(size_t size) { boost::unique_lock s(lru_mutex); + assert(currentCacheSize >= size); currentCacheSize -= size; } void Cache::deletedObject(const string &key, size_t size) { boost::unique_lock s(lru_mutex); + assert(currentCacheSize >= size); M_LRU_t::iterator mit = m_lru.find(key); assert(mit != m_lru.end()); assert(doNotEvict.find(mit->lit) == doNotEvict.end()); diff --git a/src/unit_tests.cpp b/src/unit_tests.cpp index 6ce46d32f..8de2fa668 100755 --- a/src/unit_tests.cpp +++ b/src/unit_tests.cpp @@ -1022,6 +1022,7 @@ bool syncTest1() // make the journal again, call sync->newJournalObject() makeTestJournal((journalPath / (newKey + ".journal")).string().c_str()); + cache->newJournalEntry(bf::file_size(journalPath / (newKey + ".journal"))); sync->newJournalEntry(newKey); sleep(1); @@ -1284,6 +1285,78 @@ void IOCUnlink() cout << "IOC unlink test OK" << endl; } +void IOCCopyFile1() +{ + /* + Make our usual test files + with metadata in a subdir + with object in cloud storage + call ioc::copyFile() + with dest in a different subdir + verify the contents + */ + IOCoordinator *ioc = IOCoordinator::get(); + Cache *cache = Cache::get(); + CloudStorage *cs = CloudStorage::get(); + LocalStorage *ls = dynamic_cast(cs); + if (!ls) + { + cout << "IOCCopyFile1 requires local storage at the moment" << endl; + return; + } + + bf::path metaPath = ioc->getMetadataPath(); + bf::path csPath = ls->getPrefix(); + bf::path journalPath = ioc->getJournalPath(); + 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((csPath/testObjKey).string().c_str()); + makeTestJournal((journalPath/(string(testObjKey) + ".journal")).string().c_str()); + 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 1 OK" << endl; +} + +void IOCCopyFile2() +{ + // call IOC::copyFile() with non-existant file +} + +void IOCCopyFile3() +{ + /* + Make our usual test files + with object in the cache not in CS + call ioc::copyFile() + verify dest file exists + */ +} + +void IOCCopyFile() +{ + IOCCopyFile1(); + IOCCopyFile2(); + IOCCopyFile3(); +} int main() { @@ -1293,7 +1366,7 @@ int main() makeConnection(); cout << "connected" << endl; scoped_closer sc1(serverSock), sc2(sessionSock), sc3(clientSock); - + opentask(); metadataUpdateTest(); // requires 8K object size to test boundries @@ -1329,6 +1402,7 @@ int main() IOCReadTest1(); IOCTruncate(); IOCUnlink(); + IOCCopyFile(); return 0; }