aria2/test/DefaultBtMessageDispatcherTest.cc
Tatsuhiro Tsujikawa a1df7a762e 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

414 lines
14 KiB
C++

#include "DefaultBtMessageDispatcher.h"
#include "Util.h"
#include "Exception.h"
#include "MockPieceStorage.h"
#include "MockPeerStorage.h"
#include "BtRegistry.h"
#include "DefaultBtContext.h"
#include "MockBtMessage.h"
#include "MockBtMessageFactory.h"
#include "prefs.h"
#include "BtCancelSendingPieceEvent.h"
#include <cppunit/extensions/HelperMacros.h>
using namespace std;
class DefaultBtMessageDispatcherTest:public CppUnit::TestFixture {
CPPUNIT_TEST_SUITE(DefaultBtMessageDispatcherTest);
CPPUNIT_TEST(testAddMessage);
CPPUNIT_TEST(testSendMessages);
CPPUNIT_TEST(testSendMessages_underUploadLimit);
CPPUNIT_TEST(testSendMessages_overUploadLimit);
CPPUNIT_TEST(testSendMessages_sendingInProgress);
CPPUNIT_TEST(testDoCancelSendingPieceAction);
CPPUNIT_TEST(testCheckRequestSlotAndDoNecessaryThing);
CPPUNIT_TEST(testCheckRequestSlotAndDoNecessaryThing_timeout);
CPPUNIT_TEST(testCheckRequestSlotAndDoNecessaryThing_completeBlock);
CPPUNIT_TEST(testIsSendingInProgress);
CPPUNIT_TEST(testCountOutstandingRequest);
CPPUNIT_TEST(testIsOutstandingRequest);
CPPUNIT_TEST(testGetOutstandingRequest);
CPPUNIT_TEST(testRemoveOutstandingRequest);
CPPUNIT_TEST_SUITE_END();
private:
BtContextHandle btContext;
PeerHandle peer;
DefaultBtMessageDispatcherHandle btMessageDispatcher;
MockPeerStorageHandle peerStorage;
MockPieceStorageHandle pieceStorage;
public:
DefaultBtMessageDispatcherTest():btContext(0), peer(0), btMessageDispatcher(0) {}
void tearDown() {}
void testAddMessage();
void testSendMessages();
void testSendMessages_underUploadLimit();
void testSendMessages_overUploadLimit();
void testSendMessages_sendingInProgress();
void testDoCancelSendingPieceAction();
void testCheckRequestSlotAndDoNecessaryThing();
void testCheckRequestSlotAndDoNecessaryThing_timeout();
void testCheckRequestSlotAndDoNecessaryThing_completeBlock();
void testIsSendingInProgress();
void testCountOutstandingRequest();
void testIsOutstandingRequest();
void testGetOutstandingRequest();
void testRemoveOutstandingRequest();
class MockBtMessage2 : public MockBtMessage {
private:
bool onQueuedCalled;
bool sendCalled;
bool doCancelActionCalled;
public:
string type;
public:
MockBtMessage2():onQueuedCalled(false),
sendCalled(false),
doCancelActionCalled(false)
{}
virtual ~MockBtMessage2() {}
virtual void onQueued() {
onQueuedCalled = true;
}
bool isOnQueuedCalled() const {
return onQueuedCalled;
}
virtual void send() {
sendCalled = true;
}
bool isSendCalled() const {
return sendCalled;
}
virtual void handleEvent(const BtEventHandle& event) {
BtCancelSendingPieceEvent* e =
dynamic_cast<BtCancelSendingPieceEvent*>(event.get());
if(e) {
doCancelActionCalled = true;
}
}
bool isDoCancelActionCalled() const {
return doCancelActionCalled;
}
};
typedef SharedHandle<MockBtMessage2> MockBtMessage2Handle;
class MockPieceStorage2 : public MockPieceStorage {
private:
PieceHandle piece;
public:
virtual PieceHandle getPiece(int index) {
return piece;
}
void setPiece(const PieceHandle& piece) {
this->piece = piece;
}
};
class MockBtMessageFactory2 : public MockBtMessageFactory {
public:
virtual BtMessageHandle
createCancelMessage(int32_t index, int32_t begin, uint32_t length) {
MockBtMessage2Handle btMsg = new MockBtMessage2();
btMsg->type = "cancel";
return btMsg;
}
};
void setUp() {
btContext = new DefaultBtContext();
btContext->load("test.torrent");
peer = new Peer("192.168.0.1", 6969,
btContext->getPieceLength(),
btContext->getTotalLength());
peerStorage = new MockPeerStorage();
pieceStorage = new MockPieceStorage();
BtRegistry::clear();
BtRegistry::registerPeerStorage(btContext->getInfoHashAsString(),
peerStorage);
BtRegistry::registerPieceStorage(btContext->getInfoHashAsString(),
pieceStorage);
BtRegistry::registerPeerObjectCluster(btContext->getInfoHashAsString(),
new PeerObjectCluster());
PeerObjectHandle peerObject = new PeerObject();
peerObject->btMessageFactory = new MockBtMessageFactory2();
PEER_OBJECT_CLUSTER(btContext)->registerHandle(peer->getId(), peerObject);
btMessageDispatcher = new DefaultBtMessageDispatcher();
btMessageDispatcher->setCuid(1);
btMessageDispatcher->setBtContext(btContext);
btMessageDispatcher->setPeer(peer);
btMessageDispatcher->setMaxUploadSpeedLimit(0);
btMessageDispatcher->setBtMessageFactory(peerObject->btMessageFactory);
}
};
CPPUNIT_TEST_SUITE_REGISTRATION(DefaultBtMessageDispatcherTest);
void DefaultBtMessageDispatcherTest::testAddMessage() {
MockBtMessage2Handle msg = new MockBtMessage2();
CPPUNIT_ASSERT_EQUAL(false, msg->isOnQueuedCalled());
btMessageDispatcher->addMessageToQueue(msg);
CPPUNIT_ASSERT_EQUAL(true, msg->isOnQueuedCalled());
CPPUNIT_ASSERT_EQUAL((size_t)1,
btMessageDispatcher->getMessageQueue().size());
}
void DefaultBtMessageDispatcherTest::testSendMessages() {
TransferStat stat;
stat.setUploadSpeed(0);
peerStorage->setStat(stat);
MockBtMessage2Handle msg1 = new MockBtMessage2();
msg1->setSendingInProgress(false);
msg1->setUploading(false);
MockBtMessage2Handle msg2 = new MockBtMessage2();
msg2->setSendingInProgress(false);
msg2->setUploading(false);
btMessageDispatcher->addMessageToQueue(msg1);
btMessageDispatcher->addMessageToQueue(msg2);
btMessageDispatcher->sendMessages();
CPPUNIT_ASSERT(msg1->isSendCalled());
CPPUNIT_ASSERT(msg2->isSendCalled());
}
void DefaultBtMessageDispatcherTest::testSendMessages_underUploadLimit() {
TransferStat stat;
stat.setUploadSpeed(0);
peerStorage->setStat(stat);
MockBtMessage2Handle msg1 = new MockBtMessage2();
msg1->setSendingInProgress(false);
msg1->setUploading(true);
MockBtMessage2Handle msg2 = new MockBtMessage2();
msg2->setSendingInProgress(false);
msg2->setUploading(true);
btMessageDispatcher->addMessageToQueue(msg1);
btMessageDispatcher->addMessageToQueue(msg2);
btMessageDispatcher->sendMessages();
CPPUNIT_ASSERT(msg1->isSendCalled());
CPPUNIT_ASSERT(msg2->isSendCalled());
}
void DefaultBtMessageDispatcherTest::testSendMessages_overUploadLimit() {
btMessageDispatcher->setMaxUploadSpeedLimit(100);
TransferStat stat;
stat.setUploadSpeed(150);
peerStorage->setStat(stat);
MockBtMessage2Handle msg1 = new MockBtMessage2();
msg1->setSendingInProgress(false);
msg1->setUploading(true);
MockBtMessage2Handle msg2 = new MockBtMessage2();
msg2->setSendingInProgress(false);
msg2->setUploading(true);
MockBtMessage2Handle msg3 = new MockBtMessage2();
msg3->setSendingInProgress(false);
msg3->setUploading(false);
btMessageDispatcher->addMessageToQueue(msg1);
btMessageDispatcher->addMessageToQueue(msg2);
btMessageDispatcher->addMessageToQueue(msg3);
btMessageDispatcher->sendMessages();
CPPUNIT_ASSERT(!msg1->isSendCalled());
CPPUNIT_ASSERT(!msg2->isSendCalled());
CPPUNIT_ASSERT(msg3->isSendCalled());
CPPUNIT_ASSERT_EQUAL((size_t)2, btMessageDispatcher->getMessageQueue().size());
}
void DefaultBtMessageDispatcherTest::testSendMessages_sendingInProgress() {
MockBtMessage2Handle msg1 = new MockBtMessage2();
msg1->setSendingInProgress(false);
msg1->setUploading(false);
MockBtMessage2Handle msg2 = new MockBtMessage2();
msg2->setSendingInProgress(true);
msg2->setUploading(false);
MockBtMessage2Handle msg3 = new MockBtMessage2();
msg3->setSendingInProgress(false);
msg3->setUploading(false);
btMessageDispatcher->addMessageToQueue(msg1);
btMessageDispatcher->addMessageToQueue(msg2);
btMessageDispatcher->addMessageToQueue(msg3);
btMessageDispatcher->sendMessages();
CPPUNIT_ASSERT(msg1->isSendCalled());
CPPUNIT_ASSERT(msg2->isSendCalled());
CPPUNIT_ASSERT(!msg3->isSendCalled());
CPPUNIT_ASSERT_EQUAL((size_t)2, btMessageDispatcher->getMessageQueue().size());
}
void DefaultBtMessageDispatcherTest::testDoCancelSendingPieceAction() {
MockBtMessage2Handle msg1 = new MockBtMessage2();
MockBtMessage2Handle msg2 = new MockBtMessage2();
btMessageDispatcher->addMessageToQueue(msg1);
btMessageDispatcher->addMessageToQueue(msg2);
btMessageDispatcher->doCancelSendingPieceAction(0, 0, 0);
CPPUNIT_ASSERT_EQUAL(true, msg1->isDoCancelActionCalled());
CPPUNIT_ASSERT_EQUAL(true, msg2->isDoCancelActionCalled());
}
int MY_PIECE_LENGTH = 16*1024;
void DefaultBtMessageDispatcherTest::testCheckRequestSlotAndDoNecessaryThing() {
RequestSlot slot(0, 0, MY_PIECE_LENGTH, 0);
PieceHandle piece = new Piece(0, MY_PIECE_LENGTH);
assert(piece->getMissingUnusedBlockIndex() == 0);
SharedHandle<MockPieceStorage2> pieceStorage = new MockPieceStorage2();
pieceStorage->setPiece(piece);
CPPUNIT_ASSERT(BtRegistry::registerPieceStorage(btContext->getInfoHashAsString(),
pieceStorage));
btMessageDispatcher = new DefaultBtMessageDispatcher();
btMessageDispatcher->setCuid(1);
btMessageDispatcher->setBtContext(btContext);
btMessageDispatcher->setPeer(peer);
btMessageDispatcher->setRequestTimeout(60);
btMessageDispatcher->addOutstandingRequest(slot);
btMessageDispatcher->checkRequestSlotAndDoNecessaryThing();
CPPUNIT_ASSERT_EQUAL((size_t)0, btMessageDispatcher->getMessageQueue().size());
CPPUNIT_ASSERT_EQUAL((size_t)1, btMessageDispatcher->getRequestSlots().size());
}
void DefaultBtMessageDispatcherTest::testCheckRequestSlotAndDoNecessaryThing_timeout() {
RequestSlot slot(0, 0, MY_PIECE_LENGTH, 0);
// make this slot timeout
slot.setDispatchedTime(0);
PieceHandle piece = new Piece(0, MY_PIECE_LENGTH);
assert(piece->getMissingUnusedBlockIndex() == 0);
SharedHandle<MockPieceStorage2> pieceStorage = new MockPieceStorage2();
pieceStorage->setPiece(piece);
CPPUNIT_ASSERT(BtRegistry::registerPieceStorage(btContext->getInfoHashAsString(),
pieceStorage));
btMessageDispatcher = new DefaultBtMessageDispatcher();
btMessageDispatcher->setCuid(1);
btMessageDispatcher->setBtContext(btContext);
btMessageDispatcher->setPeer(peer);
btMessageDispatcher->setRequestTimeout(60);
btMessageDispatcher->setBtMessageFactory(BT_MESSAGE_FACTORY(btContext,
peer));
btMessageDispatcher->addOutstandingRequest(slot);
btMessageDispatcher->checkRequestSlotAndDoNecessaryThing();
CPPUNIT_ASSERT_EQUAL((size_t)0, btMessageDispatcher->getMessageQueue().size());
CPPUNIT_ASSERT_EQUAL((size_t)0, btMessageDispatcher->getRequestSlots().size());
CPPUNIT_ASSERT_EQUAL(false, piece->isBlockUsed(0));
CPPUNIT_ASSERT_EQUAL(true, peer->snubbing);
}
void DefaultBtMessageDispatcherTest::testCheckRequestSlotAndDoNecessaryThing_completeBlock() {
RequestSlot slot(0, 0, MY_PIECE_LENGTH, 0);
PieceHandle piece = new Piece(0, MY_PIECE_LENGTH);
piece->completeBlock(0);
SharedHandle<MockPieceStorage2> pieceStorage = new MockPieceStorage2();
pieceStorage->setPiece(piece);
CPPUNIT_ASSERT(BtRegistry::registerPieceStorage(btContext->getInfoHashAsString(),
pieceStorage));
btMessageDispatcher = new DefaultBtMessageDispatcher();
btMessageDispatcher->setCuid(1);
btMessageDispatcher->setBtContext(btContext);
btMessageDispatcher->setPeer(peer);
btMessageDispatcher->setRequestTimeout(60);
btMessageDispatcher->setBtMessageFactory(BT_MESSAGE_FACTORY(btContext,
peer));
btMessageDispatcher->addOutstandingRequest(slot);
btMessageDispatcher->checkRequestSlotAndDoNecessaryThing();
CPPUNIT_ASSERT_EQUAL((size_t)1, btMessageDispatcher->getMessageQueue().size());
CPPUNIT_ASSERT_EQUAL((size_t)0, btMessageDispatcher->getRequestSlots().size());
}
void DefaultBtMessageDispatcherTest::testIsSendingInProgress() {
CPPUNIT_ASSERT(!btMessageDispatcher->isSendingInProgress());
MockBtMessage2Handle msg = new MockBtMessage2();
msg->setSendingInProgress(false);
btMessageDispatcher->addMessageToQueue(msg);
CPPUNIT_ASSERT(!btMessageDispatcher->isSendingInProgress());
msg->setSendingInProgress(true);
CPPUNIT_ASSERT(btMessageDispatcher->isSendingInProgress());
}
void DefaultBtMessageDispatcherTest::testCountOutstandingRequest() {
RequestSlot slot(0, 0, MY_PIECE_LENGTH, 0);
btMessageDispatcher->addOutstandingRequest(slot);
CPPUNIT_ASSERT_EQUAL((uint32_t)1, btMessageDispatcher->countOutstandingRequest());
}
void DefaultBtMessageDispatcherTest::testIsOutstandingRequest() {
RequestSlot slot(0, 0, MY_PIECE_LENGTH, 0);
btMessageDispatcher->addOutstandingRequest(slot);
CPPUNIT_ASSERT(btMessageDispatcher->isOutstandingRequest(0, 0));
CPPUNIT_ASSERT(!btMessageDispatcher->isOutstandingRequest(0, 1));
CPPUNIT_ASSERT(!btMessageDispatcher->isOutstandingRequest(1, 0));
CPPUNIT_ASSERT(!btMessageDispatcher->isOutstandingRequest(1, 1));
}
void DefaultBtMessageDispatcherTest::testGetOutstandingRequest() {
RequestSlot slot(1, 1024, 16*1024, 10);
btMessageDispatcher->addOutstandingRequest(slot);
RequestSlot s2 = btMessageDispatcher->getOutstandingRequest(1, 1024, 16*1024);
CPPUNIT_ASSERT(!RequestSlot::isNull(s2));
RequestSlot s3 = btMessageDispatcher->getOutstandingRequest(1, 1024, 17*1024);
CPPUNIT_ASSERT(RequestSlot::isNull(s3));
RequestSlot s4 = btMessageDispatcher->getOutstandingRequest(1, 2*1024, 16*1024);
CPPUNIT_ASSERT(RequestSlot::isNull(s4));
RequestSlot s5 = btMessageDispatcher->getOutstandingRequest(2, 1024, 16*1024);
CPPUNIT_ASSERT(RequestSlot::isNull(s5));
}
void DefaultBtMessageDispatcherTest::testRemoveOutstandingRequest() {
RequestSlot slot(1, 1024, 16*1024, 10);
btMessageDispatcher->addOutstandingRequest(slot);
RequestSlot s2 = btMessageDispatcher->getOutstandingRequest(1, 1024, 16*1024);
CPPUNIT_ASSERT(!RequestSlot::isNull(s2));
btMessageDispatcher->removeOutstandingRequest(s2);
RequestSlot s3 = btMessageDispatcher->getOutstandingRequest(1, 1024, 16*1024);
CPPUNIT_ASSERT(RequestSlot::isNull(s3));
}