mirror of
https://github.com/aria2/aria2.git
synced 2025-04-05 05:27:38 +03:00
Rewritten PeerStat handling. In the previous implementation, faster command tries to find slower command. In this new implementation, slower command tries to find faster command. PeerStat is now created in each HTTP/FTP request to get download rate correctly. If the download range is small, the download rate tends to small and this will occur at the later stage of download. * src/AbstractCommand.cc * src/DownloadCommand.cc * src/FileEntry.cc * src/FileEntry.h * src/Request.cc * src/Request.h * src/RequestGroup.h * src/RequestGroupMan.cc * src/SegmentMan.cc * src/SegmentMan.h * test/SegmentManTest.cc
84 lines
2.3 KiB
C++
84 lines
2.3 KiB
C++
#include "SegmentMan.h"
|
|
|
|
#include <cppunit/extensions/HelperMacros.h>
|
|
|
|
#include "DownloadContext.h"
|
|
#include "UnknownLengthPieceStorage.h"
|
|
#include "DefaultPieceStorage.h"
|
|
#include "Segment.h"
|
|
#include "Option.h"
|
|
#include "PieceSelector.h"
|
|
|
|
namespace aria2 {
|
|
|
|
class SegmentManTest:public CppUnit::TestFixture {
|
|
|
|
CPPUNIT_TEST_SUITE(SegmentManTest);
|
|
CPPUNIT_TEST(testNullBitfield);
|
|
CPPUNIT_TEST(testCompleteSegment);
|
|
CPPUNIT_TEST_SUITE_END();
|
|
private:
|
|
|
|
public:
|
|
void setUp() {
|
|
}
|
|
|
|
void testNullBitfield();
|
|
void testCompleteSegment();
|
|
void testGetPeerStat();
|
|
void testGetSegment_segmentForward();
|
|
};
|
|
|
|
|
|
CPPUNIT_TEST_SUITE_REGISTRATION( SegmentManTest );
|
|
|
|
void SegmentManTest::testNullBitfield()
|
|
{
|
|
Option op;
|
|
SharedHandle<DownloadContext> dctx
|
|
(new DownloadContext(0, 0, "aria2.tar.bz2"));
|
|
SharedHandle<UnknownLengthPieceStorage> ps
|
|
(new UnknownLengthPieceStorage(dctx, &op));
|
|
SegmentMan segmentMan(&op, dctx, ps);
|
|
|
|
SharedHandle<Segment> segment = segmentMan.getSegment(1);
|
|
CPPUNIT_ASSERT(!segment.isNull());
|
|
CPPUNIT_ASSERT_EQUAL((size_t)0, segment->getIndex());
|
|
CPPUNIT_ASSERT_EQUAL((size_t)0, segment->getLength());
|
|
CPPUNIT_ASSERT_EQUAL((size_t)0, segment->getSegmentLength());
|
|
CPPUNIT_ASSERT_EQUAL((size_t)0, segment->getWrittenLength());
|
|
|
|
SharedHandle<Segment> segment2 = segmentMan.getSegment(2);
|
|
CPPUNIT_ASSERT(segment2.isNull());
|
|
|
|
segmentMan.cancelSegment(1);
|
|
CPPUNIT_ASSERT(!segmentMan.getSegment(2).isNull());
|
|
}
|
|
|
|
void SegmentManTest::testCompleteSegment()
|
|
{
|
|
Option op;
|
|
size_t pieceLength = 1024*1024;
|
|
uint64_t totalLength = 64*1024*1024;
|
|
SharedHandle<DownloadContext> dctx
|
|
(new DownloadContext(pieceLength, totalLength, "aria2.tar.bz2"));
|
|
SharedHandle<DefaultPieceStorage> ps(new DefaultPieceStorage(dctx, &op));
|
|
|
|
SegmentMan segmentMan(&op, dctx, ps);
|
|
|
|
CPPUNIT_ASSERT(!segmentMan.getSegment(1, 0).isNull());
|
|
SharedHandle<Segment> seg = segmentMan.getSegment(1, 1);
|
|
CPPUNIT_ASSERT(!seg.isNull());
|
|
CPPUNIT_ASSERT(!segmentMan.getSegment(1, 2).isNull());
|
|
|
|
seg->updateWrittenLength(pieceLength);
|
|
segmentMan.completeSegment(1, seg);
|
|
|
|
std::deque<SharedHandle<Segment> > segments;
|
|
segmentMan.getInFlightSegment(segments, 1);
|
|
CPPUNIT_ASSERT_EQUAL((size_t)2, segments.size());
|
|
CPPUNIT_ASSERT_EQUAL((size_t)0, segments[0]->getIndex());
|
|
CPPUNIT_ASSERT_EQUAL((size_t)2, segments[1]->getIndex());
|
|
}
|
|
|
|
} // namespace aria2
|