mirror of https://github.com/aria2/aria2
2008-08-09 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Implemented ServerStatMan::removeStaleServerStat() and its test case. * src/ServerStatMan.cc * src/ServerStatMan.h * test/ServerStatManTest.ccpull/1/head
parent
d85014b937
commit
6aba376430
|
@ -1,3 +1,10 @@
|
|||
2008-08-09 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
|
||||
|
||||
Implemented ServerStatMan::removeStaleServerStat() and its test case.
|
||||
* src/ServerStatMan.cc
|
||||
* src/ServerStatMan.h
|
||||
* test/ServerStatManTest.cc
|
||||
|
||||
2008-08-09 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
|
||||
|
||||
Implemented ServerStatMan::load(...) function and its test case.
|
||||
|
|
|
@ -119,4 +119,23 @@ void ServerStatMan::load(std::istream& in)
|
|||
}
|
||||
}
|
||||
|
||||
class FindStaleServerStat {
|
||||
private:
|
||||
time_t _timeout;
|
||||
public:
|
||||
FindStaleServerStat(time_t timeout):_timeout(timeout) {}
|
||||
|
||||
bool operator()(const SharedHandle<ServerStat>& ss) const
|
||||
{
|
||||
return ss->getLastUpdated().elapsed(_timeout);
|
||||
}
|
||||
};
|
||||
|
||||
void ServerStatMan::removeStaleServerStat(time_t timeout)
|
||||
{
|
||||
_serverStats.erase(std::remove_if(_serverStats.begin(), _serverStats.end(),
|
||||
FindStaleServerStat(timeout)),
|
||||
_serverStats.end());
|
||||
}
|
||||
|
||||
} // namespace aria2
|
||||
|
|
|
@ -58,6 +58,8 @@ public:
|
|||
void load(std::istream& in);
|
||||
|
||||
void save(std::ostream& out) const;
|
||||
|
||||
void removeStaleServerStat(time_t timeout);
|
||||
private:
|
||||
std::deque<SharedHandle<ServerStat> > _serverStats;
|
||||
};
|
||||
|
|
|
@ -14,6 +14,7 @@ class ServerStatManTest:public CppUnit::TestFixture {
|
|||
CPPUNIT_TEST(testAddAndFind);
|
||||
CPPUNIT_TEST(testSave);
|
||||
CPPUNIT_TEST(testLoad);
|
||||
CPPUNIT_TEST(testRemoveStaleServerStat);
|
||||
CPPUNIT_TEST_SUITE_END();
|
||||
public:
|
||||
void setUp() {}
|
||||
|
@ -23,6 +24,7 @@ public:
|
|||
void testAddAndFind();
|
||||
void testSave();
|
||||
void testLoad();
|
||||
void testRemoveStaleServerStat();
|
||||
};
|
||||
|
||||
|
||||
|
@ -62,7 +64,7 @@ void ServerStatManTest::testSave()
|
|||
localhost_ftp->setLastUpdated(Time(1210000001));
|
||||
SharedHandle<ServerStat> mirror(new ServerStat("mirror", "http"));
|
||||
mirror->setDownloadSpeed(0);
|
||||
mirror->setError();
|
||||
mirror->setStatus(ServerStat::ERROR);
|
||||
mirror->setLastUpdated(Time(1210000002));
|
||||
|
||||
ServerStatMan ssm;
|
||||
|
@ -108,4 +110,30 @@ void ServerStatManTest::testLoad()
|
|||
CPPUNIT_ASSERT_EQUAL(ServerStat::ERROR, mirror->getStatus());
|
||||
}
|
||||
|
||||
void ServerStatManTest::testRemoveStaleServerStat()
|
||||
{
|
||||
Time now;
|
||||
SharedHandle<ServerStat> localhost_http(new ServerStat("localhost", "http"));
|
||||
localhost_http->setDownloadSpeed(25000);
|
||||
localhost_http->setLastUpdated(now);
|
||||
SharedHandle<ServerStat> localhost_ftp(new ServerStat("localhost", "ftp"));
|
||||
localhost_ftp->setDownloadSpeed(30000);
|
||||
localhost_ftp->setLastUpdated(Time(1210000001));
|
||||
SharedHandle<ServerStat> mirror(new ServerStat("mirror", "http"));
|
||||
mirror->setDownloadSpeed(0);
|
||||
mirror->setStatus(ServerStat::ERROR);
|
||||
mirror->setLastUpdated(Time(1210000002));
|
||||
|
||||
ServerStatMan ssm;
|
||||
CPPUNIT_ASSERT(ssm.add(localhost_http));
|
||||
CPPUNIT_ASSERT(ssm.add(localhost_ftp));
|
||||
CPPUNIT_ASSERT(ssm.add(mirror));
|
||||
|
||||
ssm.removeStaleServerStat(24*60*60);
|
||||
|
||||
CPPUNIT_ASSERT(!ssm.find("localhost", "http").isNull());
|
||||
CPPUNIT_ASSERT(ssm.find("localhost", "ftp").isNull());
|
||||
CPPUNIT_ASSERT(ssm.find("mirror", "http").isNull());
|
||||
}
|
||||
|
||||
} // namespace aria2
|
||||
|
|
Loading…
Reference in New Issue