2006-12-24 06:25:21 +00:00
|
|
|
#include "DefaultBtMessageDispatcher.h"
|
2008-11-03 06:49:02 +00:00
|
|
|
|
|
|
|
#include <cassert>
|
|
|
|
|
|
|
|
#include <cppunit/extensions/HelperMacros.h>
|
|
|
|
|
2009-10-22 15:35:33 +00:00
|
|
|
#include "util.h"
|
2006-12-24 06:25:21 +00:00
|
|
|
#include "Exception.h"
|
|
|
|
#include "MockBtMessage.h"
|
|
|
|
#include "MockBtMessageFactory.h"
|
|
|
|
#include "prefs.h"
|
|
|
|
#include "BtCancelSendingPieceEvent.h"
|
2008-04-20 00:50:22 +00:00
|
|
|
#include "BtHandshakeMessage.h"
|
2009-02-28 11:48:26 +00:00
|
|
|
#include "Option.h"
|
|
|
|
#include "RequestGroupMan.h"
|
|
|
|
#include "ServerStatMan.h"
|
|
|
|
#include "RequestGroup.h"
|
2009-06-28 10:37:15 +00:00
|
|
|
#include "DownloadContext.h"
|
|
|
|
#include "bittorrent_helper.h"
|
2013-01-11 05:20:34 +00:00
|
|
|
#include "PeerConnection.h"
|
2006-12-24 06:25:21 +00:00
|
|
|
|
2008-02-08 15:53:45 +00:00
|
|
|
namespace aria2 {
|
2006-12-24 06:25:21 +00:00
|
|
|
|
|
|
|
class DefaultBtMessageDispatcherTest:public CppUnit::TestFixture {
|
|
|
|
|
|
|
|
CPPUNIT_TEST_SUITE(DefaultBtMessageDispatcherTest);
|
|
|
|
CPPUNIT_TEST(testAddMessage);
|
|
|
|
CPPUNIT_TEST(testSendMessages);
|
|
|
|
CPPUNIT_TEST(testSendMessages_underUploadLimit);
|
2009-02-28 11:48:26 +00:00
|
|
|
// See the comment on the definition
|
|
|
|
//CPPUNIT_TEST(testSendMessages_overUploadLimit);
|
2006-12-24 06:25:21 +00:00
|
|
|
CPPUNIT_TEST(testDoCancelSendingPieceAction);
|
|
|
|
CPPUNIT_TEST(testCheckRequestSlotAndDoNecessaryThing);
|
|
|
|
CPPUNIT_TEST(testCheckRequestSlotAndDoNecessaryThing_timeout);
|
|
|
|
CPPUNIT_TEST(testCheckRequestSlotAndDoNecessaryThing_completeBlock);
|
|
|
|
CPPUNIT_TEST(testCountOutstandingRequest);
|
|
|
|
CPPUNIT_TEST(testIsOutstandingRequest);
|
|
|
|
CPPUNIT_TEST(testGetOutstandingRequest);
|
|
|
|
CPPUNIT_TEST(testRemoveOutstandingRequest);
|
|
|
|
CPPUNIT_TEST_SUITE_END();
|
|
|
|
private:
|
2013-06-21 16:10:38 +00:00
|
|
|
std::shared_ptr<DownloadContext> dctx_;
|
|
|
|
std::shared_ptr<Peer> peer;
|
2013-06-30 07:55:15 +00:00
|
|
|
std::unique_ptr<DefaultBtMessageDispatcher> btMessageDispatcher;
|
|
|
|
std::unique_ptr<MockBtMessageFactory> messageFactory_;
|
|
|
|
std::unique_ptr<RequestGroupMan> rgman_;
|
2013-06-21 16:10:38 +00:00
|
|
|
std::shared_ptr<Option> option_;
|
2013-06-30 07:55:15 +00:00
|
|
|
std::unique_ptr<RequestGroup> rg_;
|
2006-12-24 06:25:21 +00:00
|
|
|
public:
|
2007-01-16 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
To decrease CPU usage in bittorrent download, calculation
results in
BitfieldMan were cached and realtime fetching PeerObject was
removed
with WeakHandle introduced. Option values are set to the objects
by setter before download begins.
* src/DefaultBtRequestFactory.cc: Use messageFactory member.
* src/DefaultBtRequestFactory.h
(dispatcher): BtMessageDispatcherHandle ->
BtMessageDispatcherWeakHandle.
(messageFactory): New variable.
(setBtMessageDispatcher): BtMessageDispatcherHandle ->
BtMessageDispatcherWeakHandle.
(setBtMessageFactory): New function.
* src/DefaultBtMessageDispatcher.cc:
(sendMessages): Use maxUploadSpeedLimit instead of fetching the
value
from Option.
(checkRequestSlotAndDoNecessaryThing): Use requestTimeout
instead of
feating the value from Option.
Use messageFactory member.
* src/PeerInteractionCommand.cc
(PeerInteractionCommand): Added maxDownloadSpeedLimit.
Add reverse dependencies to factory object.
Set maxUploadSpeedLimit and requestTimeout and messageFactory to
dispatcher.
Set messageFactory to receiver.
Set keepAliveInterval and maxDownloadSpeedLimit and
messageFactory to
btInteractive.
Set receiver to peerObject.
Set maxDownloadSpeedLimit to this.
(executeInternal): Use maxDownloadSpeedLimit member.
* src/BtChokeMessage.cc
(doReceivedAction): Use dispatcher, requestFactory member.
(onSendComplete): Use dispatcher member.
* src/PeerInteractionCommand.h
(maxDownloadSpeedLimit): New variable.
* src/DefaultBtMessageReceiver.h
(peerConnection): PeerConnectionHandle ->
PeerConnectionWeakHandle
(dispatcher):
BtMessageDispatcherHandle -> BtMessageDispatcherWeakHandle
(messageFactory): New variable.
(setPeerConnection): PeerConnectionHandle ->
PeerConnectionWeakHandle
(getPeerConnection): PeerConnectionHandle ->
PeerConnectionWeakHandle
(setDispatcher):
BtMessageDispatcherHandle -> BtMessageDispatcherWeakHandle
(setBtMessageFactory): New function.
* src/DefaultBtInteractive.cc
(initiateHandshake): Use messageFactory member.
(addBitfieldMessageToQueue): Use messageFactory member.
(addAllowedFastMessageToQueue): Use messageFactory member.
(decideChoking): Use messageFactory member.
(checkHave): Use messageFactory member.
(sendKeepAlive): Use keepAliveInterval, messageFactory member.
(receiveMessages): Use maxDownloadSpeedLimit member.
(decideInterest): Use messageFactory member.
* src/BtRequestMessage.cc
(doReceivedAction): Use messageFactory, dispatcher member.
(onQueued): Use dispatcher member.
* src/BtPieceMessage.cc
(doReceivedAction): Use dispatcher member.
(send): Use peerConnection member.
(onWrongPiece): Use requestFactory member.
(handleChokingEvent): Use messageFactory, dispatcher member.
(handleCancelSendingPieceEvent): Use messageFactory, dispatcher
member.
* src/BtMessageDispatcher.h
(BtMessageDispatcherWeakHandle): New type definition.
* src/SimpleBtMessage.cc
(send): Use peerConnection member.
* src/BtRejectMessage.cc
(doReceivedAction): Use dispatcher member.
* src/DefaultBtMessageDispatcher.h
(Option.h): Removed include.
(messageFactory): New variable.
(option): Removed.
(maxUploadSpeedLimit): New variable.
(requestTimeout): New variable.
(DefaultBtMessageDispatcher): Removed option.
Added maxUploadSpeedLimit, requestTimeout.
(setOption): Removed.
(getOption): Removed.
(setMaxUploadSpeedLimit): New function.
(setRequestTimeout): New function.
(setBtMessageFactory): New function.
* src/DefaultBtInteractive.h
(btMessageReceiver):
BtMessageReceiverHandle -> BtMessageReceiverWeakHandle
(dispatcher):
BtMessageDispatcherHandle -> BtMessageReceiverWeakHandle
(btRequestFactory):
BtRequestFactoryHandle -> BtRequestFactoryWeakHandle
(peerConnection):
PeerConnectionHandle -> PeerConnectionWeakHandle
(messageFactory): New variable.
(option): Removed.
(keepAliveInterval): New variable.
(maxDownloadSpeedLimit): New variable.
(DefaultBtInteractive): Added keepAliveInterval,
maxDownloadSpeedLimit.
(setBtMessageReceiver):
BtMessageReceiverHandle -> BtMessageReceiverWeakHandle
(setDispatcher):
BtMessageDispatcherHandle -> BtMessageReceiverWeakHandle
(setBtRequestFactory):
BtRequestFactoryHandle -> BtRequestFactoryWeakHandle
(setPeerConnection):
PeerConnectionHandle -> PeerConnectionWeakHandle
(setOption): Removed.
(setKeepAliveInterval): New function.
(setMaxDownloadSpeedLimit): New function.
(setBtMessageFactory): New function.
* src/BitfieldMan.h
(cachedNumMissingBlock): New variable.
(cachedNumFilteredBlock): New variable.
(cachedCompletedLength): New variable.
(cachedFilteredComletedLength): New variable.
(cachedFilteredTotalLength): New variable.
(countMissingBlockNow): New function.
(countFilteredBlockNow): New function.
(getFilteredTotalLengthNow): New function.
(getCompletedLengthNow): New function.
(getFilteredCompletedLengthNow): New function.
(updateCache): New function.
* src/AbstractBtMessage.h
(BtMessageDispatcher.h): New include.
(PeerConnection.h): New include.
(BtRequestFactory.h): New include
(BtMessageFactory.h): New include.
(dispatcher): New variable.
(messageFactory): New variable.
(peerConnection: New variable.
(setBtMessageDispatcher): New function.
(setPeerConnection): New function.
(setBtMessageFactory): New function.
(setBtRequestFactory): New function.
* src/DefaultBtMessageFactory.cc
(setCommonProperty): Set dispatcher, requestFactory, this,
peerConnection to msg.
* src/BtRegistry.h
(BT_MESSAGE_RECEIVER): New macro.
* src/PeerConnection.h
(PeerConnectionWeakHandle): New type definition.
* src/BtMessageFactory.h
(BtMessageFactoryWeakHandle): New type definition.
* src/BitfieldMan.cc
(BitfieldMan): Added cachedNumMissingBlock,
cachedNumFilteredBlock,
cachedCompletedLength, cachedFilteredComletedLength,
cachedFilteredTotalLength.
Call updateCache().
(countMissingBlock): Return cachedNumMissingBlock.
(countMissingBlockNow): New function.
(countBlock): Return cachedNumFilteredBlock if filterEnabled is
true.
(countFilteredBlockNow): New function.
(setBit): Call updateCache().
(unsetBit): Call updateCache().
(setBitfield): Call updateCache().
(clearAllBit): Call updateCache().
(setAllBit): Use setBitInternal instead of setBit.
Call updateCache().
(addFilter): Call updateCache().
(enableFilter): Call updateCache().
(disableFilter): Call updateCache().
(clearFilter): Call updateCache().
(getFilteredTotalLength): Return cachedFilteredTotalLength.
(getFilteredTotalLengthNow): New function.
(getCompletedLength): Return cachedCompletedLength.
(getCompletedLengthNow): New function.
(getFilteredCompletedLength): Return
cachedFilteredComletedLength.
(getFilteredCompletedLengthNow): New function.
(updateCache): New function.
* src/BtMessageReceiver.h
(BtMessageReceiverWeakHandle): New type definition.
* src/DefaultBtMessageReceiver.cc
(receiveHandshake): Use messageFactory member.
(sendHandshake): Use messageFactory member.
(receiveMessage): Use messageFactory member.
* src/DefaultBtMessageFactory.h
(dispatcher): New variable.
(requestFactory): New variable.
(peerConnection): New variablle.
(setBtMessageDispatcher): New function.
(setBtRequestFactory): New function.
(setPeerConnection): New function.
* src/SharedHandle.h
(RefCount): New class.
(WeakHandle): New class.
* src/PeerObject.h
(BtMessageReceiver.h): New include.
(PeerObject): Added btMessageReceiver.
(btMessageReceiver): New variable.
* src/Util.cc
(countBit): Simplified.
* src/BtCancelMessage.cc
(doReceivedAction): Use dispatcher member.
* src/BtRequestFactory.h
(BtRequestFactoryWeakHandle): New type definition.
* src/PeerStorage.h
(downloadSpeed): int -> uint32_t
(uploadSpeed): int -> uint32_t
(sessionDownloadLength): long long int -> uint64_t
(sessionUploadLength): long long int -> uint64_t
2007-01-16 15:20:26 +00:00
|
|
|
void tearDown() {}
|
2006-12-24 06:25:21 +00:00
|
|
|
|
|
|
|
void testAddMessage();
|
|
|
|
void testSendMessages();
|
|
|
|
void testSendMessages_underUploadLimit();
|
|
|
|
void testSendMessages_overUploadLimit();
|
|
|
|
void testDoCancelSendingPieceAction();
|
|
|
|
void testCheckRequestSlotAndDoNecessaryThing();
|
|
|
|
void testCheckRequestSlotAndDoNecessaryThing_timeout();
|
|
|
|
void testCheckRequestSlotAndDoNecessaryThing_completeBlock();
|
|
|
|
void testCountOutstandingRequest();
|
|
|
|
void testIsOutstandingRequest();
|
|
|
|
void testGetOutstandingRequest();
|
|
|
|
void testRemoveOutstandingRequest();
|
|
|
|
|
2013-06-30 07:55:15 +00:00
|
|
|
struct EventCheck {
|
|
|
|
EventCheck() : onQueuedCalled{false}, sendCalled{false},
|
|
|
|
doCancelActionCalled{false}
|
|
|
|
{}
|
2006-12-24 06:25:21 +00:00
|
|
|
bool onQueuedCalled;
|
|
|
|
bool sendCalled;
|
|
|
|
bool doCancelActionCalled;
|
2013-06-30 07:55:15 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class MockBtMessage2 : public MockBtMessage {
|
2006-12-24 06:25:21 +00:00
|
|
|
public:
|
2013-06-30 07:55:15 +00:00
|
|
|
EventCheck* evcheck;
|
2008-02-08 15:53:45 +00:00
|
|
|
std::string type;
|
2013-06-30 07:55:15 +00:00
|
|
|
MockBtMessage2(EventCheck* evcheck = nullptr)
|
|
|
|
: evcheck{evcheck}
|
2006-12-24 06:25:21 +00:00
|
|
|
{}
|
|
|
|
|
2013-07-06 06:54:03 +00:00
|
|
|
virtual void onQueued() CXX11_OVERRIDE
|
2013-06-30 07:55:15 +00:00
|
|
|
{
|
|
|
|
if(evcheck){
|
|
|
|
evcheck->onQueuedCalled = true;
|
|
|
|
}
|
2006-12-24 06:25:21 +00:00
|
|
|
}
|
|
|
|
|
2013-07-06 06:54:03 +00:00
|
|
|
virtual void send() CXX11_OVERRIDE
|
2013-06-30 07:55:15 +00:00
|
|
|
{
|
|
|
|
if(evcheck) {
|
|
|
|
evcheck->sendCalled = true;
|
|
|
|
}
|
2006-12-24 06:25:21 +00:00
|
|
|
}
|
|
|
|
|
2009-04-21 14:52:04 +00:00
|
|
|
virtual void onCancelSendingPieceEvent
|
2013-07-06 06:54:03 +00:00
|
|
|
(const BtCancelSendingPieceEvent& event) CXX11_OVERRIDE
|
2009-04-21 14:52:04 +00:00
|
|
|
{
|
2013-06-30 07:55:15 +00:00
|
|
|
if(evcheck) {
|
|
|
|
evcheck->doCancelActionCalled = true;
|
|
|
|
}
|
2012-10-01 14:52:22 +00:00
|
|
|
}
|
2006-12-24 06:25:21 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class MockBtMessageFactory2 : public MockBtMessageFactory {
|
|
|
|
public:
|
2013-06-30 07:55:15 +00:00
|
|
|
virtual std::unique_ptr<BtCancelMessage>
|
2013-07-06 06:54:03 +00:00
|
|
|
createCancelMessage(size_t index, int32_t begin, int32_t length)
|
|
|
|
CXX11_OVERRIDE
|
2013-06-30 07:55:15 +00:00
|
|
|
{
|
|
|
|
return make_unique<BtCancelMessage>(index, begin, length);
|
2006-12-24 06:25:21 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-06-30 07:55:15 +00:00
|
|
|
void setUp()
|
|
|
|
{
|
|
|
|
option_ = std::make_shared<Option>();
|
2010-12-03 04:08:22 +00:00
|
|
|
option_->put(PREF_DIR, ".");
|
2009-02-28 11:48:26 +00:00
|
|
|
|
2013-06-30 07:55:15 +00:00
|
|
|
rg_ = make_unique<RequestGroup>(GroupId::create(), option_);
|
2009-02-28 11:48:26 +00:00
|
|
|
|
2013-06-30 07:55:15 +00:00
|
|
|
dctx_ = std::make_shared<DownloadContext>();
|
2010-12-03 04:08:22 +00:00
|
|
|
bittorrent::load(A2_TEST_DIR"/test.torrent", dctx_, option_);
|
2009-11-28 10:12:04 +00:00
|
|
|
|
2010-06-21 13:51:56 +00:00
|
|
|
rg_->setDownloadContext(dctx_);
|
2009-02-28 11:48:26 +00:00
|
|
|
|
2013-06-30 07:55:15 +00:00
|
|
|
peer = std::make_shared<Peer>("192.168.0.1", 6969);
|
2009-06-28 10:37:15 +00:00
|
|
|
peer->allocateSessionResource
|
2010-06-21 13:51:56 +00:00
|
|
|
(dctx_->getPieceLength(), dctx_->getTotalLength());
|
2013-06-30 07:55:15 +00:00
|
|
|
messageFactory_ = make_unique<MockBtMessageFactory2>();
|
2006-12-24 06:25:21 +00:00
|
|
|
|
2013-06-30 07:55:15 +00:00
|
|
|
rgman_ = make_unique<RequestGroupMan>
|
|
|
|
(std::vector<std::shared_ptr<RequestGroup>>{}, 0, option_.get());
|
2009-02-28 11:48:26 +00:00
|
|
|
|
2013-06-30 07:55:15 +00:00
|
|
|
btMessageDispatcher = make_unique<DefaultBtMessageDispatcher>();
|
2006-12-24 06:25:21 +00:00
|
|
|
btMessageDispatcher->setPeer(peer);
|
2013-06-23 03:25:58 +00:00
|
|
|
btMessageDispatcher->setDownloadContext(dctx_.get());
|
2010-11-12 12:48:48 +00:00
|
|
|
btMessageDispatcher->setBtMessageFactory(messageFactory_.get());
|
2008-11-03 06:49:02 +00:00
|
|
|
btMessageDispatcher->setCuid(1);
|
2010-11-12 12:48:48 +00:00
|
|
|
btMessageDispatcher->setRequestGroupMan(rgman_.get());
|
2006-12-24 06:25:21 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
CPPUNIT_TEST_SUITE_REGISTRATION(DefaultBtMessageDispatcherTest);
|
|
|
|
|
2013-06-30 07:55:15 +00:00
|
|
|
void DefaultBtMessageDispatcherTest::testAddMessage()
|
|
|
|
{
|
|
|
|
auto evcheck = EventCheck{};
|
|
|
|
auto msg = make_unique<MockBtMessage2>(&evcheck);
|
|
|
|
btMessageDispatcher->addMessageToQueue(std::move(msg));
|
|
|
|
CPPUNIT_ASSERT_EQUAL(true, evcheck.onQueuedCalled);
|
2006-12-24 06:25:21 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)1,
|
2010-01-05 16:01:46 +00:00
|
|
|
btMessageDispatcher->getMessageQueue().size());
|
2006-12-24 06:25:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void DefaultBtMessageDispatcherTest::testSendMessages() {
|
2013-06-30 07:55:15 +00:00
|
|
|
auto evcheck1 = EventCheck{};
|
|
|
|
auto msg1 = make_unique<MockBtMessage2>(&evcheck1);
|
2006-12-24 06:25:21 +00:00
|
|
|
msg1->setUploading(false);
|
2013-06-30 07:55:15 +00:00
|
|
|
auto evcheck2 = EventCheck{};
|
|
|
|
auto msg2 = make_unique<MockBtMessage2>(&evcheck2);
|
2006-12-24 06:25:21 +00:00
|
|
|
msg2->setUploading(false);
|
2013-06-30 07:55:15 +00:00
|
|
|
btMessageDispatcher->addMessageToQueue(std::move(msg1));
|
|
|
|
btMessageDispatcher->addMessageToQueue(std::move(msg2));
|
2013-01-11 05:20:34 +00:00
|
|
|
btMessageDispatcher->sendMessagesInternal();
|
2006-12-24 06:25:21 +00:00
|
|
|
|
2013-06-30 07:55:15 +00:00
|
|
|
CPPUNIT_ASSERT(evcheck1.sendCalled);
|
|
|
|
CPPUNIT_ASSERT(evcheck2.sendCalled);
|
2006-12-24 06:25:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void DefaultBtMessageDispatcherTest::testSendMessages_underUploadLimit() {
|
2013-06-30 07:55:15 +00:00
|
|
|
auto evcheck1 = EventCheck{};
|
|
|
|
auto msg1 = make_unique<MockBtMessage2>(&evcheck1);
|
2006-12-24 06:25:21 +00:00
|
|
|
msg1->setUploading(true);
|
2013-06-30 07:55:15 +00:00
|
|
|
auto evcheck2 = EventCheck{};
|
|
|
|
auto msg2 = make_unique<MockBtMessage2>(&evcheck2);
|
2006-12-24 06:25:21 +00:00
|
|
|
msg2->setUploading(true);
|
2013-06-30 07:55:15 +00:00
|
|
|
btMessageDispatcher->addMessageToQueue(std::move(msg1));
|
|
|
|
btMessageDispatcher->addMessageToQueue(std::move(msg2));
|
2013-01-11 05:20:34 +00:00
|
|
|
btMessageDispatcher->sendMessagesInternal();
|
2006-12-24 06:25:21 +00:00
|
|
|
|
2013-06-30 07:55:15 +00:00
|
|
|
CPPUNIT_ASSERT(evcheck1.sendCalled);
|
|
|
|
CPPUNIT_ASSERT(evcheck2.sendCalled);
|
2006-12-24 06:25:21 +00:00
|
|
|
}
|
|
|
|
|
2013-06-30 07:55:15 +00:00
|
|
|
void DefaultBtMessageDispatcherTest::testDoCancelSendingPieceAction()
|
|
|
|
{
|
|
|
|
auto evcheck1 = EventCheck{};
|
|
|
|
auto msg1 = make_unique<MockBtMessage2>(&evcheck1);
|
|
|
|
auto evcheck2 = EventCheck{};
|
|
|
|
auto msg2 = make_unique<MockBtMessage2>(&evcheck2);
|
|
|
|
|
|
|
|
btMessageDispatcher->addMessageToQueue(std::move(msg1));
|
|
|
|
btMessageDispatcher->addMessageToQueue(std::move(msg2));
|
2006-12-24 06:25:21 +00:00
|
|
|
|
|
|
|
btMessageDispatcher->doCancelSendingPieceAction(0, 0, 0);
|
|
|
|
|
2013-06-30 07:55:15 +00:00
|
|
|
CPPUNIT_ASSERT(evcheck1.doCancelActionCalled);
|
|
|
|
CPPUNIT_ASSERT(evcheck2.doCancelActionCalled);
|
2006-12-24 06:25:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int MY_PIECE_LENGTH = 16*1024;
|
|
|
|
|
2013-06-30 07:55:15 +00:00
|
|
|
void DefaultBtMessageDispatcherTest::testCheckRequestSlotAndDoNecessaryThing()
|
|
|
|
{
|
2013-06-29 15:31:50 +00:00
|
|
|
auto piece = std::make_shared<Piece>(0, MY_PIECE_LENGTH);
|
2008-03-08 08:04:28 +00:00
|
|
|
size_t index;
|
|
|
|
CPPUNIT_ASSERT(piece->getMissingUnusedBlockIndex(index));
|
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)0, index);
|
2006-12-24 06:25:21 +00:00
|
|
|
|
2008-11-03 06:49:02 +00:00
|
|
|
btMessageDispatcher->setRequestTimeout(60);
|
2013-06-29 15:31:50 +00:00
|
|
|
btMessageDispatcher->addOutstandingRequest
|
|
|
|
(make_unique<RequestSlot>(0, 0, MY_PIECE_LENGTH, 0, piece));
|
2006-12-24 06:25:21 +00:00
|
|
|
|
|
|
|
btMessageDispatcher->checkRequestSlotAndDoNecessaryThing();
|
|
|
|
|
2008-11-03 06:49:02 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)0,
|
2010-01-05 16:01:46 +00:00
|
|
|
btMessageDispatcher->getMessageQueue().size());
|
2008-11-03 06:49:02 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)1,
|
2010-01-05 16:01:46 +00:00
|
|
|
btMessageDispatcher->getRequestSlots().size());
|
2006-12-24 06:25:21 +00:00
|
|
|
}
|
|
|
|
|
2013-06-29 15:31:50 +00:00
|
|
|
void DefaultBtMessageDispatcherTest::
|
|
|
|
testCheckRequestSlotAndDoNecessaryThing_timeout() {
|
|
|
|
auto piece = std::make_shared<Piece>(0, MY_PIECE_LENGTH);
|
2008-03-08 08:04:28 +00:00
|
|
|
size_t index;
|
|
|
|
CPPUNIT_ASSERT(piece->getMissingUnusedBlockIndex(index));
|
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)0, index);
|
2006-12-24 06:25:21 +00:00
|
|
|
|
2007-01-16 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
To decrease CPU usage in bittorrent download, calculation
results in
BitfieldMan were cached and realtime fetching PeerObject was
removed
with WeakHandle introduced. Option values are set to the objects
by setter before download begins.
* src/DefaultBtRequestFactory.cc: Use messageFactory member.
* src/DefaultBtRequestFactory.h
(dispatcher): BtMessageDispatcherHandle ->
BtMessageDispatcherWeakHandle.
(messageFactory): New variable.
(setBtMessageDispatcher): BtMessageDispatcherHandle ->
BtMessageDispatcherWeakHandle.
(setBtMessageFactory): New function.
* src/DefaultBtMessageDispatcher.cc:
(sendMessages): Use maxUploadSpeedLimit instead of fetching the
value
from Option.
(checkRequestSlotAndDoNecessaryThing): Use requestTimeout
instead of
feating the value from Option.
Use messageFactory member.
* src/PeerInteractionCommand.cc
(PeerInteractionCommand): Added maxDownloadSpeedLimit.
Add reverse dependencies to factory object.
Set maxUploadSpeedLimit and requestTimeout and messageFactory to
dispatcher.
Set messageFactory to receiver.
Set keepAliveInterval and maxDownloadSpeedLimit and
messageFactory to
btInteractive.
Set receiver to peerObject.
Set maxDownloadSpeedLimit to this.
(executeInternal): Use maxDownloadSpeedLimit member.
* src/BtChokeMessage.cc
(doReceivedAction): Use dispatcher, requestFactory member.
(onSendComplete): Use dispatcher member.
* src/PeerInteractionCommand.h
(maxDownloadSpeedLimit): New variable.
* src/DefaultBtMessageReceiver.h
(peerConnection): PeerConnectionHandle ->
PeerConnectionWeakHandle
(dispatcher):
BtMessageDispatcherHandle -> BtMessageDispatcherWeakHandle
(messageFactory): New variable.
(setPeerConnection): PeerConnectionHandle ->
PeerConnectionWeakHandle
(getPeerConnection): PeerConnectionHandle ->
PeerConnectionWeakHandle
(setDispatcher):
BtMessageDispatcherHandle -> BtMessageDispatcherWeakHandle
(setBtMessageFactory): New function.
* src/DefaultBtInteractive.cc
(initiateHandshake): Use messageFactory member.
(addBitfieldMessageToQueue): Use messageFactory member.
(addAllowedFastMessageToQueue): Use messageFactory member.
(decideChoking): Use messageFactory member.
(checkHave): Use messageFactory member.
(sendKeepAlive): Use keepAliveInterval, messageFactory member.
(receiveMessages): Use maxDownloadSpeedLimit member.
(decideInterest): Use messageFactory member.
* src/BtRequestMessage.cc
(doReceivedAction): Use messageFactory, dispatcher member.
(onQueued): Use dispatcher member.
* src/BtPieceMessage.cc
(doReceivedAction): Use dispatcher member.
(send): Use peerConnection member.
(onWrongPiece): Use requestFactory member.
(handleChokingEvent): Use messageFactory, dispatcher member.
(handleCancelSendingPieceEvent): Use messageFactory, dispatcher
member.
* src/BtMessageDispatcher.h
(BtMessageDispatcherWeakHandle): New type definition.
* src/SimpleBtMessage.cc
(send): Use peerConnection member.
* src/BtRejectMessage.cc
(doReceivedAction): Use dispatcher member.
* src/DefaultBtMessageDispatcher.h
(Option.h): Removed include.
(messageFactory): New variable.
(option): Removed.
(maxUploadSpeedLimit): New variable.
(requestTimeout): New variable.
(DefaultBtMessageDispatcher): Removed option.
Added maxUploadSpeedLimit, requestTimeout.
(setOption): Removed.
(getOption): Removed.
(setMaxUploadSpeedLimit): New function.
(setRequestTimeout): New function.
(setBtMessageFactory): New function.
* src/DefaultBtInteractive.h
(btMessageReceiver):
BtMessageReceiverHandle -> BtMessageReceiverWeakHandle
(dispatcher):
BtMessageDispatcherHandle -> BtMessageReceiverWeakHandle
(btRequestFactory):
BtRequestFactoryHandle -> BtRequestFactoryWeakHandle
(peerConnection):
PeerConnectionHandle -> PeerConnectionWeakHandle
(messageFactory): New variable.
(option): Removed.
(keepAliveInterval): New variable.
(maxDownloadSpeedLimit): New variable.
(DefaultBtInteractive): Added keepAliveInterval,
maxDownloadSpeedLimit.
(setBtMessageReceiver):
BtMessageReceiverHandle -> BtMessageReceiverWeakHandle
(setDispatcher):
BtMessageDispatcherHandle -> BtMessageReceiverWeakHandle
(setBtRequestFactory):
BtRequestFactoryHandle -> BtRequestFactoryWeakHandle
(setPeerConnection):
PeerConnectionHandle -> PeerConnectionWeakHandle
(setOption): Removed.
(setKeepAliveInterval): New function.
(setMaxDownloadSpeedLimit): New function.
(setBtMessageFactory): New function.
* src/BitfieldMan.h
(cachedNumMissingBlock): New variable.
(cachedNumFilteredBlock): New variable.
(cachedCompletedLength): New variable.
(cachedFilteredComletedLength): New variable.
(cachedFilteredTotalLength): New variable.
(countMissingBlockNow): New function.
(countFilteredBlockNow): New function.
(getFilteredTotalLengthNow): New function.
(getCompletedLengthNow): New function.
(getFilteredCompletedLengthNow): New function.
(updateCache): New function.
* src/AbstractBtMessage.h
(BtMessageDispatcher.h): New include.
(PeerConnection.h): New include.
(BtRequestFactory.h): New include
(BtMessageFactory.h): New include.
(dispatcher): New variable.
(messageFactory): New variable.
(peerConnection: New variable.
(setBtMessageDispatcher): New function.
(setPeerConnection): New function.
(setBtMessageFactory): New function.
(setBtRequestFactory): New function.
* src/DefaultBtMessageFactory.cc
(setCommonProperty): Set dispatcher, requestFactory, this,
peerConnection to msg.
* src/BtRegistry.h
(BT_MESSAGE_RECEIVER): New macro.
* src/PeerConnection.h
(PeerConnectionWeakHandle): New type definition.
* src/BtMessageFactory.h
(BtMessageFactoryWeakHandle): New type definition.
* src/BitfieldMan.cc
(BitfieldMan): Added cachedNumMissingBlock,
cachedNumFilteredBlock,
cachedCompletedLength, cachedFilteredComletedLength,
cachedFilteredTotalLength.
Call updateCache().
(countMissingBlock): Return cachedNumMissingBlock.
(countMissingBlockNow): New function.
(countBlock): Return cachedNumFilteredBlock if filterEnabled is
true.
(countFilteredBlockNow): New function.
(setBit): Call updateCache().
(unsetBit): Call updateCache().
(setBitfield): Call updateCache().
(clearAllBit): Call updateCache().
(setAllBit): Use setBitInternal instead of setBit.
Call updateCache().
(addFilter): Call updateCache().
(enableFilter): Call updateCache().
(disableFilter): Call updateCache().
(clearFilter): Call updateCache().
(getFilteredTotalLength): Return cachedFilteredTotalLength.
(getFilteredTotalLengthNow): New function.
(getCompletedLength): Return cachedCompletedLength.
(getCompletedLengthNow): New function.
(getFilteredCompletedLength): Return
cachedFilteredComletedLength.
(getFilteredCompletedLengthNow): New function.
(updateCache): New function.
* src/BtMessageReceiver.h
(BtMessageReceiverWeakHandle): New type definition.
* src/DefaultBtMessageReceiver.cc
(receiveHandshake): Use messageFactory member.
(sendHandshake): Use messageFactory member.
(receiveMessage): Use messageFactory member.
* src/DefaultBtMessageFactory.h
(dispatcher): New variable.
(requestFactory): New variable.
(peerConnection): New variablle.
(setBtMessageDispatcher): New function.
(setBtRequestFactory): New function.
(setPeerConnection): New function.
* src/SharedHandle.h
(RefCount): New class.
(WeakHandle): New class.
* src/PeerObject.h
(BtMessageReceiver.h): New include.
(PeerObject): Added btMessageReceiver.
(btMessageReceiver): New variable.
* src/Util.cc
(countBit): Simplified.
* src/BtCancelMessage.cc
(doReceivedAction): Use dispatcher member.
* src/BtRequestFactory.h
(BtRequestFactoryWeakHandle): New type definition.
* src/PeerStorage.h
(downloadSpeed): int -> uint32_t
(uploadSpeed): int -> uint32_t
(sessionDownloadLength): long long int -> uint64_t
(sessionUploadLength): long long int -> uint64_t
2007-01-16 15:20:26 +00:00
|
|
|
btMessageDispatcher->setRequestTimeout(60);
|
2013-06-29 15:31:50 +00:00
|
|
|
auto slot = make_unique<RequestSlot>(0, 0, MY_PIECE_LENGTH, 0, piece);
|
|
|
|
// make this slot timeout
|
|
|
|
slot->setDispatchedTime(0);
|
|
|
|
btMessageDispatcher->addOutstandingRequest(std::move(slot));
|
2006-12-24 06:25:21 +00:00
|
|
|
btMessageDispatcher->checkRequestSlotAndDoNecessaryThing();
|
|
|
|
|
2008-11-03 06:49:02 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)0,
|
2010-01-05 16:01:46 +00:00
|
|
|
btMessageDispatcher->getMessageQueue().size());
|
2008-11-03 06:49:02 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)0,
|
2010-01-05 16:01:46 +00:00
|
|
|
btMessageDispatcher->getRequestSlots().size());
|
2006-12-24 06:25:21 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL(false, piece->isBlockUsed(0));
|
2008-02-09 17:14:40 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL(true, peer->snubbing());
|
2006-12-24 06:25:21 +00:00
|
|
|
}
|
|
|
|
|
2013-06-29 15:31:50 +00:00
|
|
|
void DefaultBtMessageDispatcherTest::
|
|
|
|
testCheckRequestSlotAndDoNecessaryThing_completeBlock() {
|
|
|
|
auto piece = std::make_shared<Piece>(0, MY_PIECE_LENGTH);
|
2006-12-24 06:25:21 +00:00
|
|
|
piece->completeBlock(0);
|
2007-01-16 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
To decrease CPU usage in bittorrent download, calculation
results in
BitfieldMan were cached and realtime fetching PeerObject was
removed
with WeakHandle introduced. Option values are set to the objects
by setter before download begins.
* src/DefaultBtRequestFactory.cc: Use messageFactory member.
* src/DefaultBtRequestFactory.h
(dispatcher): BtMessageDispatcherHandle ->
BtMessageDispatcherWeakHandle.
(messageFactory): New variable.
(setBtMessageDispatcher): BtMessageDispatcherHandle ->
BtMessageDispatcherWeakHandle.
(setBtMessageFactory): New function.
* src/DefaultBtMessageDispatcher.cc:
(sendMessages): Use maxUploadSpeedLimit instead of fetching the
value
from Option.
(checkRequestSlotAndDoNecessaryThing): Use requestTimeout
instead of
feating the value from Option.
Use messageFactory member.
* src/PeerInteractionCommand.cc
(PeerInteractionCommand): Added maxDownloadSpeedLimit.
Add reverse dependencies to factory object.
Set maxUploadSpeedLimit and requestTimeout and messageFactory to
dispatcher.
Set messageFactory to receiver.
Set keepAliveInterval and maxDownloadSpeedLimit and
messageFactory to
btInteractive.
Set receiver to peerObject.
Set maxDownloadSpeedLimit to this.
(executeInternal): Use maxDownloadSpeedLimit member.
* src/BtChokeMessage.cc
(doReceivedAction): Use dispatcher, requestFactory member.
(onSendComplete): Use dispatcher member.
* src/PeerInteractionCommand.h
(maxDownloadSpeedLimit): New variable.
* src/DefaultBtMessageReceiver.h
(peerConnection): PeerConnectionHandle ->
PeerConnectionWeakHandle
(dispatcher):
BtMessageDispatcherHandle -> BtMessageDispatcherWeakHandle
(messageFactory): New variable.
(setPeerConnection): PeerConnectionHandle ->
PeerConnectionWeakHandle
(getPeerConnection): PeerConnectionHandle ->
PeerConnectionWeakHandle
(setDispatcher):
BtMessageDispatcherHandle -> BtMessageDispatcherWeakHandle
(setBtMessageFactory): New function.
* src/DefaultBtInteractive.cc
(initiateHandshake): Use messageFactory member.
(addBitfieldMessageToQueue): Use messageFactory member.
(addAllowedFastMessageToQueue): Use messageFactory member.
(decideChoking): Use messageFactory member.
(checkHave): Use messageFactory member.
(sendKeepAlive): Use keepAliveInterval, messageFactory member.
(receiveMessages): Use maxDownloadSpeedLimit member.
(decideInterest): Use messageFactory member.
* src/BtRequestMessage.cc
(doReceivedAction): Use messageFactory, dispatcher member.
(onQueued): Use dispatcher member.
* src/BtPieceMessage.cc
(doReceivedAction): Use dispatcher member.
(send): Use peerConnection member.
(onWrongPiece): Use requestFactory member.
(handleChokingEvent): Use messageFactory, dispatcher member.
(handleCancelSendingPieceEvent): Use messageFactory, dispatcher
member.
* src/BtMessageDispatcher.h
(BtMessageDispatcherWeakHandle): New type definition.
* src/SimpleBtMessage.cc
(send): Use peerConnection member.
* src/BtRejectMessage.cc
(doReceivedAction): Use dispatcher member.
* src/DefaultBtMessageDispatcher.h
(Option.h): Removed include.
(messageFactory): New variable.
(option): Removed.
(maxUploadSpeedLimit): New variable.
(requestTimeout): New variable.
(DefaultBtMessageDispatcher): Removed option.
Added maxUploadSpeedLimit, requestTimeout.
(setOption): Removed.
(getOption): Removed.
(setMaxUploadSpeedLimit): New function.
(setRequestTimeout): New function.
(setBtMessageFactory): New function.
* src/DefaultBtInteractive.h
(btMessageReceiver):
BtMessageReceiverHandle -> BtMessageReceiverWeakHandle
(dispatcher):
BtMessageDispatcherHandle -> BtMessageReceiverWeakHandle
(btRequestFactory):
BtRequestFactoryHandle -> BtRequestFactoryWeakHandle
(peerConnection):
PeerConnectionHandle -> PeerConnectionWeakHandle
(messageFactory): New variable.
(option): Removed.
(keepAliveInterval): New variable.
(maxDownloadSpeedLimit): New variable.
(DefaultBtInteractive): Added keepAliveInterval,
maxDownloadSpeedLimit.
(setBtMessageReceiver):
BtMessageReceiverHandle -> BtMessageReceiverWeakHandle
(setDispatcher):
BtMessageDispatcherHandle -> BtMessageReceiverWeakHandle
(setBtRequestFactory):
BtRequestFactoryHandle -> BtRequestFactoryWeakHandle
(setPeerConnection):
PeerConnectionHandle -> PeerConnectionWeakHandle
(setOption): Removed.
(setKeepAliveInterval): New function.
(setMaxDownloadSpeedLimit): New function.
(setBtMessageFactory): New function.
* src/BitfieldMan.h
(cachedNumMissingBlock): New variable.
(cachedNumFilteredBlock): New variable.
(cachedCompletedLength): New variable.
(cachedFilteredComletedLength): New variable.
(cachedFilteredTotalLength): New variable.
(countMissingBlockNow): New function.
(countFilteredBlockNow): New function.
(getFilteredTotalLengthNow): New function.
(getCompletedLengthNow): New function.
(getFilteredCompletedLengthNow): New function.
(updateCache): New function.
* src/AbstractBtMessage.h
(BtMessageDispatcher.h): New include.
(PeerConnection.h): New include.
(BtRequestFactory.h): New include
(BtMessageFactory.h): New include.
(dispatcher): New variable.
(messageFactory): New variable.
(peerConnection: New variable.
(setBtMessageDispatcher): New function.
(setPeerConnection): New function.
(setBtMessageFactory): New function.
(setBtRequestFactory): New function.
* src/DefaultBtMessageFactory.cc
(setCommonProperty): Set dispatcher, requestFactory, this,
peerConnection to msg.
* src/BtRegistry.h
(BT_MESSAGE_RECEIVER): New macro.
* src/PeerConnection.h
(PeerConnectionWeakHandle): New type definition.
* src/BtMessageFactory.h
(BtMessageFactoryWeakHandle): New type definition.
* src/BitfieldMan.cc
(BitfieldMan): Added cachedNumMissingBlock,
cachedNumFilteredBlock,
cachedCompletedLength, cachedFilteredComletedLength,
cachedFilteredTotalLength.
Call updateCache().
(countMissingBlock): Return cachedNumMissingBlock.
(countMissingBlockNow): New function.
(countBlock): Return cachedNumFilteredBlock if filterEnabled is
true.
(countFilteredBlockNow): New function.
(setBit): Call updateCache().
(unsetBit): Call updateCache().
(setBitfield): Call updateCache().
(clearAllBit): Call updateCache().
(setAllBit): Use setBitInternal instead of setBit.
Call updateCache().
(addFilter): Call updateCache().
(enableFilter): Call updateCache().
(disableFilter): Call updateCache().
(clearFilter): Call updateCache().
(getFilteredTotalLength): Return cachedFilteredTotalLength.
(getFilteredTotalLengthNow): New function.
(getCompletedLength): Return cachedCompletedLength.
(getCompletedLengthNow): New function.
(getFilteredCompletedLength): Return
cachedFilteredComletedLength.
(getFilteredCompletedLengthNow): New function.
(updateCache): New function.
* src/BtMessageReceiver.h
(BtMessageReceiverWeakHandle): New type definition.
* src/DefaultBtMessageReceiver.cc
(receiveHandshake): Use messageFactory member.
(sendHandshake): Use messageFactory member.
(receiveMessage): Use messageFactory member.
* src/DefaultBtMessageFactory.h
(dispatcher): New variable.
(requestFactory): New variable.
(peerConnection): New variablle.
(setBtMessageDispatcher): New function.
(setBtRequestFactory): New function.
(setPeerConnection): New function.
* src/SharedHandle.h
(RefCount): New class.
(WeakHandle): New class.
* src/PeerObject.h
(BtMessageReceiver.h): New include.
(PeerObject): Added btMessageReceiver.
(btMessageReceiver): New variable.
* src/Util.cc
(countBit): Simplified.
* src/BtCancelMessage.cc
(doReceivedAction): Use dispatcher member.
* src/BtRequestFactory.h
(BtRequestFactoryWeakHandle): New type definition.
* src/PeerStorage.h
(downloadSpeed): int -> uint32_t
(uploadSpeed): int -> uint32_t
(sessionDownloadLength): long long int -> uint64_t
(sessionUploadLength): long long int -> uint64_t
2007-01-16 15:20:26 +00:00
|
|
|
btMessageDispatcher->setRequestTimeout(60);
|
2013-06-29 15:31:50 +00:00
|
|
|
btMessageDispatcher->addOutstandingRequest
|
|
|
|
(make_unique<RequestSlot>(0, 0, MY_PIECE_LENGTH, 0, piece));
|
2006-12-24 06:25:21 +00:00
|
|
|
|
|
|
|
btMessageDispatcher->checkRequestSlotAndDoNecessaryThing();
|
|
|
|
|
2008-11-03 06:49:02 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)1,
|
2010-01-05 16:01:46 +00:00
|
|
|
btMessageDispatcher->getMessageQueue().size());
|
2008-11-03 06:49:02 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)0,
|
2010-01-05 16:01:46 +00:00
|
|
|
btMessageDispatcher->getRequestSlots().size());
|
2006-12-24 06:25:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void DefaultBtMessageDispatcherTest::testCountOutstandingRequest() {
|
2013-06-29 15:31:50 +00:00
|
|
|
btMessageDispatcher->addOutstandingRequest
|
|
|
|
(make_unique<RequestSlot>(0, 0, MY_PIECE_LENGTH, 0));
|
2008-11-03 06:49:02 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)1,
|
2010-01-05 16:01:46 +00:00
|
|
|
btMessageDispatcher->countOutstandingRequest());
|
2006-12-24 06:25:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void DefaultBtMessageDispatcherTest::testIsOutstandingRequest() {
|
2013-06-29 15:31:50 +00:00
|
|
|
btMessageDispatcher->addOutstandingRequest
|
|
|
|
(make_unique<RequestSlot>(0, 0, MY_PIECE_LENGTH, 0));
|
2006-12-24 06:25:21 +00:00
|
|
|
|
|
|
|
CPPUNIT_ASSERT(btMessageDispatcher->isOutstandingRequest(0, 0));
|
|
|
|
CPPUNIT_ASSERT(!btMessageDispatcher->isOutstandingRequest(0, 1));
|
2012-10-01 14:52:22 +00:00
|
|
|
CPPUNIT_ASSERT(!btMessageDispatcher->isOutstandingRequest(1, 0));
|
|
|
|
CPPUNIT_ASSERT(!btMessageDispatcher->isOutstandingRequest(1, 1));
|
2006-12-24 06:25:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void DefaultBtMessageDispatcherTest::testGetOutstandingRequest() {
|
2013-06-29 15:31:50 +00:00
|
|
|
btMessageDispatcher->addOutstandingRequest
|
|
|
|
(make_unique<RequestSlot>(1, 1024, 16*1024, 10));
|
2006-12-24 06:25:21 +00:00
|
|
|
|
2013-06-29 15:31:50 +00:00
|
|
|
CPPUNIT_ASSERT(btMessageDispatcher->getOutstandingRequest(1, 1024, 16*1024));
|
2006-12-24 06:25:21 +00:00
|
|
|
|
2013-06-29 15:31:50 +00:00
|
|
|
CPPUNIT_ASSERT(!btMessageDispatcher->
|
|
|
|
getOutstandingRequest(1, 1024, 17*1024));
|
2006-12-24 06:25:21 +00:00
|
|
|
|
2013-06-29 15:31:50 +00:00
|
|
|
CPPUNIT_ASSERT(!btMessageDispatcher->
|
|
|
|
getOutstandingRequest(1, 2*1024, 16*1024));
|
2006-12-24 06:25:21 +00:00
|
|
|
|
2013-06-29 15:31:50 +00:00
|
|
|
CPPUNIT_ASSERT(!btMessageDispatcher->
|
|
|
|
getOutstandingRequest(2, 1024, 16*1024));
|
2006-12-24 06:25:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void DefaultBtMessageDispatcherTest::testRemoveOutstandingRequest() {
|
2013-06-29 15:31:50 +00:00
|
|
|
auto piece = std::make_shared<Piece>(1, 1024*1024);
|
2008-12-29 13:58:21 +00:00
|
|
|
size_t blockIndex = 0;
|
|
|
|
CPPUNIT_ASSERT(piece->getMissingUnusedBlockIndex(blockIndex));
|
|
|
|
uint32_t begin = blockIndex*piece->getBlockLength();
|
|
|
|
size_t length = piece->getBlockLength(blockIndex);
|
2013-06-29 15:31:50 +00:00
|
|
|
RequestSlot slot;
|
|
|
|
btMessageDispatcher->addOutstandingRequest
|
|
|
|
(make_unique<RequestSlot>(piece->getIndex(), begin, length, blockIndex,
|
|
|
|
piece));
|
|
|
|
|
|
|
|
auto s2 = btMessageDispatcher->getOutstandingRequest(piece->getIndex(),
|
|
|
|
begin, length);
|
|
|
|
CPPUNIT_ASSERT(s2);
|
2008-12-29 13:58:21 +00:00
|
|
|
CPPUNIT_ASSERT(piece->isBlockUsed(blockIndex));
|
2006-12-24 06:25:21 +00:00
|
|
|
|
|
|
|
btMessageDispatcher->removeOutstandingRequest(s2);
|
|
|
|
|
2013-06-29 15:31:50 +00:00
|
|
|
auto s3 = btMessageDispatcher->getOutstandingRequest(piece->getIndex(),
|
|
|
|
begin, length);
|
|
|
|
CPPUNIT_ASSERT(!s3);
|
2008-12-29 13:58:21 +00:00
|
|
|
CPPUNIT_ASSERT(!piece->isBlockUsed(blockIndex));
|
2006-12-24 06:25:21 +00:00
|
|
|
}
|
2008-02-08 15:53:45 +00:00
|
|
|
|
|
|
|
} // namespace aria2
|