Protocols::BitTorrent::Transfers::Testing::ChokerTest Class Reference

Inherits TestFixture.

Inheritance diagram for Protocols::BitTorrent::Transfers::Testing::ChokerTest:

Inheritance graph
[legend]
Collaboration diagram for Protocols::BitTorrent::Transfers::Testing::ChokerTest:

Collaboration graph
[legend]
List of all members.

Detailed Description

Tests for Choker.

Definition at line 38 of file ChokerTest.cpp.

Public Member Functions

 ChokerTest ()
void setUp ()
void tearDown ()
void sessionsStateSetPeerIsChoked (const Sessions &sessions, bool choked)
 Stubbes isPeerChoked() with choked for sessions.
void sessionsStateSetPeerIsInterested (const Sessions &sessions, bool interested)
 Stubbes isPeerChoked() with interested for sessions.
void sessionsStateSetPeerIsSeeder (const Sessions &sessions, bool seeder)
 Stubbes isPeerChoked() with choked for sessions.
void sessionsStateSetWeAreSnubbed (const Sessions &sessions, bool snubbed)
 Stubbes areWeSnubbed() with choked for sessions.
void refOpenSessions (const Sessions &sessions)
 Adds a newly opened sessions to Choker.
void refCloseSessions (const Sessions &sessions)
 Reports to Choker that the sessions were closed.
void refChokingTimeUnchokeChokeSessions (const Sessions &unchokedSessions, const Sessions &chokedSessions, const QList< int > &randomInts=QList< int >())
 Chokes and unchokes sessions when the choking time comes.
void testStartingChokerStartsTheTimer ()
 Starting the Choker should result in starting the choking timer.
void testStoppingChokerStopsTheTimer ()
 When the choker is stopped the choking timer should be stopped too.
void testAddOneSessionItGetsUnchokedNextChokingTime ()
 A newly opened session is initially choked but is then unchoked.
void testAddFourSessionsAllGetUnchokedNextChokingTime ()
 Four new sessions are unchoked after they have been added.
void testAddFiveSessionsFiveNotInterestedGetUnchokedNextChokingTime ()
 Not interested sessions are always unchoked according to specs.
void testAddFiveSessionsFourInterestedGetUnchokedNextChokingTime ()
 If all sessions are interested, then only the first four get unchoked.
void testFifthSessionUnchokedDuringFirstOptimisticUnchoking ()
 Verify optimistic choking works with all sessions having equal ratings.
void testForthSessionUnchokedDuringSecondUnchoking ()
 Verify optimistic choking works with all sessions having equal ratings.
void testOptimisticUnchokeDoesNotChangeFor2ChokingTimes ()
 The optimistic unchoke will not change even if we download nothing.
void testUnchokePeersWeDownloadFastestFrom ()
 Fastest peers we download from should be unchoked.
void testAntiSnubbingOneSnubbedSessionTwoOptimisticChokes ()
 Snubbed unchoked sessions are choked during optimistic unchoking.
void testAntiSnubbingHasNoEffectWhenNoConnectionsAreChoked ()
 Even if we are snubbed we could do nothing if there's noone to unchoke.
void testClosedSessionsAreNeitherChokedNorUnchokedAnymore ()
 Closing a session should get it removed from the Choker's internal list.
void testSeedersAreAlwaysKeptChoked ()
 Seeding peers should always be choked, they are not downloaders.
void testSeedersAreNeverOptimisticlyUnchoked ()
 Seeding peers should never be optimisticly unchoked.
void testOptimisticUnchokingPicksRandomlyFromMultipleCandidates ()
 Randomly pick a candidate for optimistic unchoking.
void testUnchokeSessionsWithHighestUploadRateWhenInSeedingMode ()
void testWeIngnoreBeingSnubbedWhenWeAreInSeedingMode ()
 No additional optimistic unchokes per snubbed session if only seeding.

Private Types

typedef QList< TransferSessionMock * > Sessions
typedef QMap< TransferSessionMock *,
SessionState
SessionsStateMap

Private Member Functions

 CPPUNIT_TEST_SUITE (ChokerTest)
 CPPUNIT_TEST (testStartingChokerStartsTheTimer)
 CPPUNIT_TEST (testStoppingChokerStopsTheTimer)
 CPPUNIT_TEST (testAddOneSessionItGetsUnchokedNextChokingTime)
 CPPUNIT_TEST (testAddFourSessionsAllGetUnchokedNextChokingTime)
 CPPUNIT_TEST (testAddFiveSessionsFiveNotInterestedGetUnchokedNextChokingTime)
 CPPUNIT_TEST (testAddFiveSessionsFourInterestedGetUnchokedNextChokingTime)
 CPPUNIT_TEST (testFifthSessionUnchokedDuringFirstOptimisticUnchoking)
 CPPUNIT_TEST (testForthSessionUnchokedDuringSecondUnchoking)
 CPPUNIT_TEST (testOptimisticUnchokeDoesNotChangeFor2ChokingTimes)
 CPPUNIT_TEST (testUnchokePeersWeDownloadFastestFrom)
 CPPUNIT_TEST (testAntiSnubbingOneSnubbedSessionTwoOptimisticChokes)
 CPPUNIT_TEST (testAntiSnubbingHasNoEffectWhenNoConnectionsAreChoked)
 CPPUNIT_TEST (testClosedSessionsAreNeitherChokedNorUnchokedAnymore)
 CPPUNIT_TEST (testSeedersAreAlwaysKeptChoked)
 CPPUNIT_TEST (testSeedersAreNeverOptimisticlyUnchoked)
 CPPUNIT_TEST (testOptimisticUnchokingPicksRandomlyFromMultipleCandidates)
 CPPUNIT_TEST (testUnchokeSessionsWithHighestUploadRateWhenInSeedingMode)
 CPPUNIT_TEST (testWeIngnoreBeingSnubbedWhenWeAreInSeedingMode)
 CPPUNIT_TEST_SUITE_END ()

Private Attributes

auto_ptr< TimerMock > timer
auto_ptr< RandomNumberGeneratorMock > randomNumberGenerator
auto_ptr< TransferManagerStateMock > transferManagerState
auto_ptr< ChokerchokerReal
auto_ptr< ChokerDriver > choker
Sessions sessions
SessionsStateMap sessionsState
Sessions openedSessions
const Choke choke
const Unchoke unchoke
QList< int > randomIntsZero
QList< int > randomIntsZeroZero
bool isTestingSeedingMode

Static Private Attributes

static const int SessionsCount = 10

Classes

struct  SessionState


Member Typedef Documentation

typedef QList<TransferSessionMock *> Protocols::BitTorrent::Transfers::Testing::ChokerTest::Sessions [private]
 

Definition at line 75 of file ChokerTest.cpp.

typedef QMap<TransferSessionMock *, SessionState> Protocols::BitTorrent::Transfers::Testing::ChokerTest::SessionsStateMap [private]
 

Definition at line 76 of file ChokerTest.cpp.


Constructor & Destructor Documentation

Protocols::BitTorrent::Transfers::Testing::ChokerTest::ChokerTest  )  [inline]
 

Definition at line 95 of file ChokerTest.cpp.


Member Function Documentation

Protocols::BitTorrent::Transfers::Testing::ChokerTest::CPPUNIT_TEST testWeIngnoreBeingSnubbedWhenWeAreInSeedingMode   )  [private]
 

Protocols::BitTorrent::Transfers::Testing::ChokerTest::CPPUNIT_TEST testUnchokeSessionsWithHighestUploadRateWhenInSeedingMode   )  [private]
 

Protocols::BitTorrent::Transfers::Testing::ChokerTest::CPPUNIT_TEST testOptimisticUnchokingPicksRandomlyFromMultipleCandidates   )  [private]
 

Protocols::BitTorrent::Transfers::Testing::ChokerTest::CPPUNIT_TEST testSeedersAreNeverOptimisticlyUnchoked   )  [private]
 

Protocols::BitTorrent::Transfers::Testing::ChokerTest::CPPUNIT_TEST testSeedersAreAlwaysKeptChoked   )  [private]
 

Protocols::BitTorrent::Transfers::Testing::ChokerTest::CPPUNIT_TEST testClosedSessionsAreNeitherChokedNorUnchokedAnymore   )  [private]
 

Protocols::BitTorrent::Transfers::Testing::ChokerTest::CPPUNIT_TEST testAntiSnubbingHasNoEffectWhenNoConnectionsAreChoked   )  [private]
 

Protocols::BitTorrent::Transfers::Testing::ChokerTest::CPPUNIT_TEST testAntiSnubbingOneSnubbedSessionTwoOptimisticChokes   )  [private]
 

Protocols::BitTorrent::Transfers::Testing::ChokerTest::CPPUNIT_TEST testUnchokePeersWeDownloadFastestFrom   )  [private]
 

Protocols::BitTorrent::Transfers::Testing::ChokerTest::CPPUNIT_TEST testOptimisticUnchokeDoesNotChangeFor2ChokingTimes   )  [private]
 

Protocols::BitTorrent::Transfers::Testing::ChokerTest::CPPUNIT_TEST testForthSessionUnchokedDuringSecondUnchoking   )  [private]
 

Protocols::BitTorrent::Transfers::Testing::ChokerTest::CPPUNIT_TEST testFifthSessionUnchokedDuringFirstOptimisticUnchoking   )  [private]
 

Protocols::BitTorrent::Transfers::Testing::ChokerTest::CPPUNIT_TEST testAddFiveSessionsFourInterestedGetUnchokedNextChokingTime   )  [private]
 

Protocols::BitTorrent::Transfers::Testing::ChokerTest::CPPUNIT_TEST testAddFiveSessionsFiveNotInterestedGetUnchokedNextChokingTime   )  [private]
 

Protocols::BitTorrent::Transfers::Testing::ChokerTest::CPPUNIT_TEST testAddFourSessionsAllGetUnchokedNextChokingTime   )  [private]
 

Protocols::BitTorrent::Transfers::Testing::ChokerTest::CPPUNIT_TEST testAddOneSessionItGetsUnchokedNextChokingTime   )  [private]
 

Protocols::BitTorrent::Transfers::Testing::ChokerTest::CPPUNIT_TEST testStoppingChokerStopsTheTimer   )  [private]
 

Protocols::BitTorrent::Transfers::Testing::ChokerTest::CPPUNIT_TEST testStartingChokerStartsTheTimer   )  [private]
 

Protocols::BitTorrent::Transfers::Testing::ChokerTest::CPPUNIT_TEST_SUITE ChokerTest   )  [private]
 

Protocols::BitTorrent::Transfers::Testing::ChokerTest::CPPUNIT_TEST_SUITE_END  )  [private]
 

void Protocols::BitTorrent::Transfers::Testing::ChokerTest::refChokingTimeUnchokeChokeSessions const Sessions unchokedSessions,
const Sessions chokedSessions,
const QList< int > &  randomInts = QList <int>()
[inline]
 

Chokes and unchokes sessions when the choking time comes.

Parameters:
unchokesSession are the sessions that will be unchoked at this choking round.
chokedSessions are the sessions that will be choked at this choking rount.
randomInts is the list of ints that the RandomNumberGenerator will returns.
Note:
The stubbed values for isPeerStubbed() of the sessions in unchokedSessions and chokedSessions are also updated.

Definition at line 200 of file ChokerTest.cpp.

void Protocols::BitTorrent::Transfers::Testing::ChokerTest::refCloseSessions const Sessions sessions  )  [inline]
 

Reports to Choker that the sessions were closed.

Definition at line 178 of file ChokerTest.cpp.

void Protocols::BitTorrent::Transfers::Testing::ChokerTest::refOpenSessions const Sessions sessions  )  [inline]
 

Adds a newly opened sessions to Choker.

Definition at line 168 of file ChokerTest.cpp.

void Protocols::BitTorrent::Transfers::Testing::ChokerTest::sessionsStateSetPeerIsChoked const Sessions sessions,
bool  choked
[inline]
 

Stubbes isPeerChoked() with choked for sessions.

Definition at line 139 of file ChokerTest.cpp.

void Protocols::BitTorrent::Transfers::Testing::ChokerTest::sessionsStateSetPeerIsInterested const Sessions sessions,
bool  interested
[inline]
 

Stubbes isPeerChoked() with interested for sessions.

Definition at line 146 of file ChokerTest.cpp.

void Protocols::BitTorrent::Transfers::Testing::ChokerTest::sessionsStateSetPeerIsSeeder const Sessions sessions,
bool  seeder
[inline]
 

Stubbes isPeerChoked() with choked for sessions.

Definition at line 154 of file ChokerTest.cpp.

void Protocols::BitTorrent::Transfers::Testing::ChokerTest::sessionsStateSetWeAreSnubbed const Sessions sessions,
bool  snubbed
[inline]
 

Stubbes areWeSnubbed() with choked for sessions.

Definition at line 161 of file ChokerTest.cpp.

void Protocols::BitTorrent::Transfers::Testing::ChokerTest::setUp  )  [inline]
 

Definition at line 107 of file ChokerTest.cpp.

void Protocols::BitTorrent::Transfers::Testing::ChokerTest::tearDown  )  [inline]
 

Definition at line 123 of file ChokerTest.cpp.

void Protocols::BitTorrent::Transfers::Testing::ChokerTest::testAddFiveSessionsFiveNotInterestedGetUnchokedNextChokingTime  )  [inline]
 

Not interested sessions are always unchoked according to specs.

Definition at line 292 of file ChokerTest.cpp.

void Protocols::BitTorrent::Transfers::Testing::ChokerTest::testAddFiveSessionsFourInterestedGetUnchokedNextChokingTime  )  [inline]
 

If all sessions are interested, then only the first four get unchoked.

Definition at line 301 of file ChokerTest.cpp.

void Protocols::BitTorrent::Transfers::Testing::ChokerTest::testAddFourSessionsAllGetUnchokedNextChokingTime  )  [inline]
 

Four new sessions are unchoked after they have been added.

Definition at line 284 of file ChokerTest.cpp.

void Protocols::BitTorrent::Transfers::Testing::ChokerTest::testAddOneSessionItGetsUnchokedNextChokingTime  )  [inline]
 

A newly opened session is initially choked but is then unchoked.

Definition at line 276 of file ChokerTest.cpp.

void Protocols::BitTorrent::Transfers::Testing::ChokerTest::testAntiSnubbingHasNoEffectWhenNoConnectionsAreChoked  )  [inline]
 

Even if we are snubbed we could do nothing if there's noone to unchoke.

Definition at line 463 of file ChokerTest.cpp.

void Protocols::BitTorrent::Transfers::Testing::ChokerTest::testAntiSnubbingOneSnubbedSessionTwoOptimisticChokes  )  [inline]
 

Snubbed unchoked sessions are choked during optimistic unchoking.

If we have unchoked peers that stubbed us, then we shoke these peers and assign these slots to optimistic unchoking. Then we will do more than one optimistic unchoke.

In this test we have two connections that are choked. When time for optimistic unchoking comes, then we choke the snubbed session and unchoke two instead of one session optimisticly.

Definition at line 447 of file ChokerTest.cpp.

void Protocols::BitTorrent::Transfers::Testing::ChokerTest::testClosedSessionsAreNeitherChokedNorUnchokedAnymore  )  [inline]
 

Closing a session should get it removed from the Choker's internal list.

If we open a session and close it right away before the first unchoking round then the session should not be unchoked in the first round to come because it has already been closed.

Definition at line 481 of file ChokerTest.cpp.

void Protocols::BitTorrent::Transfers::Testing::ChokerTest::testFifthSessionUnchokedDuringFirstOptimisticUnchoking  )  [inline]
 

Verify optimistic choking works with all sessions having equal ratings.

  • First choking time first 4 sessions get unchoked.
  • Second choking time no ratings change, no chokes/unchokes.
  • Third choking time is optimistic choking - choke 4th session unchoke 5th session.

This test also verifies that sessions are consistently choked/unchoked. This means, a session that has already been choked is not choked again, a session that has already been unchoked is not unchoked again. Only changes in the state result in sending out packets. That is seen by the fact that during the second choking time no choke/unchoke packets are sent.

Definition at line 323 of file ChokerTest.cpp.

void Protocols::BitTorrent::Transfers::Testing::ChokerTest::testForthSessionUnchokedDuringSecondUnchoking  )  [inline]
 

Verify optimistic choking works with all sessions having equal ratings.

After first optimistic unchoking 4th session is choked and 5th is unchoked. The second optimistic unchoking chokes the 5th session and unchokes again the 4th session.

This is done with all sessions having equal ratings. The sorting algorithm should be stable and this tests verifeis that.

Definition at line 345 of file ChokerTest.cpp.

void Protocols::BitTorrent::Transfers::Testing::ChokerTest::testOptimisticUnchokeDoesNotChangeFor2ChokingTimes  )  [inline]
 

The optimistic unchoke will not change even if we download nothing.

We will unchoke sessions from which we download a lot but we keep choked. The exception is when we have optimistic unchokes. Optimistic unchokes will not be choked in favor of a session from which we download better. We could only do that at the next optimistic unchoking round.

Even though we download with 5b/s from session [3] and download nothing from session [4], we will not choke session [4] in favore of session [3] because session [4] was our optimistic unchoke.

Definition at line 368 of file ChokerTest.cpp.

void Protocols::BitTorrent::Transfers::Testing::ChokerTest::testOptimisticUnchokingPicksRandomlyFromMultipleCandidates  )  [inline]
 

Randomly pick a candidate for optimistic unchoking.

Note:
Previous test involving optimistic unchoking only had a single candidate. Let's now verify that the random number is correctly used for selecting from multiple candidates. Furthermore we want to verify that the modulo computation if performed correctly when a big integer is returned by the random number generator: 6 sessions are choked, but because all they are "new" each has a three times higher probability of being selected. We implement this by counting each new session as three sessions. Therefore we have a total of 18 choked candidates (6 of which are unique). We want to randomly unchoke the fourth unique session, which is at the indices 9, 10, 11 but we return a "random" number bigger then 18, e.g 28 => 28 mod 18 == 10 => we pich the fourth unique choked session, which is indeed sessions [7].

Definition at line 533 of file ChokerTest.cpp.

void Protocols::BitTorrent::Transfers::Testing::ChokerTest::testSeedersAreAlwaysKeptChoked  )  [inline]
 

Seeding peers should always be choked, they are not downloaders.

Sessions that start as seeders are never unchoked even if there are enough upload slots. Sessions that have turned into seeders must be choked.

Definition at line 494 of file ChokerTest.cpp.

void Protocols::BitTorrent::Transfers::Testing::ChokerTest::testSeedersAreNeverOptimisticlyUnchoked  )  [inline]
 

Seeding peers should never be optimisticly unchoked.

Definition at line 506 of file ChokerTest.cpp.

void Protocols::BitTorrent::Transfers::Testing::ChokerTest::testStartingChokerStartsTheTimer  )  [inline]
 

Starting the Choker should result in starting the choking timer.

We verify that the timer is initialized with the correct handler function and the correct timeout interval.

Definition at line 255 of file ChokerTest.cpp.

void Protocols::BitTorrent::Transfers::Testing::ChokerTest::testStoppingChokerStopsTheTimer  )  [inline]
 

When the choker is stopped the choking timer should be stopped too.

Definition at line 267 of file ChokerTest.cpp.

void Protocols::BitTorrent::Transfers::Testing::ChokerTest::testUnchokePeersWeDownloadFastestFrom  )  [inline]
 

Fastest peers we download from should be unchoked.

The fastests interested peers we download from get unchoked. The ones that are not interested but even faster get unchoked too.

Definition at line 387 of file ChokerTest.cpp.

void Protocols::BitTorrent::Transfers::Testing::ChokerTest::testUnchokeSessionsWithHighestUploadRateWhenInSeedingMode  )  [inline]
 

Definition at line 548 of file ChokerTest.cpp.

void Protocols::BitTorrent::Transfers::Testing::ChokerTest::testWeIngnoreBeingSnubbedWhenWeAreInSeedingMode  )  [inline]
 

No additional optimistic unchokes per snubbed session if only seeding.

Definition at line 600 of file ChokerTest.cpp.


Member Data Documentation

const Choke Protocols::BitTorrent::Transfers::Testing::ChokerTest::choke [private]
 

Definition at line 87 of file ChokerTest.cpp.

auto_ptr<ChokerDriver> Protocols::BitTorrent::Transfers::Testing::ChokerTest::choker [private]
 

Definition at line 82 of file ChokerTest.cpp.

auto_ptr<Choker> Protocols::BitTorrent::Transfers::Testing::ChokerTest::chokerReal [private]
 

Definition at line 81 of file ChokerTest.cpp.

bool Protocols::BitTorrent::Transfers::Testing::ChokerTest::isTestingSeedingMode [private]
 

Definition at line 91 of file ChokerTest.cpp.

Sessions Protocols::BitTorrent::Transfers::Testing::ChokerTest::openedSessions [private]
 

Definition at line 85 of file ChokerTest.cpp.

QList<int> Protocols::BitTorrent::Transfers::Testing::ChokerTest::randomIntsZero [private]
 

Definition at line 89 of file ChokerTest.cpp.

QList<int> Protocols::BitTorrent::Transfers::Testing::ChokerTest::randomIntsZeroZero [private]
 

Definition at line 90 of file ChokerTest.cpp.

auto_ptr<RandomNumberGeneratorMock> Protocols::BitTorrent::Transfers::Testing::ChokerTest::randomNumberGenerator [private]
 

Definition at line 79 of file ChokerTest.cpp.

Sessions Protocols::BitTorrent::Transfers::Testing::ChokerTest::sessions [private]
 

Definition at line 83 of file ChokerTest.cpp.

const int Protocols::BitTorrent::Transfers::Testing::ChokerTest::SessionsCount = 10 [static, private]
 

Definition at line 92 of file ChokerTest.cpp.

SessionsStateMap Protocols::BitTorrent::Transfers::Testing::ChokerTest::sessionsState [private]
 

Definition at line 84 of file ChokerTest.cpp.

auto_ptr<TimerMock> Protocols::BitTorrent::Transfers::Testing::ChokerTest::timer [private]
 

Definition at line 78 of file ChokerTest.cpp.

auto_ptr<TransferManagerStateMock> Protocols::BitTorrent::Transfers::Testing::ChokerTest::transferManagerState [private]
 

Definition at line 80 of file ChokerTest.cpp.

const Unchoke Protocols::BitTorrent::Transfers::Testing::ChokerTest::unchoke [private]
 

Definition at line 88 of file ChokerTest.cpp.


The documentation for this class was generated from the following file: