|
@@ -24,7 +24,6 @@ class DefaultPieceStorageTest:public CppUnit::TestFixture {
|
|
|
CPPUNIT_TEST(testGetPiece);
|
|
|
CPPUNIT_TEST(testGetPieceInUsedPieces);
|
|
|
CPPUNIT_TEST(testGetPieceCompletedPiece);
|
|
|
- CPPUNIT_TEST(testGetMissingPiece_fileEntry);
|
|
|
CPPUNIT_TEST(testCancelPiece);
|
|
|
CPPUNIT_TEST(testMarkPiecesDone);
|
|
|
CPPUNIT_TEST_SUITE_END();
|
|
@@ -62,7 +61,6 @@ public:
|
|
|
void testGetPiece();
|
|
|
void testGetPieceInUsedPieces();
|
|
|
void testGetPieceCompletedPiece();
|
|
|
- void testGetMissingPiece_fileEntry();
|
|
|
void testCancelPiece();
|
|
|
void testMarkPiecesDone();
|
|
|
};
|
|
@@ -172,79 +170,10 @@ void DefaultPieceStorageTest::testGetPieceCompletedPiece() {
|
|
|
CPPUNIT_ASSERT_EQUAL(true, pieceGot->pieceComplete());
|
|
|
}
|
|
|
|
|
|
-void DefaultPieceStorageTest::testGetMissingPiece_fileEntry()
|
|
|
-{
|
|
|
- // - 32KB
|
|
|
- // +--------+
|
|
|
- // |11111222|
|
|
|
- int32_t pieceLength = 256*1024;
|
|
|
- int64_t totalLength = 1*pieceLength;
|
|
|
- int32_t blockLength = 16*1024;
|
|
|
- std::deque<std::string> uris1;
|
|
|
- uris1.push_back("http://localhost/src/file1.txt");
|
|
|
- std::deque<std::string> uris2;
|
|
|
- uris2.push_back("http://localhost/src/file2.txt");
|
|
|
- SharedHandle<FileEntry> file1 = new FileEntry("src/file1.txt", 150*1024, 0/*, uris1*/);
|
|
|
- SharedHandle<FileEntry> file2 = new FileEntry("src/file2.txt", 106*1024, file1->getLength() /*, uris2*/);
|
|
|
-
|
|
|
- SharedHandle<MockBtContext> dctx = new MockBtContext();
|
|
|
- dctx->setPieceLength(pieceLength);
|
|
|
- dctx->setTotalLength(totalLength);
|
|
|
- dctx->addFileEntry(file1);
|
|
|
- dctx->addFileEntry(file2);
|
|
|
-
|
|
|
- SharedHandle<DefaultPieceStorage> ps = new DefaultPieceStorage(dctx, option);
|
|
|
-
|
|
|
- SharedHandle<Piece> p = ps->getMissingPiece(file1);
|
|
|
- CPPUNIT_ASSERT(!p.isNull());
|
|
|
- CPPUNIT_ASSERT_EQUAL((int32_t)0, p->getIndex());
|
|
|
-
|
|
|
- for(int32_t i = 0; i < 9; ++i) {
|
|
|
- p->completeBlock(i);
|
|
|
- }
|
|
|
- SharedHandle<Piece> subPiece = new Piece(9, blockLength, 1);
|
|
|
- p->addSubPiece(subPiece);
|
|
|
-
|
|
|
- ps->cancelPiece(p);
|
|
|
-
|
|
|
- // Piece index = 0 should be retrieved again because the part of file1 is
|
|
|
- // not complete
|
|
|
- SharedHandle<Piece> p2 = ps->getMissingPiece(file1);
|
|
|
- CPPUNIT_ASSERT(!p2.isNull());
|
|
|
- CPPUNIT_ASSERT_EQUAL((int32_t)0, p2->getIndex());
|
|
|
-
|
|
|
- // Make the part of file1 complete
|
|
|
- for(int32_t i = 0; i < 6*1024; ++i) {
|
|
|
- p2->getSubPiece(9)->completeBlock(i);
|
|
|
- }
|
|
|
- ps->cancelPiece(p2);
|
|
|
-
|
|
|
- // Null Piece should be retrieved
|
|
|
- CPPUNIT_ASSERT(ps->getMissingPiece(file1).isNull());
|
|
|
-
|
|
|
- // Next, I retrive the piece giving file2
|
|
|
- SharedHandle<Piece> p3 = ps->getMissingPiece(file2);
|
|
|
- CPPUNIT_ASSERT(!p3.isNull());
|
|
|
- CPPUNIT_ASSERT_EQUAL((int32_t)0, p3->getIndex());
|
|
|
-
|
|
|
- // Make the part of file2 complete
|
|
|
- for(int32_t i = 6*1024; i < 16*1024; ++i) {
|
|
|
- p3->getSubPiece(9)->completeBlock(i);
|
|
|
- }
|
|
|
- for(int32_t i = 10; i < 16; ++i) {
|
|
|
- p3->completeBlock(i);
|
|
|
- }
|
|
|
- ps->cancelPiece(p3);
|
|
|
-
|
|
|
- // Null Piece should be retrieved
|
|
|
- CPPUNIT_ASSERT(ps->getMissingPiece(file2).isNull());
|
|
|
-}
|
|
|
-
|
|
|
void DefaultPieceStorageTest::testCancelPiece()
|
|
|
{
|
|
|
int32_t pieceLength = 256*1024;
|
|
|
int64_t totalLength = 32*pieceLength; // <-- make the number of piece greater than END_GAME_PIECE_NUM
|
|
|
- int32_t blockLength = 16*1024;
|
|
|
std::deque<std::string> uris1;
|
|
|
uris1.push_back("http://localhost/src/file1.txt");
|
|
|
SharedHandle<FileEntry> file1 = new FileEntry("src/file1.txt", totalLength, 0 /*, uris1*/);
|
|
@@ -256,18 +185,14 @@ void DefaultPieceStorageTest::testCancelPiece()
|
|
|
|
|
|
SharedHandle<DefaultPieceStorage> ps = new DefaultPieceStorage(dctx, option);
|
|
|
|
|
|
- SharedHandle<Piece> p = ps->getMissingPiece(file1);
|
|
|
+ SharedHandle<Piece> p = ps->getMissingPiece();
|
|
|
+ p->completeBlock(0);
|
|
|
|
|
|
- SharedHandle<Piece> subPiece = new Piece(0, blockLength, 1);
|
|
|
- subPiece->completeBlock(0);
|
|
|
- p->addSubPiece(subPiece);
|
|
|
-
|
|
|
ps->cancelPiece(p);
|
|
|
|
|
|
- // See the sub piece is also hibernated...
|
|
|
- SharedHandle<Piece> p2 = ps->getMissingPiece(file1);
|
|
|
+ SharedHandle<Piece> p2 = ps->getMissingPiece();
|
|
|
|
|
|
- CPPUNIT_ASSERT(!p2->getSubPiece(0).isNull());
|
|
|
+ CPPUNIT_ASSERT(p2->hasBlock(0));
|
|
|
}
|
|
|
|
|
|
void DefaultPieceStorageTest::testMarkPiecesDone()
|