mirror of https://github.com/aria2/aria2
2009-02-08 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
Rewritten AdaptiveURISelector::mayRetryWithIncreasedTimeout() using RequestGroup::extractURIResult(). * src/AdaptiveURISelector.cc * src/RequestGroup.cc * src/RequestGroup.h * test/RequestGroupTest.ccpull/1/head
parent
b8d177dd5d
commit
9bb57720cf
|
@ -1,3 +1,12 @@
|
||||||
|
2009-02-08 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
|
||||||
|
|
||||||
|
Rewritten AdaptiveURISelector::mayRetryWithIncreasedTimeout()
|
||||||
|
using RequestGroup::extractURIResult().
|
||||||
|
* src/AdaptiveURISelector.cc
|
||||||
|
* src/RequestGroup.cc
|
||||||
|
* src/RequestGroup.h
|
||||||
|
* test/RequestGroupTest.cc
|
||||||
|
|
||||||
2009-02-08 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
|
2009-02-08 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
|
||||||
|
|
||||||
Added tests for array_ptr.
|
Added tests for array_ptr.
|
||||||
|
|
|
@ -99,18 +99,17 @@ void AdaptiveURISelector::mayRetryWithIncreasedTimeout
|
||||||
_requestGroup->setTimeout(_requestGroup->getTimeout()*2);
|
_requestGroup->setTimeout(_requestGroup->getTimeout()*2);
|
||||||
|
|
||||||
// looking for retries
|
// looking for retries
|
||||||
const std::deque<URIResult>& uriResults = _requestGroup->getURIResults();
|
std::deque<URIResult> timeouts;
|
||||||
for (std::deque<URIResult>::const_iterator i = uriResults.begin();
|
_requestGroup->extractURIResult(timeouts, DownloadResult::TIME_OUT);
|
||||||
i != uriResults.end(); ++i) {
|
std::transform(timeouts.begin(), timeouts.end(), std::back_inserter(uris),
|
||||||
if ((*i).getResult() == DownloadResult::TIME_OUT) {
|
std::mem_fun_ref(&URIResult::getURI));
|
||||||
_logger->debug("AdaptiveURISelector: will retry server with increased"
|
|
||||||
" timeout (%d s): %s",
|
for(std::deque<std::string>::const_iterator i = uris.begin(); i != uris.end();
|
||||||
_requestGroup->getTimeout(), (*i).getURI().c_str());
|
++i) {
|
||||||
uris.push_back((*i).getURI());
|
_logger->debug("AdaptiveURISelector: will retry server with increased"
|
||||||
}
|
" timeout (%d s): %s",
|
||||||
|
_requestGroup->getTimeout(), (*i).c_str());
|
||||||
}
|
}
|
||||||
std::sort(uris.begin(), uris.end());
|
|
||||||
uris.erase(std::unique(uris.begin(), uris.end()), uris.end());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string AdaptiveURISelector::selectOne(const std::deque<std::string>& uris)
|
std::string AdaptiveURISelector::selectOne(const std::deque<std::string>& uris)
|
||||||
|
|
|
@ -1135,6 +1135,28 @@ const std::deque<URIResult>& RequestGroup::getURIResults() const
|
||||||
return _uriResults;
|
return _uriResults;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class FindURIResultByResult {
|
||||||
|
private:
|
||||||
|
DownloadResult::RESULT _r;
|
||||||
|
public:
|
||||||
|
FindURIResultByResult(DownloadResult::RESULT r):_r(r) {}
|
||||||
|
|
||||||
|
bool operator()(const URIResult& uriResult) const
|
||||||
|
{
|
||||||
|
return uriResult.getResult() == _r;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
void RequestGroup::extractURIResult
|
||||||
|
(std::deque<URIResult>& res, DownloadResult::RESULT r)
|
||||||
|
{
|
||||||
|
std::deque<URIResult>::iterator i =
|
||||||
|
std::stable_partition(_uriResults.begin(), _uriResults.end(),
|
||||||
|
FindURIResultByResult(r));
|
||||||
|
std::copy(_uriResults.begin(), i, std::back_inserter(res));
|
||||||
|
_uriResults.erase(_uriResults.begin(), i);
|
||||||
|
}
|
||||||
|
|
||||||
void RequestGroup::setTimeout(time_t timeout)
|
void RequestGroup::setTimeout(time_t timeout)
|
||||||
{
|
{
|
||||||
_timeout = timeout;
|
_timeout = timeout;
|
||||||
|
|
|
@ -333,6 +333,10 @@ public:
|
||||||
|
|
||||||
const std::deque<URIResult>& getURIResults() const;
|
const std::deque<URIResult>& getURIResults() const;
|
||||||
|
|
||||||
|
// Extracts URIResult whose _result is r and stores them into res.
|
||||||
|
// The extracted URIResults are removed from _uriResults.
|
||||||
|
void extractURIResult(std::deque<URIResult>& res, DownloadResult::RESULT r);
|
||||||
|
|
||||||
void dependsOn(const SharedHandle<Dependency>& dep);
|
void dependsOn(const SharedHandle<Dependency>& dep);
|
||||||
|
|
||||||
bool isDependencyResolved();
|
bool isDependencyResolved();
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
#include "RequestGroup.h"
|
#include "RequestGroup.h"
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
#include <cppunit/extensions/HelperMacros.h>
|
#include <cppunit/extensions/HelperMacros.h>
|
||||||
|
|
||||||
#include "ServerHost.h"
|
#include "ServerHost.h"
|
||||||
|
@ -17,6 +18,7 @@ class RequestGroupTest : public CppUnit::TestFixture {
|
||||||
CPPUNIT_TEST(testRemoveURIWhoseHostnameIs);
|
CPPUNIT_TEST(testRemoveURIWhoseHostnameIs);
|
||||||
CPPUNIT_TEST(testGetFilePath);
|
CPPUNIT_TEST(testGetFilePath);
|
||||||
CPPUNIT_TEST(testCreateDownloadResult);
|
CPPUNIT_TEST(testCreateDownloadResult);
|
||||||
|
CPPUNIT_TEST(testExtractURIResult);
|
||||||
CPPUNIT_TEST_SUITE_END();
|
CPPUNIT_TEST_SUITE_END();
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
@ -27,6 +29,7 @@ public:
|
||||||
void testRemoveURIWhoseHostnameIs();
|
void testRemoveURIWhoseHostnameIs();
|
||||||
void testGetFilePath();
|
void testGetFilePath();
|
||||||
void testCreateDownloadResult();
|
void testCreateDownloadResult();
|
||||||
|
void testExtractURIResult();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -139,4 +142,33 @@ void RequestGroupTest::testCreateDownloadResult()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void RequestGroupTest::testExtractURIResult()
|
||||||
|
{
|
||||||
|
Option op;
|
||||||
|
RequestGroup group(&op, std::deque<std::string>());
|
||||||
|
group.addURIResult("http://timeout/file", DownloadResult::TIME_OUT);
|
||||||
|
group.addURIResult("http://finished/file", DownloadResult::FINISHED);
|
||||||
|
group.addURIResult("http://timeout/file2", DownloadResult::TIME_OUT);
|
||||||
|
group.addURIResult("http://unknownerror/file", DownloadResult::UNKNOWN_ERROR);
|
||||||
|
|
||||||
|
std::deque<URIResult> res;
|
||||||
|
group.extractURIResult(res, DownloadResult::TIME_OUT);
|
||||||
|
CPPUNIT_ASSERT_EQUAL((size_t)2, res.size());
|
||||||
|
CPPUNIT_ASSERT_EQUAL(std::string("http://timeout/file"), res[0].getURI());
|
||||||
|
CPPUNIT_ASSERT_EQUAL(std::string("http://timeout/file2"), res[1].getURI());
|
||||||
|
|
||||||
|
CPPUNIT_ASSERT_EQUAL((size_t)2, group.getURIResults().size());
|
||||||
|
CPPUNIT_ASSERT_EQUAL(std::string("http://finished/file"),
|
||||||
|
group.getURIResults()[0].getURI());
|
||||||
|
CPPUNIT_ASSERT_EQUAL(std::string("http://unknownerror/file"),
|
||||||
|
group.getURIResults()[1].getURI());
|
||||||
|
|
||||||
|
res.clear();
|
||||||
|
|
||||||
|
group.extractURIResult(res, DownloadResult::TIME_OUT);
|
||||||
|
CPPUNIT_ASSERT(res.empty());
|
||||||
|
CPPUNIT_ASSERT_EQUAL((size_t)2, group.getURIResults().size());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
} // namespace aria2
|
} // namespace aria2
|
||||||
|
|
Loading…
Reference in New Issue