Add Update Handler class
Change-Id: I465297bfa3b8c4c8e6e7f7cd028b2d4afeb4e768
Refs: #3598
diff --git a/tests/unit-tests/torrent-manager.t.cpp b/tests/unit-tests/torrent-manager.t.cpp
index eba4ae4..cf009f1 100644
--- a/tests/unit-tests/torrent-manager.t.cpp
+++ b/tests/unit-tests/torrent-manager.t.cpp
@@ -21,6 +21,7 @@
#include "boost-test.hpp"
+#include "dummy-parser-fixture.hpp"
#include "torrent-manager.hpp"
#include "torrent-file.hpp"
#include "unit-test-time-fixture.hpp"
@@ -43,18 +44,14 @@
namespace fs = boost::filesystem;
class TestTorrentManager : public TorrentManager {
- public:
- TestTorrentManager(const ndn::Name& torrentFileName,
- const std::string& filePath)
- : TorrentManager(torrentFileName, filePath)
- {
- }
-
+public:
TestTorrentManager(const ndn::Name& torrentFileName,
const std::string& filePath,
std::shared_ptr<DummyClientFace> face)
: TorrentManager(torrentFileName, filePath, face)
+ , m_face(face)
{
+ m_keyChain = make_shared<KeyChain>();
}
std::vector<TorrentFile> torrentSegments() const {
@@ -111,6 +108,18 @@
bool writeFileManifest(const FileManifest& manifest, const std::string& path) {
return TorrentManager::writeFileManifest(manifest, path);
}
+
+ void sendRoutablePrefixResponse() {
+ // Create a data packet containing one name as content
+ shared_ptr<Data> d = DummyParser::createDataPacket(Name("/localhop/nfd/rib/routable-prefixes"),
+ { Name("ucla") });
+ m_keyChain->sign(*d);
+ m_face->receive(*d);
+ }
+
+private:
+ shared_ptr<KeyChain> m_keyChain;
+ shared_ptr<DummyClientFace> m_face;
};
class FaceFixture : public UnitTestTimeFixture
@@ -138,7 +147,6 @@
: FaceFixture(false)
{
}
-
};
BOOST_FIXTURE_TEST_SUITE(TestTorrentManagerInitialize, FaceFixture)
@@ -202,8 +210,12 @@
TestTorrentManager manager(initialSegmentName,
filePath,
face);
+
manager.Initialize();
+ advanceClocks(time::milliseconds(1), 10);
+ manager.sendRoutablePrefixResponse();
+
// Check that the torrent segments and file manifests match (content and order)
BOOST_CHECK(manager.torrentSegments() == torrentSegments);
BOOST_CHECK(manager.fileManifests() == manifests);
@@ -222,8 +234,13 @@
BOOST_AUTO_TEST_CASE(CheckInitializeEmpty)
{
TestTorrentManager manager("/NTORRENT/foo/torrent-file/sha256digest=02c737fd4c6e7de4b4825b089f39700c2dfa8fd2bb2b91f09201e357c4463253",
- "tests/testdata/");
+ "tests/testdata/", face);
+
manager.Initialize();
+
+ advanceClocks(time::milliseconds(1), 10);
+ manager.sendRoutablePrefixResponse();
+
BOOST_CHECK(manager.torrentSegments() == vector<TorrentFile>());
BOOST_CHECK(manager.fileManifests() == vector<FileManifest>());
}
@@ -276,8 +293,12 @@
TestTorrentManager manager(initialSegmentName,
filePath,
face);
+
manager.Initialize();
+ advanceClocks(time::milliseconds(1), 10);
+ manager.sendRoutablePrefixResponse();
+
// Check that the torrent segments and file manifests match (content and order)
BOOST_CHECK(manager.torrentSegments() == torrentSegments);
BOOST_CHECK(manager.fileManifests() == vector<FileManifest>());
@@ -342,12 +363,17 @@
boost::filesystem::create_directory(filename.parent_path());
io::save(m, filename.string());
}
+
// Initialize and verify
TestTorrentManager manager(initialSegmentName,
filePath,
face);
+
manager.Initialize();
+ advanceClocks(time::milliseconds(1), 10);
+ manager.sendRoutablePrefixResponse();
+
// Check that the torrent segments and file manifests match (content and order)
BOOST_CHECK(manager.torrentSegments() == torrentSegments);
BOOST_CHECK(manager.fileManifests() == manifests);
@@ -388,8 +414,12 @@
TestTorrentManager manager("/NTORRENT/foo/torrent-file/sha256digest=946b92641d2b87bf4f5913930be20e3789ff5fb5d72739614f93f677d90fbd9d",
filePath, face);
+
manager.Initialize();
+ advanceClocks(time::milliseconds(1), 10);
+ manager.sendRoutablePrefixResponse();
+
// Test download torrent file segments
uint32_t counter = 0;
manager.downloadTorrentFile(filePath + "torrent_files", [&counter, &torrentSegments]
@@ -436,8 +466,12 @@
TestTorrentManager manager("/NTORRENT/foo/torrent-file/sha256digest=946b92641d2b87bf4f5913930be20e3789ff5fb5d72739614f93f677d90fbd9d",
filePath, face);
+
manager.Initialize();
+ advanceClocks(time::milliseconds(1), 10);
+ manager.sendRoutablePrefixResponse();
+
// Test download manifest segments -- 2 files (the first one segment, the second multiple)
int counter = 0;
manager.download_file_manifest(manifests[0].getFullName(), filePath + "manifests",
@@ -494,8 +528,12 @@
std::string filePath = ".appdata/foo/";
TestTorrentManager manager("/NTORRENT/foo/torrent-file/sha256digest=946b92641d2b87bf4f5913930be20e3789ff5fb5d72739614f93f677d90fbd9d",
filePath, face);
+
manager.Initialize();
+ advanceClocks(time::milliseconds(1), 10);
+ manager.sendRoutablePrefixResponse();
+
Name dataName("/test/ucla");
// Download data successfully
@@ -537,8 +575,12 @@
std::string filePath = ".appdata/foo/";
TestTorrentManager manager("NTORRENT/test/torrent-file/sha256digest",
filePath, face);
+
manager.Initialize();
+ advanceClocks(time::milliseconds(1), 10);
+ manager.sendRoutablePrefixResponse();
+
TorrentFile t1(Name("NTORRENT/test/torrent-file/sha256digest"),
Name("NTORRENT/test/torrent-file/1/sha256digest"), Name("/test"),
{ Name("/manifest1") });
@@ -576,11 +618,16 @@
BOOST_AUTO_TEST_CASE(TestFindTorrentFileSegmentToDownload2)
{
std::string filePath = ".appdata/foo/";
- TestTorrentManager manager("/test/0/sha256digest",
+ TestTorrentManager manager("NTORRENT/test/torrent-file/0/sha256digest",
filePath, face);
+
manager.Initialize();
- BOOST_CHECK_EQUAL(manager.findTorrentFileSegmentToDownload()->toUri(), "/test/0/sha256digest");
+ advanceClocks(time::milliseconds(1), 10);
+ manager.sendRoutablePrefixResponse();
+
+ BOOST_CHECK_EQUAL(manager.findTorrentFileSegmentToDownload()->toUri(),
+ "/NTORRENT/test/torrent-file/0/sha256digest");
fs::remove_all(filePath);
fs::remove_all(".appdata");
@@ -631,8 +678,12 @@
TestTorrentManager manager("/NTORRENT/foo/torrent-file/sha256digest=a8a2e98cd943d895b8c4b12a208343bcf9344ce85a6376dc6f5754fe8f4a573e",
filePath,
face);
+
manager.Initialize();
+ advanceClocks(time::milliseconds(1), 10);
+ manager.sendRoutablePrefixResponse();
+
// Set the file state
std::vector<bool> v1 = {true};
manager.setFileState(manifests[0].getFullName(), make_shared<fs::fstream>(), v1);
@@ -675,10 +726,14 @@
BOOST_AUTO_TEST_CASE(TestFindManifestSegmentToDownload1)
{
std::string filePath = ".appdata/foo/";
- TestTorrentManager manager("NTORRENT/test/sha256digest",
+ TestTorrentManager manager("NTORRENT/test/torrent-file/sha256digest",
filePath, face);
+
manager.Initialize();
+ advanceClocks(time::milliseconds(1), 10);
+ manager.sendRoutablePrefixResponse();
+
Name n1(Name("NTORRENT/test/file0"));
n1.appendSequenceNumber(0);
@@ -786,8 +841,12 @@
TestTorrentManager manager("/NTORRENT/foo/torrent-file/sha256digest=a8a2e98cd943d895b8c4b12a208343bcf9344ce85a6376dc6f5754fe8f4a573e",
filePath,
face);
+
manager.Initialize();
+ advanceClocks(time::milliseconds(1), 10);
+ manager.sendRoutablePrefixResponse();
+
// Set the file state
std::vector<bool> v1 = {true};
manager.setFileState(manifests[0].getFullName(), make_shared<fs::fstream>(), v1);
@@ -885,8 +944,12 @@
TestTorrentManager manager("/NTORRENT/foo/torrent-file/sha256digest=a8a2e98cd943d895b8c4b12a208343bcf9344ce85a6376dc6f5754fe8f4a573e",
filePath,
face);
+
manager.Initialize();
+ advanceClocks(time::milliseconds(1), 10);
+ manager.sendRoutablePrefixResponse();
+
// Set the file state
std::vector<bool> v1 = {true};
manager.setFileState(manifests[0].getFullName(), make_shared<fs::fstream>(), v1);
@@ -973,7 +1036,12 @@
TestTorrentManager manager(initialSegmentName,
filePath,
face);
+
manager.Initialize();
+
+ advanceClocks(time::milliseconds(1), 10);
+ manager.sendRoutablePrefixResponse();
+
size_t nData = 0;
BOOST_CHECK_EQUAL(0, face->sentData.size());
// request all the torrent segments
@@ -1093,8 +1161,12 @@
TestTorrentManager manager(initialSegmentName,
filePath,
face);
+
manager.Initialize();
+ advanceClocks(time::milliseconds(1), 10);
+ manager.sendRoutablePrefixResponse();
+
// insert the other entities
data.insert(data.end(), torrentSegments.begin(), torrentSegments.end());
data.insert(data.end(), manifests.begin(), manifests.end());
@@ -1189,7 +1261,12 @@
TestTorrentManager manager(initialSegmentName,
filePath,
face);
+
manager.Initialize();
+
+ advanceClocks(time::milliseconds(1), 10);
+ manager.sendRoutablePrefixResponse();
+
// check that initially there is no data on disk
for (auto m : manager.fileManifests()) {
auto fileState = manager.fileState(m.getFullName());
@@ -1273,7 +1350,12 @@
TestTorrentManager manager(initialSegmentName,
filePath,
face);
+
manager.Initialize();
+
+ advanceClocks(time::milliseconds(1), 10);
+ manager.sendRoutablePrefixResponse();
+
std::string dirPath = ".appdata/foo/";
std::string torrentPath = dirPath + "torrent_files/";
BOOST_CHECK(manager.torrentSegments().empty());
@@ -1285,13 +1367,22 @@
TestTorrentManager manager2(initialSegmentName,
filePath,
face);
+
manager2.Initialize();
+
+ advanceClocks(time::milliseconds(1), 10);
+ manager2.sendRoutablePrefixResponse();
+
BOOST_CHECK(manager2.torrentSegments() == torrentSegments);
// start anew
fs::remove_all(torrentPath);
fs::create_directories(torrentPath);
manager.Initialize();
+
+ advanceClocks(time::milliseconds(1), 10);
+ manager.sendRoutablePrefixResponse();
+
BOOST_CHECK(manager.torrentSegments().empty());
// check that there is no dependence on the order of torrent segments
@@ -1350,7 +1441,12 @@
TestTorrentManager manager(initialSegmentName,
filePath,
face);
+
manager.Initialize();
+
+ advanceClocks(time::milliseconds(1), 10);
+ manager.sendRoutablePrefixResponse();
+
for (const auto& t : torrentSegments) {
manager.writeTorrentSegment(t, torrentPath);
}
@@ -1366,12 +1462,20 @@
face);
manager2.Initialize();
+
+ advanceClocks(time::milliseconds(1), 10);
+ manager2.sendRoutablePrefixResponse();
+
BOOST_CHECK(manager2.fileManifests() == manifests);
// start anew
fs::remove_all(manifestPath);
fs::create_directories(manifestPath);
manager.Initialize();
+
+ advanceClocks(time::milliseconds(1), 10);
+ manager.sendRoutablePrefixResponse();
+
BOOST_CHECK(manager.fileManifests().empty());
// check that there is no dependence on the order of torrent segments