rib: change FIB mocking mechanism
Previously, RIB test suites mock FIB updates by invoking RibManager
or Rib's private methods from a callback. In this commit, Rib class
exposes a `mockFibResponse` function variable, so that test cases
can directly specify FibUpdater's response without needing to invoke
private methods. This further allows replacing these private methods
with lambdas.
Also, logic for beginning RibUpdateBatch is abstracted out of control
command handlers, in preparation for PrefixAnnouncement-based RIB
update functions.
refs #4683
Change-Id: I0c95d8daa1458c704c7352a7809e6bed69134642
diff --git a/tests/rib/fib-updates-common.hpp b/tests/rib/fib-updates-common.hpp
index 925ca81..f063f5d 100644
--- a/tests/rib/fib-updates-common.hpp
+++ b/tests/rib/fib-updates-common.hpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/**
- * Copyright (c) 2014-2017, Regents of the University of California,
+/*
+ * Copyright (c) 2014-2018, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
@@ -81,7 +81,8 @@
.setName(name)
.setRoute(route);
- simulateSuccessfulResponse(update);
+ simulateSuccessfulResponse();
+ rib.beginApplyUpdate(update, nullptr, nullptr);
}
void
@@ -95,53 +96,17 @@
.setName(name)
.setRoute(route);
- simulateSuccessfulResponse(update);
- }
-
- void
- onSendBatchFromQueue(const RibUpdateBatch& batch)
- {
- Rib::UpdateSuccessCallback managerCallback = bind(&FibUpdatesFixture::onSuccess, this);
-
- // Only receive callback after the first send
- rib.m_onSendBatchFromQueue = nullptr;
-
- rib.onFibUpdateSuccess(batch, fibUpdater.m_inheritedRoutes, managerCallback);
+ simulateSuccessfulResponse();
+ rib.beginApplyUpdate(update, nullptr, nullptr);
}
void
destroyFace(uint64_t faceId)
{
- rib.m_onSendBatchFromQueue = bind(&FibUpdatesFixture::onSendBatchFromQueue, this, _1);
-
+ simulateSuccessfulResponse();
rib.beginRemoveFace(faceId);
}
- void
- simulateSuccessfulResponse(const RibUpdate& update)
- {
- Rib::UpdateSuccessCallback managerCallback = bind(&FibUpdatesFixture::onSuccess, this);
-
- rib.beginApplyUpdate(update, managerCallback, nullptr);
-
- RibUpdateBatch batch(update.getRoute().faceId);
- batch.add(update);
-
- // Simulate a successful response from NFD
- rib.onFibUpdateSuccess(batch, fibUpdater.m_inheritedRoutes, managerCallback);
- }
-
- void
- onSuccess()
- {
- }
-
- void
- onFailure()
- {
- BOOST_FAIL("FibUpdate failed");
- }
-
const FibUpdater::FibUpdateList&
getFibUpdates()
{
@@ -153,7 +118,6 @@
return fibUpdates;
}
-
FibUpdater::FibUpdateList
getSortedFibUpdates()
{
@@ -169,6 +133,14 @@
fibUpdater.m_updatesForNonBatchFaceId.clear();
}
+private:
+ void
+ simulateSuccessfulResponse()
+ {
+ rib.mockFibResponse = [] (const RibUpdateBatch&) { return true; };
+ rib.wantMockFibResponseOnce = true;
+ }
+
public:
ndn::util::DummyClientFace face;
ndn::nfd::Controller controller;