catchunks: remove modular version discovery
refs: #4832, #4556
Change-Id: I99b4f42d1457c74321c9b6ae84f793a93c4c1436
diff --git a/tests/chunks/consumer.t.cpp b/tests/chunks/consumer.t.cpp
index f6d3e8a..84dcb5b 100644
--- a/tests/chunks/consumer.t.cpp
+++ b/tests/chunks/consumer.t.cpp
@@ -133,43 +133,6 @@
BOOST_CHECK(output.is_equal(testStrings[2]));
}
-class DiscoverVersionDummy : public DiscoverVersion
-{
-public:
- DiscoverVersionDummy(const Name& prefix, Face& face, const Options& options)
- : Options(options)
- , DiscoverVersion(prefix, face)
- , isDiscoverRunning(false)
- , m_prefix(prefix)
- {
- }
-
- void
- run() final
- {
- isDiscoverRunning = true;
-
- auto interest = makeInterest(m_prefix, true);
- expressInterest(*interest, 1, 1);
- }
-
-private:
- void
- handleData(const Interest& interest, const Data& data) final
- {
- if (!data.getName().empty() && data.getName()[-1].isVersion())
- this->emitSignal(onDiscoverySuccess, data.getName());
- else
- this->emitSignal(onDiscoveryFailure, "Invalid versioned name");
- }
-
-public:
- bool isDiscoverRunning;
-
-private:
- Name m_prefix;
-};
-
class PipelineInterestsDummy : public PipelineInterests
{
public:
@@ -201,17 +164,16 @@
util::DummyClientFace face(io);
Consumer consumer(security::v2::getAcceptAllValidator());
- Name prefix("/ndn/chunks/test");
- auto discover = make_unique<DiscoverVersionDummy>(prefix, face, Options());
+ Name prefix = Name("/ndn/chunks/test").appendVersion(1);
+ auto discover = make_unique<DiscoverVersion>(prefix, face, Options());
auto pipeline = make_unique<PipelineInterestsDummy>(face);
- auto discoverPtr = discover.get();
auto pipelinePtr = pipeline.get();
consumer.run(std::move(discover), std::move(pipeline));
- BOOST_CHECK_EQUAL(discoverPtr->isDiscoverRunning, true);
this->advanceClocks(io, time::nanoseconds(1));
- BOOST_REQUIRE_EQUAL(face.sentInterests.size(), 1);
+ // no discovery interest is issued
+ BOOST_CHECK_EQUAL(face.sentInterests.size(), 0);
// this Data packet answers the discovery Interest, so it must end with a version number
auto data = makeData(prefix.appendVersion(0));
diff --git a/tests/chunks/discover-version-fixed.t.cpp b/tests/chunks/discover-version-fixed.t.cpp
deleted file mode 100644
index 2017c52..0000000
--- a/tests/chunks/discover-version-fixed.t.cpp
+++ /dev/null
@@ -1,145 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/*
- * Copyright (c) 2016-2018, Regents of the University of California,
- * Colorado State University,
- * University Pierre & Marie Curie, Sorbonne University.
- *
- * This file is part of ndn-tools (Named Data Networking Essential Tools).
- * See AUTHORS.md for complete list of ndn-tools authors and contributors.
- *
- * ndn-tools is free software: you can redistribute it and/or modify it under the terms
- * of the GNU General Public License as published by the Free Software Foundation,
- * either version 3 of the License, or (at your option) any later version.
- *
- * ndn-tools is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
- * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
- * PURPOSE. See the GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along with
- * ndn-tools, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
- *
- * See AUTHORS.md for complete list of ndn-cxx authors and contributors.
- *
- * @author Andrea Tosatto
- */
-
-#include "tools/chunks/catchunks/discover-version-fixed.hpp"
-
-#include "discover-version-fixture.hpp"
-
-namespace ndn {
-namespace chunks {
-namespace tests {
-
-class DiscoverVersionFixedFixture : public DiscoverVersionFixture
-{
-public:
- DiscoverVersionFixedFixture()
- : DiscoverVersionFixture(makeOptions())
- , version(1449227841747)
- {
- setDiscover(make_unique<DiscoverVersionFixed>(Name(name).appendVersion(version),
- face, makeOptions()));
- }
-
-protected:
- uint64_t version; // version to find
-};
-
-BOOST_AUTO_TEST_SUITE(Chunks)
-BOOST_AUTO_TEST_SUITE(TestDiscoverVersionFixed)
-
-BOOST_FIXTURE_TEST_CASE(RequestedVersionAvailable, DiscoverVersionFixedFixture)
-{
- discover->run();
- advanceClocks(io, time::nanoseconds(1), 1);
- BOOST_REQUIRE_EQUAL(face.sentInterests.size(), 1);
-
- face.receive(*makeDataWithVersion(version));
-
- advanceClocks(io, time::nanoseconds(1), 1);
-
- BOOST_CHECK_EQUAL(isDiscoveryFinished, true);
- BOOST_CHECK_EQUAL(discoveredVersion, version);
-
- BOOST_REQUIRE_EQUAL(face.sentInterests.size(), 1);
- auto lastInterest = face.sentInterests.back();
- BOOST_CHECK_EQUAL(lastInterest.getExclude().size(), 0);
- BOOST_CHECK_EQUAL(lastInterest.getMaxSuffixComponents(), 2);
- BOOST_CHECK_EQUAL(lastInterest.getMinSuffixComponents(), 2);
- BOOST_CHECK_EQUAL(lastInterest.getMustBeFresh(), mustBeFresh);
-}
-
-BOOST_FIXTURE_TEST_CASE(NoVersionsAvailable, DiscoverVersionFixedFixture)
-{
- discover->run();
- advanceClocks(io, time::nanoseconds(1), 1);
- BOOST_REQUIRE_EQUAL(face.sentInterests.size(), 1);
-
- for (int retries = 0; retries < maxRetriesOnTimeoutOrNack; ++retries) {
- advanceClocks(io, interestLifetime, 1);
- BOOST_CHECK_EQUAL(isDiscoveryFinished, false);
- BOOST_REQUIRE_EQUAL(face.sentInterests.size(), 2 + retries);
- }
-
- for (const auto& lastInterest : face.sentInterests) {
- BOOST_CHECK_EQUAL(lastInterest.getExclude().size(), 0);
- BOOST_CHECK_EQUAL(lastInterest.getMaxSuffixComponents(), 2);
- BOOST_CHECK_EQUAL(lastInterest.getMinSuffixComponents(), 2);
- BOOST_CHECK_EQUAL(lastInterest.getMustBeFresh(), mustBeFresh);
- BOOST_CHECK_EQUAL(lastInterest.getName().equals(Name(name).appendVersion(version)), true);
- }
-
- advanceClocks(io, interestLifetime, 1);
- BOOST_CHECK_EQUAL(isDiscoveryFinished, true);
- // check if discovered version is the default value
- BOOST_CHECK_EQUAL(discoveredVersion, 0);
- BOOST_CHECK_EQUAL(face.sentInterests.size(), maxRetriesOnTimeoutOrNack + 1);
-}
-
-BOOST_FIXTURE_TEST_CASE(DataNotSegment, DiscoverVersionFixedFixture)
-{
- discover->run();
- advanceClocks(io, time::nanoseconds(1), 1);
- BOOST_REQUIRE_EQUAL(face.sentInterests.size(), 1);
-
- std::vector<std::string> randomStrings {
- "",
- "abcdefg",
- "12345",
- "qr%67a3%4e"
- };
-
- Exclude expectedExclude;
- for (size_t retries = 0; retries < randomStrings.size(); ++retries) {
- auto data = make_shared<Data>(Name(name).appendVersion(version).append(randomStrings[retries]));
- data->setFinalBlock(name::Component::fromSegment(0));
- data = signData(data);
-
- face.receive(*data);
- advanceClocks(io, time::nanoseconds(1), 1);
-
- BOOST_CHECK_EQUAL(isDiscoveryFinished, false);
-
- BOOST_REQUIRE_EQUAL(face.sentInterests.size(), 1 + retries);
- auto lastInterest = face.sentInterests.back();
- if (randomStrings[retries] != "")
- expectedExclude.excludeOne(name::Component::fromEscapedString(randomStrings[retries]));
- BOOST_CHECK_EQUAL(lastInterest.getExclude(), expectedExclude);
- BOOST_CHECK_EQUAL(lastInterest.getMaxSuffixComponents(), 2);
- BOOST_CHECK_EQUAL(lastInterest.getMinSuffixComponents(), 2);
- BOOST_CHECK_EQUAL(lastInterest.getMustBeFresh(), mustBeFresh);
- }
-
- advanceClocks(io, interestLifetime, maxRetriesOnTimeoutOrNack + 1);
- BOOST_CHECK_EQUAL(isDiscoveryFinished, true);
- // check if discovered version is the default value
- BOOST_CHECK_EQUAL(discoveredVersion, 0);
-}
-
-BOOST_AUTO_TEST_SUITE_END() // TestDiscoverVersionFixed
-BOOST_AUTO_TEST_SUITE_END() // Chunks
-
-} // namespace tests
-} // namespace chunks
-} // namespace ndn
diff --git a/tests/chunks/discover-version-fixture.hpp b/tests/chunks/discover-version-fixture.hpp
deleted file mode 100644
index d42429a..0000000
--- a/tests/chunks/discover-version-fixture.hpp
+++ /dev/null
@@ -1,110 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/*
- * Copyright (c) 2016-2019, Regents of the University of California,
- * Colorado State University,
- * University Pierre & Marie Curie, Sorbonne University.
- *
- * This file is part of ndn-tools (Named Data Networking Essential Tools).
- * See AUTHORS.md for complete list of ndn-tools authors and contributors.
- *
- * ndn-tools is free software: you can redistribute it and/or modify it under the terms
- * of the GNU General Public License as published by the Free Software Foundation,
- * either version 3 of the License, or (at your option) any later version.
- *
- * ndn-tools is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
- * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
- * PURPOSE. See the GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along with
- * ndn-tools, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
- *
- * See AUTHORS.md for complete list of ndn-cxx authors and contributors.
- *
- * @author Andrea Tosatto
- */
-
-#ifndef NDN_TOOLS_TESTS_CHUNKS_DISCOVER_VERSION_FIXTURE_HPP
-#define NDN_TOOLS_TESTS_CHUNKS_DISCOVER_VERSION_FIXTURE_HPP
-
-#include "tools/chunks/catchunks/discover-version.hpp"
-
-#include "tests/test-common.hpp"
-#include <ndn-cxx/util/dummy-client-face.hpp>
-
-namespace ndn {
-namespace chunks {
-namespace tests {
-
-using namespace ndn::tests;
-
-class DiscoverVersionFixture : public UnitTestTimeFixture, virtual protected Options
-{
-public:
- DiscoverVersionFixture(const Options& options)
- : Options(options)
- , face(io)
- , name("/ndn/chunks/test")
- , discoveredVersion(0)
- , isDiscoveryFinished(false)
- {
- }
-
- virtual
- ~DiscoverVersionFixture() = default;
-
-protected:
- void
- setDiscover(unique_ptr<DiscoverVersion> disc)
- {
- discover = std::move(disc);
- discover->onDiscoverySuccess.connect(bind(&DiscoverVersionFixture::onSuccess, this, _1));
- discover->onDiscoveryFailure.connect(bind(&DiscoverVersionFixture::onFailure, this, _1));
- }
-
- shared_ptr<Data>
- makeDataWithVersion(uint64_t version) const
- {
- auto data = make_shared<Data>(Name(name).appendVersion(version).appendSegment(0));
- data->setFinalBlock(name::Component::fromSegment(0));
- return signData(data);
- }
-
- static Options
- makeOptions()
- {
- Options options;
- options.isVerbose = false;
- options.interestLifetime = time::seconds(1);
- options.maxRetriesOnTimeoutOrNack = 15;
- return options;
- }
-
- virtual void
- onSuccess(const Name& versionedName)
- {
- isDiscoveryFinished = true;
-
- BOOST_REQUIRE(!versionedName.empty() && versionedName[-1].isVersion());
- discoveredVersion = versionedName[-1].toVersion();
- }
-
- virtual void
- onFailure(const std::string& reason)
- {
- isDiscoveryFinished = true;
- }
-
-protected:
- boost::asio::io_service io;
- util::DummyClientFace face;
- Name name;
- unique_ptr<DiscoverVersion> discover;
- uint64_t discoveredVersion;
- bool isDiscoveryFinished;
-};
-
-} // namespace tests
-} // namespace chunks
-} // namespace ndn
-
-#endif // NDN_TOOLS_TESTS_CHUNKS_DISCOVER_VERSION_FIXTURE_HPP
diff --git a/tests/chunks/discover-version-realtime.t.cpp b/tests/chunks/discover-version-realtime.t.cpp
deleted file mode 100644
index 5bfcfce..0000000
--- a/tests/chunks/discover-version-realtime.t.cpp
+++ /dev/null
@@ -1,158 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/*
- * Copyright (c) 2016-2019, Regents of the University of California,
- * Colorado State University,
- * University Pierre & Marie Curie, Sorbonne University.
- *
- * This file is part of ndn-tools (Named Data Networking Essential Tools).
- * See AUTHORS.md for complete list of ndn-tools authors and contributors.
- *
- * ndn-tools is free software: you can redistribute it and/or modify it under the terms
- * of the GNU General Public License as published by the Free Software Foundation,
- * either version 3 of the License, or (at your option) any later version.
- *
- * ndn-tools is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
- * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
- * PURPOSE. See the GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along with
- * ndn-tools, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
- *
- * See AUTHORS.md for complete list of ndn-cxx authors and contributors.
- *
- * @author Chavoosh Ghasemi
- */
-
-#include "tools/chunks/catchunks/discover-version-realtime.hpp"
-
-#include "discover-version-fixture.hpp"
-#include "tests/identity-management-fixture.hpp"
-
-#include <ndn-cxx/metadata-object.hpp>
-
-
-namespace ndn {
-namespace chunks {
-namespace tests {
-
-class DiscoverVersionRealtimeFixture : public DiscoverVersionFixture,
- public IdentityManagementFixture,
- protected DiscoverVersionRealtimeOptions
-{
-public:
- typedef DiscoverVersionRealtimeOptions Options;
-
-public:
- explicit
- DiscoverVersionRealtimeFixture(const Options& opt = makeOptionsRealtime())
- : chunks::Options(opt)
- , DiscoverVersionFixture(opt)
- , Options(opt)
- {
- setDiscover(make_unique<DiscoverVersionRealtime>(Name(name), face, opt));
- }
-
-protected:
- static Options
- makeOptionsRealtime()
- {
- Options options;
- options.isVerbose = false;
- options.maxRetriesOnTimeoutOrNack = 15;
- return options;
- }
-};
-
-BOOST_AUTO_TEST_SUITE(Chunks)
-BOOST_FIXTURE_TEST_SUITE(TestDiscoverVersionRealtime, DiscoverVersionRealtimeFixture)
-
-BOOST_AUTO_TEST_CASE(Success)
-{
- // issue a discovery Interest to learn Data version
- discover->run();
- advanceClocks(io, time::nanoseconds(1), 1);
-
- BOOST_REQUIRE_EQUAL(face.sentInterests.size(), 1);
-
- Interest discoveryInterest = MetadataObject::makeDiscoveryInterest(name);
- auto lastInterest = face.sentInterests.back();
- BOOST_CHECK_EQUAL(lastInterest.getName(), discoveryInterest.getName());
-
- // Send back a metadata packet with a valid versioned name
- uint64_t version = 1449241767037;
-
- MetadataObject mobject;
- mobject.setVersionedName(Name(name).appendVersion(version));
- face.receive(mobject.makeData(lastInterest.getName(), m_keyChain));
- advanceClocks(io, time::nanoseconds(1), 1);
-
- BOOST_CHECK(isDiscoveryFinished);
- BOOST_CHECK_EQUAL(discoveredVersion, version);
-}
-
-BOOST_AUTO_TEST_CASE(InvalidVersionedName)
-{
- // issue a discovery Interest to learn Data version
- discover->run();
- advanceClocks(io, time::nanoseconds(1), 1);
-
- BOOST_REQUIRE_EQUAL(face.sentInterests.size(), 1);
-
- // Send back a metadata packet with an invalid versioned name
- MetadataObject mobject;
- mobject.setVersionedName(name);
- face.receive(mobject.makeData(face.sentInterests.back().getName(), m_keyChain));
-
- // finish discovery process without a resolved version number
- BOOST_CHECK(isDiscoveryFinished);
- BOOST_CHECK_EQUAL(discoveredVersion, 0);
-}
-
-BOOST_AUTO_TEST_CASE(InvalidMetadataPacket)
-{
- // issue a discovery Interest to learn Data version
- discover->run();
- advanceClocks(io, time::nanoseconds(1), 1);
-
- BOOST_REQUIRE_EQUAL(face.sentInterests.size(), 1);
-
- // Send back an invalid metadata packet
- Data data(face.sentInterests.back().getName());
- data.setContentType(tlv::ContentType_Key);
- face.receive(signData(data));
-
- // finish discovery process without a resolved version number
- BOOST_CHECK(isDiscoveryFinished);
- BOOST_CHECK_EQUAL(discoveredVersion, 0);
-}
-
-BOOST_AUTO_TEST_CASE(Timeout)
-{
- // issue a discovery Interest to learn Data version
- discover->run();
- advanceClocks(io, time::nanoseconds(1), 1);
-
- BOOST_REQUIRE_EQUAL(face.sentInterests.size(), 1);
-
- // timeout discovery Interests
- for (int retries = 0; retries < maxRetriesOnTimeoutOrNack; ++retries) {
- advanceClocks(io, interestLifetime, 1);
-
- BOOST_CHECK_EQUAL(isDiscoveryFinished, false);
- BOOST_REQUIRE_EQUAL(face.sentInterests.size(), retries + 2);
- }
-
- // timeout the last sent Interest
- advanceClocks(io, interestLifetime, 1);
-
- // finish discovery process without a resolved version number
- BOOST_CHECK(isDiscoveryFinished);
- BOOST_CHECK_EQUAL(discoveredVersion, 0);
-}
-
-BOOST_AUTO_TEST_SUITE_END() // TestDiscoverVersionRealtime
-BOOST_AUTO_TEST_SUITE_END() // Chunks
-
-} // namespace tests
-} // namespace chunks
-} // namespace ndn
diff --git a/tests/chunks/discover-version.t.cpp b/tests/chunks/discover-version.t.cpp
new file mode 100644
index 0000000..266bcf5
--- /dev/null
+++ b/tests/chunks/discover-version.t.cpp
@@ -0,0 +1,206 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2016-2019, Regents of the University of California,
+ * Colorado State University,
+ * University Pierre & Marie Curie, Sorbonne University.
+ *
+ * This file is part of ndn-tools (Named Data Networking Essential Tools).
+ * See AUTHORS.md for complete list of ndn-tools authors and contributors.
+ *
+ * ndn-tools is free software: you can redistribute it and/or modify it under the terms
+ * of the GNU General Public License as published by the Free Software Foundation,
+ * either version 3 of the License, or (at your option) any later version.
+ *
+ * ndn-tools is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
+ * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+ * PURPOSE. See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * ndn-tools, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * See AUTHORS.md for complete list of ndn-cxx authors and contributors.
+ *
+ * @author Chavoosh Ghasemi
+ */
+
+#include "tools/chunks/catchunks/discover-version.hpp"
+
+#include "tests/test-common.hpp"
+#include "tests/identity-management-fixture.hpp"
+
+#include <ndn-cxx/metadata-object.hpp>
+#include <ndn-cxx/util/dummy-client-face.hpp>
+
+namespace ndn {
+namespace chunks {
+namespace tests {
+
+using namespace ndn::tests;
+
+class DiscoverVersionFixture : public UnitTestTimeFixture,
+ public IdentityManagementFixture
+{
+public:
+ DiscoverVersionFixture()
+ : face(io)
+ , name("/ndn/chunks/test")
+ , isDiscoveryFinished(false)
+ , version(1449227841747)
+ {
+ opt.interestLifetime = ndn::DEFAULT_INTEREST_LIFETIME;
+ opt.maxRetriesOnTimeoutOrNack = 15;
+ opt.isVerbose = false;
+ }
+
+ void
+ run(const Name& prefix)
+ {
+ BOOST_REQUIRE(!prefix.empty());
+ discover = make_unique<DiscoverVersion>(prefix, face, opt);
+ discover->onDiscoverySuccess.connect([this] (const Name& versionedName) {
+ isDiscoveryFinished = true;
+ BOOST_REQUIRE(!versionedName.empty() && versionedName[-1].isVersion());
+ discoveredVersion = versionedName[-1].toVersion();
+ });
+ discover->onDiscoveryFailure.connect([this] (const std::string& reason) {
+ isDiscoveryFinished = true;
+ });
+
+ discover->run();
+ advanceClocks(io, time::nanoseconds(1));
+ }
+
+protected:
+ boost::asio::io_service io;
+ util::DummyClientFace face;
+ Name name;
+ unique_ptr<DiscoverVersion> discover;
+ optional<uint64_t> discoveredVersion;
+ bool isDiscoveryFinished;
+ uint64_t version;
+ Options opt;
+};
+
+BOOST_AUTO_TEST_SUITE(Chunks)
+BOOST_FIXTURE_TEST_SUITE(TestDiscoverVersion, DiscoverVersionFixture)
+
+BOOST_AUTO_TEST_CASE(VersionNumberIsProvided)
+{
+ run(Name(name).appendVersion(version));
+
+ // no version discovery interest is expressed
+ BOOST_CHECK_EQUAL(face.sentInterests.size(), 0);
+
+ BOOST_CHECK_EQUAL(isDiscoveryFinished, true);
+ BOOST_CHECK_EQUAL(discoveredVersion.value(), version);
+}
+
+BOOST_AUTO_TEST_CASE(DiscoverySuccess)
+{
+ // express a discovery Interest to learn Data version
+ run(name);
+
+ BOOST_REQUIRE_EQUAL(face.sentInterests.size(), 1);
+
+ Interest discoveryInterest = MetadataObject::makeDiscoveryInterest(name);
+ auto lastInterest = face.sentInterests.back();
+ BOOST_CHECK_EQUAL(lastInterest.getName(), discoveryInterest.getName());
+
+ // Send back a metadata packet with a valid versioned name
+ MetadataObject mobject;
+ mobject.setVersionedName(Name(name).appendVersion(version));
+ face.receive(mobject.makeData(lastInterest.getName(), m_keyChain));
+ advanceClocks(io, time::nanoseconds(1));
+
+ BOOST_CHECK(isDiscoveryFinished);
+ BOOST_CHECK_EQUAL(discoveredVersion.value(), version);
+}
+
+BOOST_AUTO_TEST_CASE(InvalidDiscoveredVersionedName)
+{
+ // issue a discovery Interest to learn Data version
+ run(name);
+
+ BOOST_REQUIRE_EQUAL(face.sentInterests.size(), 1);
+
+ // Send back a metadata packet with an invalid versioned name
+ MetadataObject mobject;
+ mobject.setVersionedName(name);
+ face.receive(mobject.makeData(face.sentInterests.back().getName(), m_keyChain));
+
+ // finish discovery process without a resolved version number
+ BOOST_CHECK(isDiscoveryFinished);
+ BOOST_CHECK(!discoveredVersion.has_value());
+}
+
+BOOST_AUTO_TEST_CASE(InvalidMetadataPacket)
+{
+ // issue a discovery Interest to learn Data version
+ run(name);
+
+ BOOST_REQUIRE_EQUAL(face.sentInterests.size(), 1);
+
+ // Send back an invalid metadata packet
+ Data data(face.sentInterests.back().getName());
+ data.setContentType(tlv::ContentType_Key);
+ face.receive(signData(data));
+
+ // finish discovery process without a resolved version number
+ BOOST_CHECK(isDiscoveryFinished);
+ BOOST_CHECK(!discoveredVersion.has_value());
+}
+
+BOOST_AUTO_TEST_CASE(Timeout1)
+{
+ // issue a discovery Interest to learn Data version
+ run(name);
+
+ BOOST_REQUIRE_EQUAL(face.sentInterests.size(), 1);
+
+ // timeout discovery Interests
+ for (int retries = 0; retries < opt.maxRetriesOnTimeoutOrNack; ++retries) {
+ advanceClocks(io, opt.interestLifetime);
+
+ BOOST_CHECK_EQUAL(isDiscoveryFinished, false);
+ BOOST_REQUIRE_EQUAL(face.sentInterests.size(), retries + 2);
+ }
+
+ // timeout the last sent Interest
+ advanceClocks(io, opt.interestLifetime);
+
+ // finish discovery process without a resolved version number
+ BOOST_CHECK(isDiscoveryFinished);
+ BOOST_CHECK(!discoveredVersion.has_value());
+}
+
+BOOST_AUTO_TEST_CASE(Timeout2)
+{
+ // issue a discovery Interest to learn Data version
+ run(name);
+
+ BOOST_REQUIRE_EQUAL(face.sentInterests.size(), 1);
+
+ // timeout discovery Interests
+ for (int retries = 0; retries < opt.maxRetriesOnTimeoutOrNack; ++retries) {
+ advanceClocks(io, opt.interestLifetime);
+
+ BOOST_CHECK_EQUAL(isDiscoveryFinished, false);
+ BOOST_REQUIRE_EQUAL(face.sentInterests.size(), retries + 2);
+ }
+
+ // satisfy the last Interest with a valid metadata packet
+ MetadataObject mobject;
+ mobject.setVersionedName(Name(name).appendVersion(version));
+ face.receive(mobject.makeData(face.sentInterests.back().getName(), m_keyChain));
+ advanceClocks(io, time::nanoseconds(1));
+
+ BOOST_CHECK(isDiscoveryFinished);
+ BOOST_CHECK_EQUAL(discoveredVersion.value(), version);
+}
+
+BOOST_AUTO_TEST_SUITE_END() // TestDiscoverVersion
+BOOST_AUTO_TEST_SUITE_END() // Chunks
+
+} // namespace tests
+} // namespace chunks
+} // namespace ndn