void testCriticalChunkSpread() { DummyTorrentCreator creator; bt::TorrentControl tc; QVERIFY(creator.createSingleFileTorrent(2*TEST_FILE_SIZE,"test2.avi")); Out(SYS_GEN|LOG_DEBUG) << "Created " << creator.torrentPath() << endl; try { tc.init(0,creator.torrentPath(),creator.tempPath() + "tor0",creator.tempPath() + "data/"); tc.createFiles(); } catch (bt::Error & err) { Out(SYS_GEN|LOG_DEBUG) << "Failed to load torrent: " << creator.torrentPath() << endl; QFAIL("Torrent load failure"); } ExtendedStreamingChunkSelector* csel = new ExtendedStreamingChunkSelector(); tc.setChunkSelector(csel); QVERIFY(csel != 0); Downloader* downer = csel->downloader(); QVERIFY(downer != 0); // Check that critical chunks are spread over multiple peers csel->setSequentialRange(20,60); DummyDownloader dd[32]; for (Uint32 i = 0;i < 32;i++) { downer->addPieceDownloader(&dd[i]); } // Check the spread of the downloaders downer->update(); for (Uint32 i = 20;i < csel->criticialWindowSize();i++) { QVERIFY(downer->downloading(i)); QVERIFY(downer->download(i)->getNumDownloaders() == 32 / csel->criticialWindowSize()); } for (Uint32 i = 0;i < 32;i++) { QVERIFY(dd[i].getNumGrabbed() == 1); } for (Uint32 i = 0;i < 32;i++) { downer->removePieceDownloader(&dd[i]); } // cleanup tc.setChunkSelector(0); }
void testObj::test<3>(void) { // note that there is race condition in next two lines - it may happen that between // download of blacklisted IPs by strategy and download by donwloader it may change // thus there is some (small) probablilty that this test will randomly fail. const Downloader dwnl(1); // just one entry to download const DShieldParser dsp( dwnl.download() ); // parse it Strategy s( InstanceName("x"), Strategy::Parameters(1, 10, 0.5) ); // initiliaze strategy to use ensure("no entries parsed", dsp.begin()!=dsp.end() ); GraphNodePtrNN leaf=makeNewLeaf( (*dsp.begin()).to_string().c_str() ); // make leaf that is blacklisted // this host should be blacklisted s.process(leaf, changed_); ensure_equals("nothing changed", changed_.size(), 1u); changed_.clear(); // now it should NOT be blacklisted, since it has already changed s.process(leaf, changed_); ensure_equals("the same host has been black-listed twice", changed_.size(), 0u); }