face: Convert to use the global IO service by all ChannelFactories
Change-Id: Ibd8d5cea142171b5700d8920eb3eedc084bbd588
diff --git a/tests/face/tcp.cpp b/tests/face/tcp.cpp
index 5990ab4..cba8796 100644
--- a/tests/face/tcp.cpp
+++ b/tests/face/tcp.cpp
@@ -17,8 +17,7 @@
BOOST_AUTO_TEST_CASE(ChannelMap)
{
- boost::asio::io_service io;
- TcpChannelFactory factory(io);
+ TcpChannelFactory factory;
shared_ptr<TcpChannel> channel1 = factory.create("127.0.0.1", "20070");
shared_ptr<TcpChannel> channel1a = factory.create("127.0.0.1", "20070");
@@ -147,7 +146,7 @@
void
abortTestCase(const std::string& message)
{
- m_ioService.stop();
+ g_io.stop();
BOOST_FAIL(message);
}
@@ -155,12 +154,11 @@
void
afterIo()
{
- if (--m_ioRemaining <= 0) m_ioService.stop();
+ if (--m_ioRemaining <= 0)
+ g_io.stop();
}
public:
- boost::asio::io_service m_ioService;
-
int m_ioRemaining;
shared_ptr<Face> m_face1;
@@ -176,13 +174,12 @@
BOOST_FIXTURE_TEST_CASE(EndToEnd, EndToEndFixture)
{
- TcpChannelFactory factory(m_ioService);
- Scheduler scheduler(m_ioService); // to limit the amount of time the test may take
+ TcpChannelFactory factory;
EventId abortEvent =
- scheduler.scheduleEvent(time::seconds(10),
- bind(&EndToEndFixture::abortTestCase, this,
- "TcpChannel error: cannot connect or cannot accept connection"));
+ scheduler::schedule(time::seconds(10),
+ bind(&EndToEndFixture::abortTestCase, this,
+ "TcpChannel error: cannot connect or cannot accept connection"));
shared_ptr<TcpChannel> channel1 = factory.create("127.0.0.1", "20070");
shared_ptr<TcpChannel> channel2 = factory.create("127.0.0.1", "20071");
@@ -196,9 +193,9 @@
time::seconds(4));
m_ioRemaining = 2;
- m_ioService.run();
- m_ioService.reset();
- scheduler.cancelEvent(abortEvent);
+ g_io.run();
+ g_io.reset();
+ scheduler::cancel(abortEvent);
BOOST_REQUIRE(static_cast<bool>(m_face1));
BOOST_REQUIRE(static_cast<bool>(m_face2));
@@ -212,9 +209,9 @@
// integrated tests needs to check that TcpFace for non-loopback fails these tests...
abortEvent =
- scheduler.scheduleEvent(time::seconds(10),
- bind(&EndToEndFixture::abortTestCase, this,
- "TcpChannel error: cannot send or receive Interest/Data packets"));
+ scheduler::schedule(time::seconds(10),
+ bind(&EndToEndFixture::abortTestCase, this,
+ "TcpChannel error: cannot send or receive Interest/Data packets"));
Interest interest1("ndn:/TpnzGvW9R");
Data data1 ("ndn:/KfczhUqVix");
@@ -236,8 +233,9 @@
m_face2->sendData (data2 );
m_ioRemaining = 4;
- m_ioService.run();
- m_ioService.reset();
+ g_io.run();
+ g_io.reset();
+ scheduler::cancel(abortEvent);
BOOST_REQUIRE_EQUAL(m_face1_receivedInterests.size(), 1);
BOOST_REQUIRE_EQUAL(m_face1_receivedDatas .size(), 1);
@@ -252,13 +250,12 @@
BOOST_FIXTURE_TEST_CASE(MultipleAccepts, EndToEndFixture)
{
- TcpChannelFactory factory(m_ioService);
- Scheduler scheduler(m_ioService); // to limit the amount of time the test may take
+ TcpChannelFactory factory;
EventId abortEvent =
- scheduler.scheduleEvent(time::seconds(10),
- bind(&EndToEndFixture::abortTestCase, this,
- "TcpChannel error: cannot connect or cannot accept connection"));
+ scheduler::schedule(time::seconds(10),
+ bind(&EndToEndFixture::abortTestCase, this,
+ "TcpChannel error: cannot connect or cannot accept connection"));
shared_ptr<TcpChannel> channel1 = factory.create("127.0.0.1", "20070");
shared_ptr<TcpChannel> channel2 = factory.create("127.0.0.1", "20071");
@@ -272,9 +269,9 @@
time::seconds(4)); // very short timeout
m_ioRemaining = 2;
- m_ioService.run();
- m_ioService.reset();
- scheduler.cancelEvent(abortEvent);
+ g_io.run();
+ g_io.reset();
+ scheduler::cancel(abortEvent);
BOOST_CHECK_EQUAL(m_faces.size(), 2);
@@ -290,7 +287,7 @@
BOOST_CHECK_NE(channel3, channel4);
scheduler
- .scheduleEvent
+ ::schedule
(time::seconds(1),
bind(&TcpChannel::connect, channel4,
"127.0.0.1", "20070",
@@ -303,29 +300,29 @@
m_ioRemaining = 4; // 2 connects and 2 accepts
abortEvent =
- scheduler.scheduleEvent(time::seconds(10),
- bind(&EndToEndFixture::abortTestCase, this,
- "TcpChannel error: cannot connect or cannot accept multiple connections"));
+ scheduler::schedule(time::seconds(10),
+ bind(&EndToEndFixture::abortTestCase, this,
+ "TcpChannel error: cannot connect or cannot accept multiple connections"));
- scheduler.scheduleEvent(time::seconds(0.5),
- bind(&EndToEndFixture::checkFaceList, this, 4));
+ scheduler::schedule(time::seconds(0.5),
+ bind(&EndToEndFixture::checkFaceList, this, 4));
- m_ioService.run();
- m_ioService.reset();
-
+ g_io.run();
+ g_io.reset();
+ scheduler::cancel(abortEvent);
+
BOOST_CHECK_EQUAL(m_faces.size(), 6);
}
BOOST_FIXTURE_TEST_CASE(FaceClosing, EndToEndFixture)
{
- TcpChannelFactory factory(m_ioService);
- Scheduler scheduler(m_ioService); // to limit the amount of time the test may take
+ TcpChannelFactory factory;
EventId abortEvent =
- scheduler.scheduleEvent(time::seconds(10),
- bind(&EndToEndFixture::abortTestCase, this,
- "TcpChannel error: cannot connect or cannot accept connection"));
+ scheduler::schedule(time::seconds(10),
+ bind(&EndToEndFixture::abortTestCase, this,
+ "TcpChannel error: cannot connect or cannot accept connection"));
shared_ptr<TcpChannel> channel1 = factory.create("127.0.0.1", "20070");
shared_ptr<TcpChannel> channel2 = factory.create("127.0.0.1", "20071");
@@ -339,17 +336,18 @@
time::seconds(4)); // very short timeout
m_ioRemaining = 2;
- BOOST_REQUIRE_NO_THROW(m_ioService.run());
- m_ioService.reset();
- scheduler.cancelEvent(abortEvent);
+ g_io.run();
+ // BOOST_REQUIRE_NO_THROW(g_io.run());
+ g_io.reset();
+ scheduler::cancel(abortEvent);
BOOST_CHECK_EQUAL(channel1->size(), 1);
BOOST_CHECK_EQUAL(channel2->size(), 1);
abortEvent =
- scheduler.scheduleEvent(time::seconds(10),
- bind(&EndToEndFixture::abortTestCase, this,
- "FaceClosing error: cannot properly close faces"));
+ scheduler::schedule(time::seconds(10),
+ bind(&EndToEndFixture::abortTestCase, this,
+ "FaceClosing error: cannot properly close faces"));
BOOST_REQUIRE(static_cast<bool>(m_face1));
BOOST_CHECK(static_cast<bool>(m_face2));
@@ -358,9 +356,9 @@
// just double check that we are calling the virtual method
static_pointer_cast<Face>(m_face1)->close();
- BOOST_REQUIRE_NO_THROW(m_ioService.run());
- m_ioService.reset();
- scheduler.cancelEvent(abortEvent);
+ BOOST_REQUIRE_NO_THROW(g_io.run());
+ g_io.reset();
+ scheduler::cancel(abortEvent);
// both faces should get closed
BOOST_CHECK(!static_cast<bool>(m_face1));
diff --git a/tests/face/unix-stream.cpp b/tests/face/unix-stream.cpp
index 8fba080..85bac65 100644
--- a/tests/face/unix-stream.cpp
+++ b/tests/face/unix-stream.cpp
@@ -19,8 +19,7 @@
BOOST_AUTO_TEST_CASE(ChannelMap)
{
- boost::asio::io_service io;
- UnixStreamChannelFactory factory(io);
+ UnixStreamChannelFactory factory;
shared_ptr<UnixStreamChannel> channel1 = factory.create("foo");
shared_ptr<UnixStreamChannel> channel1a = factory.create("foo");
@@ -113,7 +112,7 @@
void
abortTestCase(const std::string& message)
{
- m_ioService.stop();
+ g_io.stop();
BOOST_FAIL(message);
}
@@ -122,12 +121,10 @@
afterIo()
{
if (--m_ioRemaining <= 0)
- m_ioService.stop();
+ g_io.stop();
}
protected:
- boost::asio::io_service m_ioService;
-
int m_ioRemaining;
shared_ptr<UnixStreamFace> m_face1;
@@ -143,34 +140,33 @@
BOOST_FIXTURE_TEST_CASE(EndToEnd, EndToEndFixture)
{
- UnixStreamChannelFactory factory(m_ioService);
- Scheduler scheduler(m_ioService); // to limit the amount of time the test may take
+ UnixStreamChannelFactory factory;
EventId abortEvent =
- scheduler.scheduleEvent(time::seconds(1),
- bind(&EndToEndFixture::abortTestCase, this,
- "UnixStreamChannel error: cannot connect or cannot accept connection"));
+ scheduler::schedule(time::seconds(1),
+ bind(&EndToEndFixture::abortTestCase, this,
+ "UnixStreamChannel error: cannot connect or cannot accept connection"));
shared_ptr<UnixStreamChannel> channel1 = factory.create("foo");
channel1->listen(bind(&EndToEndFixture::channel1_onFaceCreated, this, _1),
bind(&EndToEndFixture::channel1_onConnectFailed, this, _1));
shared_ptr<stream_protocol::socket> client =
- make_shared<stream_protocol::socket>(boost::ref(m_ioService));
+ make_shared<stream_protocol::socket>(boost::ref(g_io));
client->async_connect(stream_protocol::endpoint("foo"),
bind(&EndToEndFixture::client_onConnect, this, _1));
m_ioRemaining = 2;
- m_ioService.run();
- m_ioService.reset();
- scheduler.cancelEvent(abortEvent);
+ g_io.run();
+ g_io.reset();
+ scheduler::cancel(abortEvent);
BOOST_REQUIRE(static_cast<bool>(m_face1));
abortEvent =
- scheduler.scheduleEvent(time::seconds(1),
- bind(&EndToEndFixture::abortTestCase, this,
- "UnixStreamChannel error: cannot send or receive Interest/Data packets"));
+ scheduler::schedule(time::seconds(1),
+ bind(&EndToEndFixture::abortTestCase, this,
+ "UnixStreamChannel error: cannot send or receive Interest/Data packets"));
m_face2 = make_shared<UnixStreamFace>(client);
m_face2->onReceiveInterest +=
@@ -198,8 +194,8 @@
m_face2->sendData (data2 );
m_ioRemaining = 4;
- m_ioService.run();
- m_ioService.reset();
+ g_io.run();
+ g_io.reset();
BOOST_REQUIRE_EQUAL(m_face1_receivedInterests.size(), 1);
BOOST_REQUIRE_EQUAL(m_face1_receivedDatas .size(), 1);
@@ -214,44 +210,43 @@
BOOST_FIXTURE_TEST_CASE(MultipleAccepts, EndToEndFixture)
{
- UnixStreamChannelFactory factory(m_ioService);
- Scheduler scheduler(m_ioService); // to limit the amount of time the test may take
+ UnixStreamChannelFactory factory;
EventId abortEvent =
- scheduler.scheduleEvent(time::seconds(1),
- bind(&EndToEndFixture::abortTestCase, this,
- "UnixStreamChannel error: cannot connect or cannot accept connection"));
+ scheduler::schedule(time::seconds(1),
+ bind(&EndToEndFixture::abortTestCase, this,
+ "UnixStreamChannel error: cannot connect or cannot accept connection"));
shared_ptr<UnixStreamChannel> channel = factory.create("foo");
channel->listen(bind(&EndToEndFixture::channel_onFaceCreated, this, _1),
bind(&EndToEndFixture::channel_onConnectFailed, this, _1));
shared_ptr<stream_protocol::socket> client1 =
- make_shared<stream_protocol::socket>(boost::ref(m_ioService));
+ make_shared<stream_protocol::socket>(boost::ref(g_io));
client1->async_connect(stream_protocol::endpoint("foo"),
bind(&EndToEndFixture::client_onConnect, this, _1));
m_ioRemaining = 2;
- m_ioService.run();
- m_ioService.reset();
- scheduler.cancelEvent(abortEvent);
+ g_io.run();
+ g_io.reset();
+ scheduler::cancel(abortEvent);
BOOST_CHECK_EQUAL(m_faces.size(), 1);
abortEvent =
- scheduler.scheduleEvent(time::seconds(1),
- bind(&EndToEndFixture::abortTestCase, this,
- "UnixStreamChannel error: cannot accept multiple connections"));
+ scheduler::schedule(time::seconds(1),
+ bind(&EndToEndFixture::abortTestCase, this,
+ "UnixStreamChannel error: cannot accept multiple connections"));
shared_ptr<stream_protocol::socket> client2 =
- make_shared<stream_protocol::socket>(boost::ref(m_ioService));
+ make_shared<stream_protocol::socket>(boost::ref(g_io));
client2->async_connect(stream_protocol::endpoint("foo"),
bind(&EndToEndFixture::client_onConnect, this, _1));
m_ioRemaining = 2;
- m_ioService.run();
- m_ioService.reset();
- scheduler.cancelEvent(abortEvent);
+ g_io.run();
+ g_io.reset();
+ scheduler::cancel(abortEvent);
BOOST_CHECK_EQUAL(m_faces.size(), 2);
@@ -272,9 +267,9 @@
bind(&EndToEndFixture::face2_onReceiveData, this, _1);
abortEvent =
- scheduler.scheduleEvent(time::seconds(1),
- bind(&EndToEndFixture::abortTestCase, this,
- "UnixStreamChannel error: cannot send or receive Interest/Data packets"));
+ scheduler::schedule(time::seconds(1),
+ bind(&EndToEndFixture::abortTestCase, this,
+ "UnixStreamChannel error: cannot send or receive Interest/Data packets"));
Interest interest1("ndn:/TpnzGvW9R");
Data data1 ("ndn:/KfczhUqVix");
@@ -296,8 +291,8 @@
m_face2->sendData (data2 );
m_ioRemaining = 4;
- m_ioService.run();
- m_ioService.reset();
+ g_io.run();
+ g_io.reset();
BOOST_REQUIRE_EQUAL(m_face1_receivedInterests.size(), 1);
BOOST_REQUIRE_EQUAL(m_face1_receivedDatas .size(), 1);
@@ -317,34 +312,33 @@
BOOST_FIXTURE_TEST_CASE(UnixStreamFaceLocalControlHeader, EndToEndFixture)
{
- UnixStreamChannelFactory factory(m_ioService);
- Scheduler scheduler(m_ioService); // to limit the amount of time the test may take
+ UnixStreamChannelFactory factory;
EventId abortEvent =
- scheduler.scheduleEvent(time::seconds(1),
- bind(&EndToEndFixture::abortTestCase, this,
- "UnixStreamChannel error: cannot connect or cannot accept connection"));
+ scheduler::schedule(time::seconds(1),
+ bind(&EndToEndFixture::abortTestCase, this,
+ "UnixStreamChannel error: cannot connect or cannot accept connection"));
shared_ptr<UnixStreamChannel> channel1 = factory.create("foo");
channel1->listen(bind(&EndToEndFixture::channel1_onFaceCreated, this, _1),
bind(&EndToEndFixture::channel1_onConnectFailed, this, _1));
shared_ptr<stream_protocol::socket> client =
- make_shared<stream_protocol::socket>(boost::ref(m_ioService));
+ make_shared<stream_protocol::socket>(boost::ref(g_io));
client->async_connect(stream_protocol::endpoint("foo"),
bind(&EndToEndFixture::client_onConnect, this, _1));
m_ioRemaining = 2;
- m_ioService.run();
- m_ioService.reset();
- scheduler.cancelEvent(abortEvent);
+ g_io.run();
+ g_io.reset();
+ scheduler::cancel(abortEvent);
BOOST_REQUIRE(static_cast<bool>(m_face1));
abortEvent =
- scheduler.scheduleEvent(time::seconds(1),
- bind(&EndToEndFixture::abortTestCase, this,
- "UnixStreamChannel error: cannot send or receive Interest/Data packets"));
+ scheduler::schedule(time::seconds(1),
+ bind(&EndToEndFixture::abortTestCase, this,
+ "UnixStreamChannel error: cannot send or receive Interest/Data packets"));
m_face2 = make_shared<UnixStreamFace>(client);
m_face2->onReceiveInterest +=
@@ -393,8 +387,8 @@
//
m_ioRemaining = 2;
- m_ioService.run();
- m_ioService.reset();
+ g_io.run();
+ g_io.reset();
BOOST_REQUIRE_EQUAL(m_face2_receivedInterests.size(), 1);
BOOST_REQUIRE_EQUAL(m_face2_receivedDatas .size(), 1);
@@ -428,8 +422,8 @@
client->async_send(dataWithHeader, bind(&noOp));
m_ioRemaining = 2;
- m_ioService.run();
- m_ioService.reset();
+ g_io.run();
+ g_io.reset();
BOOST_REQUIRE_EQUAL(m_face1_receivedInterests.size(), 1);
BOOST_REQUIRE_EQUAL(m_face1_receivedDatas .size(), 1);