util: rename Scheduler::scheduleEvent to schedule
Deprecate Scheduler::scheduleEvent and Scheduler::cancelEvent
refs #4883
Change-Id: I2bb16922aff04300d92dfd276dd436958a96929a
diff --git a/tests/integrated/face.cpp b/tests/integrated/face.cpp
index 5798b0f..ddc0cd3 100644
--- a/tests/integrated/face.cpp
+++ b/tests/integrated/face.cpp
@@ -87,7 +87,7 @@
}
outcome = '?';
- return sched.scheduleEvent(delay, [this, interest, &outcome] {
+ return sched.schedule(delay, [this, interest, &outcome] {
face2->expressInterest(interest,
[&] (const Interest&, const Data&) { outcome = 'D'; },
[&] (const Interest&, const lp::Nack&) { outcome = 'N'; },
@@ -108,7 +108,7 @@
scheduler::EventId
terminateAfter(time::nanoseconds delay)
{
- return sched.scheduleEvent(delay, [this] { face.getIoService().stop(); });
+ return sched.schedule(delay, [this] { face.getIoService().stop(); });
}
protected:
@@ -184,19 +184,19 @@
[&] (const Name&) { ++nRegSuccess; },
[] (const Name&, const std::string& msg) { BOOST_ERROR("unexpected register prefix failure: " << msg); });
- this->sched.scheduleEvent(1_s, [&nRegSuccess] {
+ this->sched.schedule(1_s, [&nRegSuccess] {
BOOST_CHECK_EQUAL(nRegSuccess, 1);
std::string output = executeCommand("nfdc route list | grep /Hello/World");
BOOST_CHECK(!output.empty());
});
- this->sched.scheduleEvent(2_s, [this, id, &nUnregSuccess] {
+ this->sched.schedule(2_s, [this, id, &nUnregSuccess] {
this->face.unregisterPrefix(id,
[&] { ++nUnregSuccess; },
[] (const std::string& msg) { BOOST_ERROR("unexpected unregister prefix failure: " << msg); });
});
- this->sched.scheduleEvent(3_s, [&nUnregSuccess] {
+ this->sched.schedule(3_s, [&nUnregSuccess] {
BOOST_CHECK_EQUAL(nUnregSuccess, 1);
// Boost.Test would fail if a child process exits with non-zero. http://stackoverflow.com/q/5325202
@@ -221,7 +221,7 @@
[&] (const Name&) { ++nRegSuccess2; },
[] (const Name&, const std::string& msg) { BOOST_ERROR("unexpected register prefix failure: " << msg); });
- this->sched.scheduleEvent(500_ms, [] {
+ this->sched.schedule(500_ms, [] {
std::string output = executeCommand("nfdc route list | grep /Hello/World");
BOOST_CHECK(!output.empty());
});
@@ -247,7 +247,7 @@
[&] (const Name&) { ++nRegSuccess; },
[] (const Name&, const std::string& msg) { BOOST_ERROR("unexpected register prefix failure: " << msg); });
- this->sched.scheduleEvent(700_ms, [] {
+ this->sched.schedule(700_ms, [] {
std::string output = executeCommand("nfdc route list | grep /Hello/World");
BOOST_CHECK(!output.empty());
});
@@ -272,7 +272,7 @@
this->face.setInterestFilter(InterestFilter("/Hello/World", "<><b><c>?"),
[&] (const InterestFilter&, const Interest& interest) { BOOST_ERROR("unexpected Interest"); });
- this->sched.scheduleEvent(700_ms, [] {
+ this->sched.schedule(700_ms, [] {
// Boost.Test would fail if a child process exits with non-zero. http://stackoverflow.com/q/5325202
std::string output = executeCommand("nfdc route list | grep /Hello/World || true");
BOOST_CHECK(output.empty());
diff --git a/tests/integrated/scheduler-benchmark.cpp b/tests/integrated/scheduler-benchmark.cpp
index 9bc4600..ecf6342 100644
--- a/tests/integrated/scheduler-benchmark.cpp
+++ b/tests/integrated/scheduler-benchmark.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2013-2018 Regents of the University of California.
+ * Copyright (c) 2013-2019 Regents of the University of California.
*
* This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
*
@@ -45,13 +45,13 @@
auto d1 = timedExecute([&] {
for (size_t i = 0; i < nEvents; ++i) {
- eventIds[i] = sched.scheduleEvent(1_s, []{});
+ eventIds[i] = sched.schedule(1_s, []{});
}
});
auto d2 = timedExecute([&] {
for (size_t i = 0; i < nEvents; ++i) {
- sched.cancelEvent(eventIds[i]);
+ eventIds[i].cancel();
}
});
@@ -72,13 +72,13 @@
time::steady_clock::TimePoint t2;
// +1ms ensures this extra event is executed last. In case the overhead is less than 1ms,
// it will be reported as 1ms.
- sched.scheduleEvent(t1 - time::steady_clock::now() + 1_ms, [&] {
+ sched.schedule(t1 - time::steady_clock::now() + 1_ms, [&] {
t2 = time::steady_clock::now();
BOOST_REQUIRE_EQUAL(nExpired, nEvents);
});
for (size_t i = 0; i < nEvents; ++i) {
- sched.scheduleEvent(t1 - time::steady_clock::now(), [&] { ++nExpired; });
+ sched.schedule(t1 - time::steady_clock::now(), [&] { ++nExpired; });
}
io.run();
diff --git a/tests/unit/security/signature-sha256-with-ecdsa.t.cpp b/tests/unit/security/signature-sha256-with-ecdsa.t.cpp
index abf15a2..3881756 100644
--- a/tests/unit/security/signature-sha256-with-ecdsa.t.cpp
+++ b/tests/unit/security/signature-sha256-with-ecdsa.t.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2013-2018 Regents of the University of California.
+ * Copyright (c) 2013-2019 Regents of the University of California.
*
* This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
*
@@ -128,15 +128,9 @@
auto interest = makeInterest("/SecurityTestSignatureSha256WithEcdsa/InterestSignature/Interest1");
auto interest11 = makeInterest("/SecurityTestSignatureSha256WithEcdsa/InterestSignature/Interest1");
- scheduler.scheduleEvent(100_ms, [&] {
- m_keyChain.sign(*interest, security::SigningInfo(identity));
- });
-
+ scheduler.schedule(100_ms, [&] { m_keyChain.sign(*interest, security::SigningInfo(identity)); });
advanceClocks(100_ms);
- scheduler.scheduleEvent(100_ms, [&] {
- m_keyChain.sign(*interest11, security::SigningInfo(identity));
- });
-
+ scheduler.schedule(100_ms, [&] { m_keyChain.sign(*interest11, security::SigningInfo(identity)); });
advanceClocks(100_ms);
Block interestBlock(interest->wireEncode().wire(), interest->wireEncode().size());
diff --git a/tests/unit/security/signature-sha256-with-rsa.t.cpp b/tests/unit/security/signature-sha256-with-rsa.t.cpp
index 3fca552..2363551 100644
--- a/tests/unit/security/signature-sha256-with-rsa.t.cpp
+++ b/tests/unit/security/signature-sha256-with-rsa.t.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2013-2018 Regents of the University of California.
+ * Copyright (c) 2013-2019 Regents of the University of California.
*
* This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
*
@@ -133,15 +133,9 @@
auto interest = makeInterest("/SecurityTestSignatureSha256WithRsa/InterestSignature/Interest1");
auto interest11 = makeInterest("/SecurityTestSignatureSha256WithRsa/InterestSignature/Interest1");
- scheduler.scheduleEvent(100_ms, [&] {
- m_keyChain.sign(*interest, security::SigningInfo(identity));
- });
-
+ scheduler.schedule(100_ms, [&] { m_keyChain.sign(*interest, security::SigningInfo(identity)); });
advanceClocks(100_ms);
- scheduler.scheduleEvent(100_ms, [&] {
- m_keyChain.sign(*interest11, security::SigningInfo(identity));
- });
-
+ scheduler.schedule(100_ms, [&] { m_keyChain.sign(*interest11, security::SigningInfo(identity)); });
advanceClocks(100_ms);
Block interestBlock(interest->wireEncode().wire(), interest->wireEncode().size());
diff --git a/tests/unit/util/scheduler.t.cpp b/tests/unit/util/scheduler.t.cpp
index 77b60a5..6497136 100644
--- a/tests/unit/util/scheduler.t.cpp
+++ b/tests/unit/util/scheduler.t.cpp
@@ -53,25 +53,21 @@
size_t count1 = 0;
size_t count2 = 0;
- scheduler.scheduleEvent(500_ms, [&] {
- ++count1;
- BOOST_CHECK_EQUAL(count2, 1);
- });
+ scheduler.schedule(500_ms, [&] {
+ ++count1;
+ BOOST_CHECK_EQUAL(count2, 1);
+ });
- EventId i = scheduler.scheduleEvent(1_s, [&] {
- BOOST_ERROR("This event should not have been fired");
- });
- scheduler.cancelEvent(i);
+ EventId i = scheduler.schedule(1_s, [] { BOOST_ERROR("This event should not have been fired"); });
+ i.cancel();
- scheduler.scheduleEvent(250_ms, [&] {
- BOOST_CHECK_EQUAL(count1, 0);
- ++count2;
- });
+ scheduler.schedule(250_ms, [&] {
+ BOOST_CHECK_EQUAL(count1, 0);
+ ++count2;
+ });
- i = scheduler.scheduleEvent(50_ms, [&] {
- BOOST_ERROR("This event should not have been fired");
- });
- scheduler.cancelEvent(i);
+ i = scheduler.schedule(50_ms, [&] { BOOST_ERROR("This event should not have been fired"); });
+ i.cancel();
advanceClocks(25_ms, 1000_ms);
BOOST_CHECK_EQUAL(count1, 1);
@@ -83,7 +79,7 @@
class MyException : public std::exception
{
};
- scheduler.scheduleEvent(10_ms, [] {
+ scheduler.schedule(10_ms, [] {
// use plain 'throw' to ensure that Scheduler does not depend on the
// internal machinery of NDN_THROW and that it can catch all exceptions
// regardless of how they are thrown by the application
@@ -91,7 +87,7 @@
});
bool isCallbackInvoked = false;
- scheduler.scheduleEvent(20_ms, [&isCallbackInvoked] { isCallbackInvoked = true; });
+ scheduler.schedule(20_ms, [&isCallbackInvoked] { isCallbackInvoked = true; });
BOOST_CHECK_THROW(this->advanceClocks(6_ms, 2), MyException);
this->advanceClocks(6_ms, 2);
@@ -101,7 +97,7 @@
BOOST_AUTO_TEST_CASE(CancelEmptyEvent)
{
EventId i;
- scheduler.cancelEvent(i);
+ i.cancel();
// avoid "test case [...] did not check any assertions" message from Boost.Test
BOOST_CHECK(true);
@@ -110,43 +106,33 @@
BOOST_AUTO_TEST_CASE(SelfCancel)
{
EventId selfEventId;
- selfEventId = scheduler.scheduleEvent(100_ms, [&] {
- scheduler.cancelEvent(selfEventId);
- });
-
+ selfEventId = scheduler.schedule(100_ms, [&] { selfEventId.cancel(); });
BOOST_REQUIRE_NO_THROW(advanceClocks(100_ms, 10));
}
class SelfRescheduleFixture : public SchedulerFixture
{
public:
- SelfRescheduleFixture()
- : count(0)
- {
- }
-
void
reschedule()
{
- EventId eventId = scheduler.scheduleEvent(100_ms,
- bind(&SelfRescheduleFixture::reschedule, this));
- scheduler.cancelEvent(selfEventId);
+ EventId eventId = scheduler.schedule(100_ms, bind(&SelfRescheduleFixture::reschedule, this));
+ selfEventId.cancel();
selfEventId = eventId;
if (count < 5)
count++;
else
- scheduler.cancelEvent(selfEventId);
+ selfEventId.cancel();
}
void
reschedule2()
{
- scheduler.cancelEvent(selfEventId);
+ selfEventId.cancel();
if (count < 5) {
- selfEventId = scheduler.scheduleEvent(100_ms,
- bind(&SelfRescheduleFixture::reschedule2, this));
+ selfEventId = scheduler.schedule(100_ms, bind(&SelfRescheduleFixture::reschedule2, this));
count++;
}
}
@@ -154,90 +140,70 @@
void
reschedule3()
{
- scheduler.cancelEvent(selfEventId);
+ selfEventId.cancel();
- scheduler.scheduleEvent(100_ms, [&] { ++count; });
- scheduler.scheduleEvent(100_ms, [&] { ++count; });
- scheduler.scheduleEvent(100_ms, [&] { ++count; });
- scheduler.scheduleEvent(100_ms, [&] { ++count; });
- scheduler.scheduleEvent(100_ms, [&] { ++count; });
- scheduler.scheduleEvent(100_ms, [&] { ++count; });
+ scheduler.schedule(100_ms, [&] { ++count; });
+ scheduler.schedule(100_ms, [&] { ++count; });
+ scheduler.schedule(100_ms, [&] { ++count; });
+ scheduler.schedule(100_ms, [&] { ++count; });
+ scheduler.schedule(100_ms, [&] { ++count; });
+ scheduler.schedule(100_ms, [&] { ++count; });
}
public:
EventId selfEventId;
- size_t count;
+ size_t count = 0;
};
BOOST_FIXTURE_TEST_CASE(Reschedule, SelfRescheduleFixture)
{
- selfEventId = scheduler.scheduleEvent(0_s,
- bind(&SelfRescheduleFixture::reschedule, this));
-
+ selfEventId = scheduler.schedule(0_s, bind(&SelfRescheduleFixture::reschedule, this));
BOOST_REQUIRE_NO_THROW(advanceClocks(50_ms, 1000_ms));
-
BOOST_CHECK_EQUAL(count, 5);
}
BOOST_FIXTURE_TEST_CASE(Reschedule2, SelfRescheduleFixture)
{
- selfEventId = scheduler.scheduleEvent(0_s,
- bind(&SelfRescheduleFixture::reschedule2, this));
-
+ selfEventId = scheduler.schedule(0_s, bind(&SelfRescheduleFixture::reschedule2, this));
BOOST_REQUIRE_NO_THROW(advanceClocks(50_ms, 1000_ms));
-
BOOST_CHECK_EQUAL(count, 5);
}
BOOST_FIXTURE_TEST_CASE(Reschedule3, SelfRescheduleFixture)
{
- selfEventId = scheduler.scheduleEvent(0_s,
- bind(&SelfRescheduleFixture::reschedule3, this));
-
+ selfEventId = scheduler.schedule(0_s, bind(&SelfRescheduleFixture::reschedule3, this));
BOOST_REQUIRE_NO_THROW(advanceClocks(50_ms, 1000_ms));
-
BOOST_CHECK_EQUAL(count, 6);
}
class CancelAllFixture : public SchedulerFixture
{
public:
- CancelAllFixture()
- : count(0)
- {
- }
-
void
event()
{
++count;
-
- scheduler.scheduleEvent(1_s, [&] { event(); });
+ scheduler.schedule(1_s, [&] { event(); });
}
public:
- uint32_t count;
+ uint32_t count = 0;
};
BOOST_FIXTURE_TEST_CASE(CancelAll, CancelAllFixture)
{
- scheduler.scheduleEvent(500_ms, [&] { scheduler.cancelAllEvents(); });
-
- scheduler.scheduleEvent(1_s, [&] { event(); });
-
- scheduler.scheduleEvent(3_s, [] {
- BOOST_ERROR("This event should have been cancelled" );
- });
+ scheduler.schedule(500_ms, [&] { scheduler.cancelAllEvents(); });
+ scheduler.schedule(1_s, [&] { event(); });
+ scheduler.schedule(3_s, [] { BOOST_ERROR("This event should have been cancelled" ); });
advanceClocks(100_ms, 100);
-
BOOST_CHECK_EQUAL(count, 0);
}
BOOST_AUTO_TEST_CASE(CancelAllWithScopedEventId) // Bug 3691
{
Scheduler sched(io);
- ScopedEventId eid = sched.scheduleEvent(10_ms, []{});
+ ScopedEventId eid = sched.schedule(10_ms, []{});
sched.cancelAllEvents();
eid.cancel(); // should not crash
@@ -263,7 +229,7 @@
BOOST_CHECK_EQUAL(eid == eid2, true);
BOOST_CHECK_EQUAL(eid != eid2, false);
- eid = scheduler.scheduleEvent(10_ms, []{});
+ eid = scheduler.schedule(10_ms, []{});
BOOST_CHECK_EQUAL(eid == eid2, false);
BOOST_CHECK_EQUAL(eid != eid2, true);
@@ -271,7 +237,7 @@
BOOST_CHECK_EQUAL(eid, eid2);
BOOST_CHECK_EQUAL(eid != eid2, false);
- eid2 = scheduler.scheduleEvent(10_ms, []{});
+ eid2 = scheduler.schedule(10_ms, []{});
BOOST_CHECK_EQUAL(eid == eid2, false);
BOOST_CHECK_NE(eid, eid2);
}
@@ -282,12 +248,12 @@
BOOST_CHECK_EQUAL(static_cast<bool>(eid), false);
BOOST_CHECK_EQUAL(!eid, true);
- eid = scheduler.scheduleEvent(10_ms, []{});
+ eid = scheduler.schedule(10_ms, []{});
BOOST_CHECK_EQUAL(static_cast<bool>(eid), true);
BOOST_CHECK_EQUAL(!eid, false);
EventId eid2 = eid;
- scheduler.cancelEvent(eid2);
+ eid2.cancel();
BOOST_CHECK(!eid);
BOOST_CHECK(!eid2);
}
@@ -295,17 +261,17 @@
BOOST_AUTO_TEST_CASE(DuringCallback)
{
EventId eid;
- EventId eid2 = scheduler.scheduleEvent(20_ms, []{});
+ EventId eid2 = scheduler.schedule(20_ms, []{});
bool isCallbackInvoked = false;
- eid = scheduler.scheduleEvent(10_ms, [this, &eid, &eid2, &isCallbackInvoked] {
+ eid = scheduler.schedule(10_ms, [&eid, &eid2, &isCallbackInvoked] {
isCallbackInvoked = true;
// eid is "expired" during callback execution
BOOST_CHECK(!eid);
BOOST_CHECK_NE(eid, eid2);
- scheduler.cancelEvent(eid2);
+ eid2.cancel();
BOOST_CHECK_EQUAL(eid, eid2);
});
@@ -316,7 +282,7 @@
BOOST_AUTO_TEST_CASE(Reset)
{
bool isCallbackInvoked = false;
- EventId eid = scheduler.scheduleEvent(10_ms, [&isCallbackInvoked] { isCallbackInvoked = true; });
+ EventId eid = scheduler.schedule(10_ms, [&isCallbackInvoked] { isCallbackInvoked = true; });
eid.reset();
BOOST_CHECK(!eid);
@@ -331,7 +297,7 @@
EventId eid;
BOOST_CHECK_EQUAL(boost::lexical_cast<std::string>(eid), nullString);
- eid = scheduler.scheduleEvent(10_ms, []{});
+ eid = scheduler.schedule(10_ms, []{});
BOOST_TEST_MESSAGE("eid=" << eid);
BOOST_CHECK_NE(boost::lexical_cast<std::string>(eid), nullString);
}
@@ -346,7 +312,7 @@
{
int hit = 0;
{
- ScopedEventId se = scheduler.scheduleEvent(10_ms, [&] { ++hit; });
+ ScopedEventId se = scheduler.schedule(10_ms, [&] { ++hit; });
} // se goes out of scope
this->advanceClocks(1_ms, 15);
BOOST_CHECK_EQUAL(hit, 0);
@@ -355,8 +321,8 @@
BOOST_AUTO_TEST_CASE(Assign)
{
int hit1 = 0, hit2 = 0;
- ScopedEventId se1 = scheduler.scheduleEvent(10_ms, [&] { ++hit1; });
- se1 = scheduler.scheduleEvent(10_ms, [&] { ++hit2; });
+ ScopedEventId se1 = scheduler.schedule(10_ms, [&] { ++hit1; });
+ se1 = scheduler.schedule(10_ms, [&] { ++hit2; });
this->advanceClocks(1_ms, 15);
BOOST_CHECK_EQUAL(hit1, 0);
BOOST_CHECK_EQUAL(hit2, 1);
@@ -366,7 +332,7 @@
{
int hit = 0;
{
- ScopedEventId se = scheduler.scheduleEvent(10_ms, [&] { ++hit; });
+ ScopedEventId se = scheduler.schedule(10_ms, [&] { ++hit; });
se.release();
} // se goes out of scope
this->advanceClocks(1_ms, 15);
@@ -378,7 +344,7 @@
int hit = 0;
unique_ptr<ScopedEventId> se2;
{
- ScopedEventId se = scheduler.scheduleEvent(10_ms, [&] { ++hit; });
+ ScopedEventId se = scheduler.schedule(10_ms, [&] { ++hit; });
se2 = make_unique<ScopedEventId>(std::move(se)); // move constructor
} // se goes out of scope
this->advanceClocks(1_ms, 15);
@@ -386,7 +352,7 @@
ScopedEventId se3;
{
- ScopedEventId se = scheduler.scheduleEvent(10_ms, [&] { ++hit; });
+ ScopedEventId se = scheduler.schedule(10_ms, [&] { ++hit; });
se3 = std::move(se); // move assignment
} // se goes out of scope
this->advanceClocks(1_ms, 15);
diff --git a/tests/unit/util/time-unit-test-clock.t.cpp b/tests/unit/util/time-unit-test-clock.t.cpp
index c47bdda..b65c9f9 100644
--- a/tests/unit/util/time-unit-test-clock.t.cpp
+++ b/tests/unit/util/time-unit-test-clock.t.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2013-2018 Regents of the University of California.
+ * Copyright (c) 2013-2019 Regents of the University of California.
*
* This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
*
@@ -120,7 +120,7 @@
ndn::Scheduler scheduler(io);
bool hasFired = false;
- scheduler.scheduleEvent(100_s, [&] { hasFired = true; });
+ scheduler.schedule(100_s, [&] { hasFired = true; });
io.poll();
BOOST_CHECK_EQUAL(hasFired, false);