mirror of
https://github.com/aria2/aria2.git
synced 2025-04-06 05:57:36 +03:00
2010-07-14 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
Added --max-connection-per-server=NUM option. The default value of NUM is 1. This option limits the number of connections allowed to one server for each download. This means when NUM is 2 and 1 URI is provided, even if you specified -s 5, aria2 establishes 2 connections. Default value of -j option is changed from 5 to 2. * src/BtDependency.cc * src/CreateRequestCommand.cc * src/FileEntry.cc * src/FileEntry.h * src/FtpNegotiationCommand.cc * src/HttpResponseCommand.cc * src/Metalink2RequestGroup.cc * src/OptionHandlerFactory.cc * src/TrackerWatcherCommand.cc * src/download_helper.cc * src/prefs.cc * src/prefs.h * src/usage_text.h * test/DownloadHelperTest.cc * test/FileEntryTest.cc
This commit is contained in:
parent
8274432f14
commit
c99960aa33
16 changed files with 260 additions and 129 deletions
|
@ -3,6 +3,7 @@
|
|||
#include <cppunit/extensions/HelperMacros.h>
|
||||
|
||||
#include "InOrderURISelector.h"
|
||||
#include "util.h"
|
||||
|
||||
namespace aria2 {
|
||||
|
||||
|
@ -13,7 +14,8 @@ class FileEntryTest : public CppUnit::TestFixture {
|
|||
CPPUNIT_TEST(testRemoveURIWhoseHostnameIs);
|
||||
CPPUNIT_TEST(testExtractURIResult);
|
||||
CPPUNIT_TEST(testGetRequest);
|
||||
CPPUNIT_TEST(testGetRequest_disableSingleHostMultiConnection);
|
||||
CPPUNIT_TEST(testGetRequest_withoutUriReuse);
|
||||
CPPUNIT_TEST(testGetRequest_withUniqueProtocol);
|
||||
CPPUNIT_TEST(testReuseUri);
|
||||
CPPUNIT_TEST(testAddUri);
|
||||
CPPUNIT_TEST(testAddUris);
|
||||
|
@ -27,7 +29,8 @@ public:
|
|||
void testRemoveURIWhoseHostnameIs();
|
||||
void testExtractURIResult();
|
||||
void testGetRequest();
|
||||
void testGetRequest_disableSingleHostMultiConnection();
|
||||
void testGetRequest_withoutUriReuse();
|
||||
void testGetRequest_withUniqueProtocol();
|
||||
void testReuseUri();
|
||||
void testAddUri();
|
||||
void testAddUris();
|
||||
|
@ -109,7 +112,6 @@ void FileEntryTest::testGetRequest()
|
|||
SharedHandle<Request> req = fileEntry->getRequest(selector);
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("localhost"), req->getHost());
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("http"), req->getProtocol());
|
||||
|
||||
fileEntry->poolRequest(req);
|
||||
|
||||
SharedHandle<Request> req2nd = fileEntry->getRequest(selector);
|
||||
|
@ -117,14 +119,51 @@ void FileEntryTest::testGetRequest()
|
|||
CPPUNIT_ASSERT_EQUAL(std::string("http"), req2nd->getProtocol());
|
||||
|
||||
SharedHandle<Request> req3rd = fileEntry->getRequest(selector);
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("localhost"), req3rd->getHost());
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("ftp"), req3rd->getProtocol());
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("mirror"), req3rd->getHost());
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("http"), req3rd->getProtocol());
|
||||
|
||||
SharedHandle<Request> req4th = fileEntry->getRequest(selector);
|
||||
CPPUNIT_ASSERT(req4th.isNull());
|
||||
|
||||
fileEntry->setMaxConnectionPerServer(2);
|
||||
|
||||
SharedHandle<Request> req5th = fileEntry->getRequest(selector);
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("localhost"), req5th->getHost());
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("ftp"), req5th->getProtocol());
|
||||
|
||||
SharedHandle<Request> req6th = fileEntry->getRequest(selector);
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("mirror"), req6th->getHost());
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("http"), req6th->getProtocol());
|
||||
|
||||
SharedHandle<Request> req7th = fileEntry->getRequest(selector);
|
||||
CPPUNIT_ASSERT(req7th.isNull());
|
||||
}
|
||||
|
||||
void FileEntryTest::testGetRequest_disableSingleHostMultiConnection()
|
||||
void FileEntryTest::testGetRequest_withoutUriReuse()
|
||||
{
|
||||
SharedHandle<FileEntry> fileEntry = createFileEntry();
|
||||
fileEntry->disableSingleHostMultiConnection();
|
||||
fileEntry->setMaxConnectionPerServer(2);
|
||||
SharedHandle<InOrderURISelector> selector(new InOrderURISelector());
|
||||
SharedHandle<Request> req = fileEntry->getRequest(selector, false);
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("localhost"), req->getHost());
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("http"), req->getProtocol());
|
||||
|
||||
SharedHandle<Request> req2nd = fileEntry->getRequest(selector, false);
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("localhost"), req2nd->getHost());
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("ftp"), req2nd->getProtocol());
|
||||
|
||||
SharedHandle<Request> req3rd = fileEntry->getRequest(selector, false);
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("mirror"), req3rd->getHost());
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("http"), req3rd->getProtocol());
|
||||
|
||||
SharedHandle<Request> req4th = fileEntry->getRequest(selector, false);
|
||||
CPPUNIT_ASSERT(req4th.isNull());
|
||||
}
|
||||
|
||||
void FileEntryTest::testGetRequest_withUniqueProtocol()
|
||||
{
|
||||
SharedHandle<FileEntry> fileEntry = createFileEntry();
|
||||
fileEntry->setUniqueProtocol(true);
|
||||
SharedHandle<InOrderURISelector> selector(new InOrderURISelector());
|
||||
SharedHandle<Request> req = fileEntry->getRequest(selector);
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("localhost"), req->getHost());
|
||||
|
@ -136,25 +175,42 @@ void FileEntryTest::testGetRequest_disableSingleHostMultiConnection()
|
|||
|
||||
SharedHandle<Request> req3rd = fileEntry->getRequest(selector);
|
||||
CPPUNIT_ASSERT(req3rd.isNull());
|
||||
|
||||
CPPUNIT_ASSERT_EQUAL((size_t)2, fileEntry->getRemainingUris().size());
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("ftp://localhost/aria2.zip"),
|
||||
fileEntry->getRemainingUris()[0]);
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("http://mirror/aria2.zip"),
|
||||
fileEntry->getRemainingUris()[1]);
|
||||
}
|
||||
|
||||
void FileEntryTest::testReuseUri()
|
||||
{
|
||||
SharedHandle<InOrderURISelector> selector(new InOrderURISelector());
|
||||
SharedHandle<FileEntry> fileEntry = createFileEntry();
|
||||
fileEntry->setMaxConnectionPerServer(3);
|
||||
size_t numUris = fileEntry->getRemainingUris().size();
|
||||
for(size_t i = 0; i < numUris; ++i) {
|
||||
fileEntry->getRequest(selector);
|
||||
fileEntry->getRequest(selector, false);
|
||||
}
|
||||
CPPUNIT_ASSERT_EQUAL((size_t)0, fileEntry->getRemainingUris().size());
|
||||
fileEntry->addURIResult("http://localhost/aria2.zip",
|
||||
downloadresultcode::UNKNOWN_ERROR);
|
||||
fileEntry->reuseUri(3);
|
||||
CPPUNIT_ASSERT_EQUAL((size_t)3, fileEntry->getRemainingUris().size());
|
||||
const std::deque<std::string>& uris = fileEntry->getRemainingUris();
|
||||
std::vector<std::string> ignore;
|
||||
fileEntry->reuseUri(ignore);
|
||||
CPPUNIT_ASSERT_EQUAL((size_t)2, fileEntry->getRemainingUris().size());
|
||||
std::deque<std::string> uris = fileEntry->getRemainingUris();
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("ftp://localhost/aria2.zip"), uris[0]);
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("http://mirror/aria2.zip"), uris[1]);
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("ftp://localhost/aria2.zip"), uris[2]);
|
||||
for(size_t i = 0; i < 2; ++i) {
|
||||
fileEntry->getRequest(selector, false);
|
||||
}
|
||||
CPPUNIT_ASSERT_EQUAL((size_t)0, fileEntry->getRemainingUris().size());
|
||||
ignore.clear();
|
||||
ignore.push_back("mirror");
|
||||
fileEntry->reuseUri(ignore);
|
||||
CPPUNIT_ASSERT_EQUAL((size_t)1, fileEntry->getRemainingUris().size());
|
||||
uris = fileEntry->getRemainingUris();
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("ftp://localhost/aria2.zip"), uris[0]);
|
||||
}
|
||||
|
||||
void FileEntryTest::testAddUri()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue