aria2/test/SegmentManTest.cc

203 lines
6.9 KiB
C++
Raw Normal View History

2006-09-23 11:58:23 +00:00
#include "SegmentMan.h"
#include <cppunit/extensions/HelperMacros.h>
2009-06-28 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net> Rewritten DownloadContext and removed SingleFileDownloadContext and BtContext and its derived classes. BitTorrent specific attributes are now set by DownloadContext::setAttribute() with key bittorrent::BITTORRENT. * src/AbstractBtMessage.cc * src/AbstractBtMessage.h * src/AbstractCommand.cc * src/AbstractCommand.h * src/AbstractProxyRequestCommand.cc * src/AbstractProxyResponseCommand.cc * src/ActivePeerConnectionCommand.cc * src/ActivePeerConnectionCommand.h * src/AnnounceList.cc * src/BtCheckIntegrityEntry.cc * src/BtConstants.h * src/BtContext.h: Removed * src/BtDependency.cc * src/BtExtendedMessage.cc * src/BtPieceMessage.cc * src/BtPieceMessage.h * src/BtPostDownloadHandler.cc * src/BtRegistry.cc * src/BtRegistry.h * src/BtSetup.cc * src/CheckIntegrityCommand.cc * src/CheckIntegrityEntry.cc * src/ChecksumCheckIntegrityEntry.cc * src/ConsoleStatCalc.cc * src/ContentTypeRequestGroupCriteria.cc * src/DHTGetPeersCommand.cc * src/DHTGetPeersCommand.h * src/DHTPeerLookupTask.cc * src/DHTPeerLookupTask.h * src/DHTTaskFactory.h * src/DHTTaskFactoryImpl.cc * src/DHTTaskFactoryImpl.h * src/DefaultBtAnnounce.cc * src/DefaultBtAnnounce.h * src/DefaultBtContext.cc: Removed * src/DefaultBtContext.h: Removed * src/DefaultBtInteractive.cc * src/DefaultBtInteractive.h * src/DefaultBtMessageDispatcher.cc * src/DefaultBtMessageDispatcher.h * src/DefaultBtMessageFactory.cc * src/DefaultBtMessageFactory.h * src/DefaultBtMessageReceiver.cc * src/DefaultBtMessageReceiver.h * src/DefaultBtProgressInfoFile.cc * src/DefaultBtRequestFactory.cc * src/DefaultBtRequestFactory.h * src/DefaultExtensionMessageFactory.cc * src/DefaultExtensionMessageFactory.h * src/DefaultPeerStorage.cc * src/DefaultPeerStorage.h * src/DefaultPieceStorage.cc * src/DefaultSegmentManFactory.cc * src/DiskAdaptor.cc * src/DiskAdaptor.h * src/DownloadContext.cc * src/DownloadContext.h * src/DownloadEngine.cc * src/DownloadEngineFactory.cc * src/DownloadHandler.cc * src/DownloadResult.h * src/FileAllocationCommand.cc * src/FileAllocationDispatcherCommand.cc * src/FileAllocationEntry.cc * src/FileEntry.h * src/FillRequestGroupCommand.cc * src/FtpDownloadCommand.cc * src/FtpFinishDownloadCommand.cc * src/FtpInitiateConnectionCommand.cc * src/FtpNegotiationCommand.cc * src/FtpTunnelRequestCommand.cc * src/FtpTunnelResponseCommand.cc * src/HandshakeExtensionMessage.cc * src/HandshakeExtensionMessage.h * src/HaveEraseCommand.cc * src/HttpDownloadCommand.cc * src/HttpInitiateConnectionCommand.cc * src/HttpProxyRequestCommand.cc * src/HttpProxyResponseCommand.cc * src/HttpRequest.cc * src/HttpRequest.h * src/HttpRequestCommand.cc * src/HttpResponseCommand.cc * src/HttpServerBodyCommand.cc * src/HttpServerCommand.cc * src/HttpSkipResponseCommand.cc * src/InitiateConnectionCommandFactory.cc * src/InitiatorMSEHandshakeCommand.cc * src/InitiatorMSEHandshakeCommand.h * src/IteratableChecksumValidator.cc * src/IteratableChecksumValidator.h * src/IteratableChunkChecksumValidator.cc * src/MSEHandshake.cc * src/MSEHandshake.h * src/Makefile.am * src/Makefile.in * src/Metalink2RequestGroup.cc * src/MetalinkPostDownloadHandler.cc * src/MultiDiskAdaptor.cc * src/MultiDiskAdaptor.h * src/MultiFileAllocationIterator.cc * src/MultiUrlRequestInfo.cc * src/PeerChokeCommand.cc * src/PeerChokeCommand.h * src/PeerInitiateConnectionCommand.cc * src/PeerInitiateConnectionCommand.h * src/PeerInteractionCommand.cc * src/PeerInteractionCommand.h * src/PeerReceiveHandshakeCommand.cc * src/PieceHashCheckIntegrityEntry.cc * src/RealtimeCommand.cc * src/ReceiverMSEHandshakeCommand.cc * src/RequestGroup.cc * src/RequestGroup.h * src/RequestGroupEntry.cc * src/RequestGroupMan.cc * src/SeedCheckCommand.cc * src/SeedCheckCommand.h * src/SegmentMan.cc * src/ShareRatioSeedCriteria.h * src/SingleFileDownloadContext.cc: Removed * src/SingleFileDownloadContext.h: Removed * src/SleepCommand.cc * src/StreamCheckIntegrityEntry.cc * src/TrackerWatcherCommand.cc * src/TrackerWatcherCommand.h * src/UnknownLengthPieceStorage.cc * src/Util.cc * src/Util.h * src/XmlRpcMethodImpl.cc * src/bittorrent_helper.cc * src/bittorrent_helper.h * src/download_helper.cc * src/main.cc * src/option_processing.cc * test/BitfieldManTest.cc * test/BittorrentHelperTest.cc * test/BtCancelMessageTest.cc * test/BtChokeMessageTest.cc * test/BtDependencyTest.cc * test/BtPieceMessageTest.cc * test/BtPostDownloadHandlerTest.cc * test/BtRegistryTest.cc * test/BtRejectMessageTest.cc * test/BtRequestMessageTest.cc * test/DHTPeerAnnounceStorageTest.cc * test/DefaultBtAnnounceTest.cc * test/DefaultBtContextTest.cc: Removed * test/DefaultBtMessageDispatcherTest.cc * test/DefaultBtMessageFactoryTest.cc * test/DefaultBtProgressInfoFileTest.cc * test/DefaultBtRequestFactoryTest.cc * test/DefaultExtensionMessageFactoryTest.cc * test/DefaultPeerStorageTest.cc * test/DefaultPieceStorageTest.cc * test/DirectDiskAdaptorTest.cc * test/DownloadContextTest.cc * test/DownloadHandlerFactoryTest.cc * test/DownloadHelperTest.cc * test/HandshakeExtensionMessageTest.cc * test/HttpRequestTest.cc * test/HttpResponseTest.cc * test/IteratableChecksumValidatorTest.cc * test/IteratableChunkChecksumValidatorTest.cc * test/MSEHandshakeTest.cc * test/Makefile.am * test/Makefile.in * test/Metalink2RequestGroupTest.cc * test/MetalinkPostDownloadHandlerTest.cc * test/MockBtContext.h: Removed * test/MockDHTTaskFactory.h * test/MockDownloadContext.h: Removed * test/MockPieceStorage.h * test/MultiDiskAdaptorTest.cc * test/MultiFileAllocationIteratorTest.cc * test/RequestGroupManTest.cc * test/RequestGroupTest.cc * test/SegmentManTest.cc * test/ShareRatioSeedCriteriaTest.cc * test/SingleFileDownloadContextTest.cc: Removed * test/UtilTest.cc * test/XmlRpcMethodTest.cc
2009-06-28 10:37:15 +00:00
#include "DownloadContext.h"
#include "UnknownLengthPieceStorage.h"
#include "DefaultPieceStorage.h"
#include "Segment.h"
#include "Option.h"
#include "PieceSelector.h"
#include "FileEntry.h"
#include "PeerStat.h"
2006-09-23 11:58:23 +00:00
namespace aria2 {
2006-09-23 11:58:23 +00:00
class SegmentManTest:public CppUnit::TestFixture {
CPPUNIT_TEST_SUITE(SegmentManTest);
CPPUNIT_TEST(testNullBitfield);
CPPUNIT_TEST(testCompleteSegment);
CPPUNIT_TEST(testGetSegment_sameFileEntry);
CPPUNIT_TEST(testRegisterPeerStat);
CPPUNIT_TEST(testCancelAllSegments);
CPPUNIT_TEST(testGetPeerStat);
CPPUNIT_TEST(testGetCleanSegmentIfOwnerIsIdle);
2006-09-23 11:58:23 +00:00
CPPUNIT_TEST_SUITE_END();
private:
SharedHandle<Option> option_;
SharedHandle<DownloadContext> dctx_;
SharedHandle<DefaultPieceStorage> pieceStorage_;
SharedHandle<SegmentMan> segmentMan_;
2006-09-23 11:58:23 +00:00
public:
void setUp()
{
size_t pieceLength = 1024*1024;
uint64_t totalLength = 64*1024*1024;
option_.reset(new Option());
dctx_.reset
(new DownloadContext(pieceLength, totalLength, "aria2.tar.bz2"));
pieceStorage_.reset(new DefaultPieceStorage(dctx_, option_.get()));
segmentMan_.reset(new SegmentMan(option_.get(), dctx_, pieceStorage_));
2006-09-23 11:58:23 +00:00
}
void testNullBitfield();
void testCompleteSegment();
void testGetSegment_sameFileEntry();
void testRegisterPeerStat();
void testCancelAllSegments();
void testGetPeerStat();
void testGetCleanSegmentIfOwnerIsIdle();
2006-09-23 11:58:23 +00:00
};
CPPUNIT_TEST_SUITE_REGISTRATION( SegmentManTest );
void SegmentManTest::testNullBitfield()
{
2006-09-23 11:58:23 +00:00
Option op;
2009-06-28 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net> Rewritten DownloadContext and removed SingleFileDownloadContext and BtContext and its derived classes. BitTorrent specific attributes are now set by DownloadContext::setAttribute() with key bittorrent::BITTORRENT. * src/AbstractBtMessage.cc * src/AbstractBtMessage.h * src/AbstractCommand.cc * src/AbstractCommand.h * src/AbstractProxyRequestCommand.cc * src/AbstractProxyResponseCommand.cc * src/ActivePeerConnectionCommand.cc * src/ActivePeerConnectionCommand.h * src/AnnounceList.cc * src/BtCheckIntegrityEntry.cc * src/BtConstants.h * src/BtContext.h: Removed * src/BtDependency.cc * src/BtExtendedMessage.cc * src/BtPieceMessage.cc * src/BtPieceMessage.h * src/BtPostDownloadHandler.cc * src/BtRegistry.cc * src/BtRegistry.h * src/BtSetup.cc * src/CheckIntegrityCommand.cc * src/CheckIntegrityEntry.cc * src/ChecksumCheckIntegrityEntry.cc * src/ConsoleStatCalc.cc * src/ContentTypeRequestGroupCriteria.cc * src/DHTGetPeersCommand.cc * src/DHTGetPeersCommand.h * src/DHTPeerLookupTask.cc * src/DHTPeerLookupTask.h * src/DHTTaskFactory.h * src/DHTTaskFactoryImpl.cc * src/DHTTaskFactoryImpl.h * src/DefaultBtAnnounce.cc * src/DefaultBtAnnounce.h * src/DefaultBtContext.cc: Removed * src/DefaultBtContext.h: Removed * src/DefaultBtInteractive.cc * src/DefaultBtInteractive.h * src/DefaultBtMessageDispatcher.cc * src/DefaultBtMessageDispatcher.h * src/DefaultBtMessageFactory.cc * src/DefaultBtMessageFactory.h * src/DefaultBtMessageReceiver.cc * src/DefaultBtMessageReceiver.h * src/DefaultBtProgressInfoFile.cc * src/DefaultBtRequestFactory.cc * src/DefaultBtRequestFactory.h * src/DefaultExtensionMessageFactory.cc * src/DefaultExtensionMessageFactory.h * src/DefaultPeerStorage.cc * src/DefaultPeerStorage.h * src/DefaultPieceStorage.cc * src/DefaultSegmentManFactory.cc * src/DiskAdaptor.cc * src/DiskAdaptor.h * src/DownloadContext.cc * src/DownloadContext.h * src/DownloadEngine.cc * src/DownloadEngineFactory.cc * src/DownloadHandler.cc * src/DownloadResult.h * src/FileAllocationCommand.cc * src/FileAllocationDispatcherCommand.cc * src/FileAllocationEntry.cc * src/FileEntry.h * src/FillRequestGroupCommand.cc * src/FtpDownloadCommand.cc * src/FtpFinishDownloadCommand.cc * src/FtpInitiateConnectionCommand.cc * src/FtpNegotiationCommand.cc * src/FtpTunnelRequestCommand.cc * src/FtpTunnelResponseCommand.cc * src/HandshakeExtensionMessage.cc * src/HandshakeExtensionMessage.h * src/HaveEraseCommand.cc * src/HttpDownloadCommand.cc * src/HttpInitiateConnectionCommand.cc * src/HttpProxyRequestCommand.cc * src/HttpProxyResponseCommand.cc * src/HttpRequest.cc * src/HttpRequest.h * src/HttpRequestCommand.cc * src/HttpResponseCommand.cc * src/HttpServerBodyCommand.cc * src/HttpServerCommand.cc * src/HttpSkipResponseCommand.cc * src/InitiateConnectionCommandFactory.cc * src/InitiatorMSEHandshakeCommand.cc * src/InitiatorMSEHandshakeCommand.h * src/IteratableChecksumValidator.cc * src/IteratableChecksumValidator.h * src/IteratableChunkChecksumValidator.cc * src/MSEHandshake.cc * src/MSEHandshake.h * src/Makefile.am * src/Makefile.in * src/Metalink2RequestGroup.cc * src/MetalinkPostDownloadHandler.cc * src/MultiDiskAdaptor.cc * src/MultiDiskAdaptor.h * src/MultiFileAllocationIterator.cc * src/MultiUrlRequestInfo.cc * src/PeerChokeCommand.cc * src/PeerChokeCommand.h * src/PeerInitiateConnectionCommand.cc * src/PeerInitiateConnectionCommand.h * src/PeerInteractionCommand.cc * src/PeerInteractionCommand.h * src/PeerReceiveHandshakeCommand.cc * src/PieceHashCheckIntegrityEntry.cc * src/RealtimeCommand.cc * src/ReceiverMSEHandshakeCommand.cc * src/RequestGroup.cc * src/RequestGroup.h * src/RequestGroupEntry.cc * src/RequestGroupMan.cc * src/SeedCheckCommand.cc * src/SeedCheckCommand.h * src/SegmentMan.cc * src/ShareRatioSeedCriteria.h * src/SingleFileDownloadContext.cc: Removed * src/SingleFileDownloadContext.h: Removed * src/SleepCommand.cc * src/StreamCheckIntegrityEntry.cc * src/TrackerWatcherCommand.cc * src/TrackerWatcherCommand.h * src/UnknownLengthPieceStorage.cc * src/Util.cc * src/Util.h * src/XmlRpcMethodImpl.cc * src/bittorrent_helper.cc * src/bittorrent_helper.h * src/download_helper.cc * src/main.cc * src/option_processing.cc * test/BitfieldManTest.cc * test/BittorrentHelperTest.cc * test/BtCancelMessageTest.cc * test/BtChokeMessageTest.cc * test/BtDependencyTest.cc * test/BtPieceMessageTest.cc * test/BtPostDownloadHandlerTest.cc * test/BtRegistryTest.cc * test/BtRejectMessageTest.cc * test/BtRequestMessageTest.cc * test/DHTPeerAnnounceStorageTest.cc * test/DefaultBtAnnounceTest.cc * test/DefaultBtContextTest.cc: Removed * test/DefaultBtMessageDispatcherTest.cc * test/DefaultBtMessageFactoryTest.cc * test/DefaultBtProgressInfoFileTest.cc * test/DefaultBtRequestFactoryTest.cc * test/DefaultExtensionMessageFactoryTest.cc * test/DefaultPeerStorageTest.cc * test/DefaultPieceStorageTest.cc * test/DirectDiskAdaptorTest.cc * test/DownloadContextTest.cc * test/DownloadHandlerFactoryTest.cc * test/DownloadHelperTest.cc * test/HandshakeExtensionMessageTest.cc * test/HttpRequestTest.cc * test/HttpResponseTest.cc * test/IteratableChecksumValidatorTest.cc * test/IteratableChunkChecksumValidatorTest.cc * test/MSEHandshakeTest.cc * test/Makefile.am * test/Makefile.in * test/Metalink2RequestGroupTest.cc * test/MetalinkPostDownloadHandlerTest.cc * test/MockBtContext.h: Removed * test/MockDHTTaskFactory.h * test/MockDownloadContext.h: Removed * test/MockPieceStorage.h * test/MultiDiskAdaptorTest.cc * test/MultiFileAllocationIteratorTest.cc * test/RequestGroupManTest.cc * test/RequestGroupTest.cc * test/SegmentManTest.cc * test/ShareRatioSeedCriteriaTest.cc * test/SingleFileDownloadContextTest.cc: Removed * test/UtilTest.cc * test/XmlRpcMethodTest.cc
2009-06-28 10:37:15 +00:00
SharedHandle<DownloadContext> dctx
(new DownloadContext(0, 0, "aria2.tar.bz2"));
SharedHandle<UnknownLengthPieceStorage> ps
(new UnknownLengthPieceStorage(dctx, &op));
SegmentMan segmentMan(&op, dctx, ps);
size_t minSplitSize = dctx->getPieceLength();
2006-09-23 11:58:23 +00:00
SharedHandle<Segment> segment = segmentMan.getSegment(1, minSplitSize);
CPPUNIT_ASSERT(segment);
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());
2006-09-23 11:58:23 +00:00
SharedHandle<Segment> segment2 = segmentMan.getSegment(2, minSplitSize);
CPPUNIT_ASSERT(!segment2);
2006-09-23 11:58:23 +00:00
2006-10-01 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com> To add timeout to async name resolution: * src/AbstractCommand.h (nameResolveFinished): New function. This is not elegant way. It needs to be more refined. (nameResolverCheck): New variable. * src/AbstractCommand.cc (AbstractCommand): Added nameResolverCheck. (execute): Added the check whether the name resolution has finished. (setNameResolverCheck): Set nameResolverCheck to true. (disableNameResolverCheck): Set nameResolverCheck to false. (nameResolverFinished): New function. * src/FtpInitiateConnectionCommand.h (nameResolverFinished): New function. * src/HttpInitiateConnectionCommand.h (nameResolverFinished): New function. To add the support for a non-compact response from a tracker: * src/PeerListProcessor.h: New class. * src/DefaultPeerListProcessor.h: New class. * src/DefaultPeerListProcessor.cc: New class. * src/CompactPeerListProcessor.h: New class. * src/CompactPeerListProcessor.cc: New class. * src/DelegatingPeerListProcessor.h: New class. * src/DelegatingPeerListProcessor.cc: New class. * src/TorrentMan.cc (addPeer): New function(overload). (addPeer): Delete unused peers only when new peer is added. * src/TorrentMan.h (PeerListProcessor.h): Included. (Peers): Removed. (addPeer): New function(overload). * src/TrackerUpdateCommand.cc (netinet/in.h): Removed. (DelegatingPeerListProcessor.h): Included. (execute): Updated to use DelegatingPeerListProcessor. To fix the memory leak in TorrentMan::peers: * src/PeerAbstractCommand.cc (onAbort): Added peer->resetStatus(). * src/Peer.h (resetStatus): Made public. To improve the precision of the speed calculation: * src/SpeedCalc.h (nextInterval): New variable. * src/SpeedCalc.cc (reset): Added nextInterval. (isIntervalOver): Use nextInterval instead of CHANGE_INTERVAL_SEC. (changeSw): Set nextInterval to 15 seconds relative to the current instant time. * src/main.cc (showVersion): Updated.
2006-10-01 11:29:14 +00:00
segmentMan.cancelSegment(1);
CPPUNIT_ASSERT(segmentMan.getSegment(2, minSplitSize));
}
void SegmentManTest::testCompleteSegment()
{
Option op;
size_t pieceLength = 1024*1024;
uint64_t totalLength = 64*1024*1024;
2009-06-28 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net> Rewritten DownloadContext and removed SingleFileDownloadContext and BtContext and its derived classes. BitTorrent specific attributes are now set by DownloadContext::setAttribute() with key bittorrent::BITTORRENT. * src/AbstractBtMessage.cc * src/AbstractBtMessage.h * src/AbstractCommand.cc * src/AbstractCommand.h * src/AbstractProxyRequestCommand.cc * src/AbstractProxyResponseCommand.cc * src/ActivePeerConnectionCommand.cc * src/ActivePeerConnectionCommand.h * src/AnnounceList.cc * src/BtCheckIntegrityEntry.cc * src/BtConstants.h * src/BtContext.h: Removed * src/BtDependency.cc * src/BtExtendedMessage.cc * src/BtPieceMessage.cc * src/BtPieceMessage.h * src/BtPostDownloadHandler.cc * src/BtRegistry.cc * src/BtRegistry.h * src/BtSetup.cc * src/CheckIntegrityCommand.cc * src/CheckIntegrityEntry.cc * src/ChecksumCheckIntegrityEntry.cc * src/ConsoleStatCalc.cc * src/ContentTypeRequestGroupCriteria.cc * src/DHTGetPeersCommand.cc * src/DHTGetPeersCommand.h * src/DHTPeerLookupTask.cc * src/DHTPeerLookupTask.h * src/DHTTaskFactory.h * src/DHTTaskFactoryImpl.cc * src/DHTTaskFactoryImpl.h * src/DefaultBtAnnounce.cc * src/DefaultBtAnnounce.h * src/DefaultBtContext.cc: Removed * src/DefaultBtContext.h: Removed * src/DefaultBtInteractive.cc * src/DefaultBtInteractive.h * src/DefaultBtMessageDispatcher.cc * src/DefaultBtMessageDispatcher.h * src/DefaultBtMessageFactory.cc * src/DefaultBtMessageFactory.h * src/DefaultBtMessageReceiver.cc * src/DefaultBtMessageReceiver.h * src/DefaultBtProgressInfoFile.cc * src/DefaultBtRequestFactory.cc * src/DefaultBtRequestFactory.h * src/DefaultExtensionMessageFactory.cc * src/DefaultExtensionMessageFactory.h * src/DefaultPeerStorage.cc * src/DefaultPeerStorage.h * src/DefaultPieceStorage.cc * src/DefaultSegmentManFactory.cc * src/DiskAdaptor.cc * src/DiskAdaptor.h * src/DownloadContext.cc * src/DownloadContext.h * src/DownloadEngine.cc * src/DownloadEngineFactory.cc * src/DownloadHandler.cc * src/DownloadResult.h * src/FileAllocationCommand.cc * src/FileAllocationDispatcherCommand.cc * src/FileAllocationEntry.cc * src/FileEntry.h * src/FillRequestGroupCommand.cc * src/FtpDownloadCommand.cc * src/FtpFinishDownloadCommand.cc * src/FtpInitiateConnectionCommand.cc * src/FtpNegotiationCommand.cc * src/FtpTunnelRequestCommand.cc * src/FtpTunnelResponseCommand.cc * src/HandshakeExtensionMessage.cc * src/HandshakeExtensionMessage.h * src/HaveEraseCommand.cc * src/HttpDownloadCommand.cc * src/HttpInitiateConnectionCommand.cc * src/HttpProxyRequestCommand.cc * src/HttpProxyResponseCommand.cc * src/HttpRequest.cc * src/HttpRequest.h * src/HttpRequestCommand.cc * src/HttpResponseCommand.cc * src/HttpServerBodyCommand.cc * src/HttpServerCommand.cc * src/HttpSkipResponseCommand.cc * src/InitiateConnectionCommandFactory.cc * src/InitiatorMSEHandshakeCommand.cc * src/InitiatorMSEHandshakeCommand.h * src/IteratableChecksumValidator.cc * src/IteratableChecksumValidator.h * src/IteratableChunkChecksumValidator.cc * src/MSEHandshake.cc * src/MSEHandshake.h * src/Makefile.am * src/Makefile.in * src/Metalink2RequestGroup.cc * src/MetalinkPostDownloadHandler.cc * src/MultiDiskAdaptor.cc * src/MultiDiskAdaptor.h * src/MultiFileAllocationIterator.cc * src/MultiUrlRequestInfo.cc * src/PeerChokeCommand.cc * src/PeerChokeCommand.h * src/PeerInitiateConnectionCommand.cc * src/PeerInitiateConnectionCommand.h * src/PeerInteractionCommand.cc * src/PeerInteractionCommand.h * src/PeerReceiveHandshakeCommand.cc * src/PieceHashCheckIntegrityEntry.cc * src/RealtimeCommand.cc * src/ReceiverMSEHandshakeCommand.cc * src/RequestGroup.cc * src/RequestGroup.h * src/RequestGroupEntry.cc * src/RequestGroupMan.cc * src/SeedCheckCommand.cc * src/SeedCheckCommand.h * src/SegmentMan.cc * src/ShareRatioSeedCriteria.h * src/SingleFileDownloadContext.cc: Removed * src/SingleFileDownloadContext.h: Removed * src/SleepCommand.cc * src/StreamCheckIntegrityEntry.cc * src/TrackerWatcherCommand.cc * src/TrackerWatcherCommand.h * src/UnknownLengthPieceStorage.cc * src/Util.cc * src/Util.h * src/XmlRpcMethodImpl.cc * src/bittorrent_helper.cc * src/bittorrent_helper.h * src/download_helper.cc * src/main.cc * src/option_processing.cc * test/BitfieldManTest.cc * test/BittorrentHelperTest.cc * test/BtCancelMessageTest.cc * test/BtChokeMessageTest.cc * test/BtDependencyTest.cc * test/BtPieceMessageTest.cc * test/BtPostDownloadHandlerTest.cc * test/BtRegistryTest.cc * test/BtRejectMessageTest.cc * test/BtRequestMessageTest.cc * test/DHTPeerAnnounceStorageTest.cc * test/DefaultBtAnnounceTest.cc * test/DefaultBtContextTest.cc: Removed * test/DefaultBtMessageDispatcherTest.cc * test/DefaultBtMessageFactoryTest.cc * test/DefaultBtProgressInfoFileTest.cc * test/DefaultBtRequestFactoryTest.cc * test/DefaultExtensionMessageFactoryTest.cc * test/DefaultPeerStorageTest.cc * test/DefaultPieceStorageTest.cc * test/DirectDiskAdaptorTest.cc * test/DownloadContextTest.cc * test/DownloadHandlerFactoryTest.cc * test/DownloadHelperTest.cc * test/HandshakeExtensionMessageTest.cc * test/HttpRequestTest.cc * test/HttpResponseTest.cc * test/IteratableChecksumValidatorTest.cc * test/IteratableChunkChecksumValidatorTest.cc * test/MSEHandshakeTest.cc * test/Makefile.am * test/Makefile.in * test/Metalink2RequestGroupTest.cc * test/MetalinkPostDownloadHandlerTest.cc * test/MockBtContext.h: Removed * test/MockDHTTaskFactory.h * test/MockDownloadContext.h: Removed * test/MockPieceStorage.h * test/MultiDiskAdaptorTest.cc * test/MultiFileAllocationIteratorTest.cc * test/RequestGroupManTest.cc * test/RequestGroupTest.cc * test/SegmentManTest.cc * test/ShareRatioSeedCriteriaTest.cc * test/SingleFileDownloadContextTest.cc: Removed * test/UtilTest.cc * test/XmlRpcMethodTest.cc
2009-06-28 10:37:15 +00:00
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.getSegmentWithIndex(1, 0));
SharedHandle<Segment> seg = segmentMan.getSegmentWithIndex(1, 1);
CPPUNIT_ASSERT(seg);
CPPUNIT_ASSERT(segmentMan.getSegmentWithIndex(1, 2));
seg->updateWrittenLength(pieceLength);
segmentMan.completeSegment(1, seg);
std::vector<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());
}
void SegmentManTest::testGetSegment_sameFileEntry()
{
Option op;
SharedHandle<DownloadContext> dctx(new DownloadContext());
dctx->setPieceLength(2);
SharedHandle<FileEntry> fileEntries[] = {
SharedHandle<FileEntry>(new FileEntry("file1", 3, 0)),
SharedHandle<FileEntry>(new FileEntry("file2", 6, 3)),
SharedHandle<FileEntry>(new FileEntry("file3", 1, 9))
};
dctx->setFileEntries(&fileEntries[0], &fileEntries[3]);
SharedHandle<DefaultPieceStorage> ps(new DefaultPieceStorage(dctx, &op));
SegmentMan segman(&op, dctx, ps);
size_t minSplitSize =dctx->getPieceLength();
std::vector<SharedHandle<Segment> > segments;
segman.getSegment(segments, 1, minSplitSize, fileEntries[1], 4);
// See 3 segments are returned, not 4 because the part of file1 is
// not filled in segment#1
CPPUNIT_ASSERT_EQUAL((size_t)3, segments.size());
SharedHandle<Segment> segmentNo1 = segman.getSegmentWithIndex(2, 1);
// Fill the part of file1 in segment#1
segmentNo1->updateWrittenLength(1);
segman.cancelSegment(2);
segman.cancelSegment(1);
segments.clear();
segman.getSegment(segments, 1, minSplitSize, fileEntries[1], 4);
CPPUNIT_ASSERT_EQUAL((size_t)4, segments.size());
segman.cancelSegment(1);
SharedHandle<Segment> segmentNo4 = segman.getSegmentWithIndex(1, 4);
// Fill the part of file2 in segment#4
segmentNo4->updateWrittenLength(1);
segman.cancelSegment(1);
segments.clear();
segman.getSegment(segments, 1, minSplitSize, fileEntries[1], 4);
// segment#4 is not returned because the part of file2 is filled.
CPPUNIT_ASSERT_EQUAL((size_t)3, segments.size());
}
void SegmentManTest::testRegisterPeerStat()
{
Option op;
SharedHandle<DownloadContext> dctx(new DownloadContext());
SharedHandle<DefaultPieceStorage> ps(new DefaultPieceStorage(dctx, &op));
SegmentMan segman(&op, dctx, ps);
SharedHandle<PeerStat> p1(new PeerStat(0, "host1", "http"));
segman.registerPeerStat(p1);
CPPUNIT_ASSERT_EQUAL((size_t)1, segman.getPeerStats().size());
SharedHandle<PeerStat> p2(new PeerStat(0, "host2", "http"));
segman.registerPeerStat(p2);
CPPUNIT_ASSERT_EQUAL((size_t)1, segman.getPeerStats().size());
p2->downloadStart();
segman.registerPeerStat(p1);
CPPUNIT_ASSERT_EQUAL((size_t)2, segman.getPeerStats().size());
}
void SegmentManTest::testCancelAllSegments()
{
segmentMan_->getSegmentWithIndex(1, 0);
segmentMan_->getSegmentWithIndex(2, 1);
CPPUNIT_ASSERT(!segmentMan_->getSegmentWithIndex(3, 0));
CPPUNIT_ASSERT(!segmentMan_->getSegmentWithIndex(4, 1));
segmentMan_->cancelAllSegments();
CPPUNIT_ASSERT(segmentMan_->getSegmentWithIndex(3, 0));
CPPUNIT_ASSERT(segmentMan_->getSegmentWithIndex(4, 1));
}
void SegmentManTest::testGetPeerStat()
{
SharedHandle<PeerStat> peerStat1(new PeerStat(1));
segmentMan_->registerPeerStat(peerStat1);
CPPUNIT_ASSERT_EQUAL((cuid_t)1, segmentMan_->getPeerStat(1)->getCuid());
}
void SegmentManTest::testGetCleanSegmentIfOwnerIsIdle()
{
SharedHandle<Segment> seg1 = segmentMan_->getSegmentWithIndex(1, 0);
SharedHandle<Segment> seg2 = segmentMan_->getSegmentWithIndex(2, 1);
seg2->updateWrittenLength(100);
CPPUNIT_ASSERT(segmentMan_->getCleanSegmentIfOwnerIsIdle(3, 0));
SharedHandle<PeerStat> peerStat3(new PeerStat(3));
segmentMan_->registerPeerStat(peerStat3);
CPPUNIT_ASSERT(segmentMan_->getCleanSegmentIfOwnerIsIdle(4, 0));
SharedHandle<PeerStat> peerStat4(new PeerStat(4));
peerStat4->downloadStart();
segmentMan_->registerPeerStat(peerStat4);
// Owner PeerStat is not IDLE
CPPUNIT_ASSERT(!segmentMan_->getCleanSegmentIfOwnerIsIdle(5, 0));
// Segment::updateWrittenLength != 0
CPPUNIT_ASSERT(!segmentMan_->getCleanSegmentIfOwnerIsIdle(5, 1));
}
} // namespace aria2