mirror of
https://github.com/aria2/aria2.git
synced 2025-02-26 08:22:11 +00:00
The old implementation calculates download/upload statistics for a RequestGroup by summing up all PeerStat objects. For global statistics, those are summed together. This clearly incurs runtime penalty and we introduced some kind of caching which updates statistics every 250ms but it did not work right. This change removes all these aggregation code, and instead makes RequestGroup and RequestGroupMan objects hold NetStat object and download/upload bytes are directly calculated by thier own NetStat. This is far more simplar than the old way and less runtime penalty and brings more accuracy.
47 lines
1.1 KiB
C++
47 lines
1.1 KiB
C++
#include "ShareRatioSeedCriteria.h"
|
|
|
|
#include <cppunit/extensions/HelperMacros.h>
|
|
|
|
#include "DownloadContext.h"
|
|
#include "BtRuntime.h"
|
|
#include "MockPieceStorage.h"
|
|
#include "FileEntry.h"
|
|
|
|
namespace aria2 {
|
|
|
|
class ShareRatioSeedCriteriaTest:public CppUnit::TestFixture {
|
|
|
|
CPPUNIT_TEST_SUITE(ShareRatioSeedCriteriaTest);
|
|
CPPUNIT_TEST(testEvaluate);
|
|
CPPUNIT_TEST_SUITE_END();
|
|
|
|
public:
|
|
void testEvaluate();
|
|
};
|
|
|
|
|
|
CPPUNIT_TEST_SUITE_REGISTRATION(ShareRatioSeedCriteriaTest);
|
|
|
|
void ShareRatioSeedCriteriaTest::testEvaluate() {
|
|
SharedHandle<DownloadContext> dctx(new DownloadContext(1024*1024, 1000000));
|
|
SharedHandle<BtRuntime> btRuntime(new BtRuntime());
|
|
btRuntime->setUploadLengthAtStartup(1000000);
|
|
|
|
SharedHandle<MockPieceStorage> pieceStorage(new MockPieceStorage());
|
|
pieceStorage->setCompletedLength(1000000);
|
|
|
|
ShareRatioSeedCriteria cri(1.0, dctx);
|
|
cri.setBtRuntime(btRuntime);
|
|
cri.setPieceStorage(pieceStorage);
|
|
|
|
CPPUNIT_ASSERT(cri.evaluate());
|
|
|
|
cri.setRatio(2.0);
|
|
CPPUNIT_ASSERT(!cri.evaluate());
|
|
// check div by zero
|
|
dctx->getFirstFileEntry()->setLength(0);
|
|
CPPUNIT_ASSERT(!cri.evaluate());
|
|
}
|
|
|
|
} // namespace aria2
|