Search in sources :

Example 1 with TorrentPiece

use of com.acgist.snail.pojo.bean.TorrentPiece in project snail by acgist.

the class TorrentStreamGroupTest method testPick.

@Test
void testPick() throws DownloadException {
    LoggerConfig.off();
    final var path = "E:/snail/07E1B909D8D193D80E440A8593FB57A658223A0E.torrent";
    final var session = TorrentContext.getInstance().newTorrentSession(path);
    final var entity = new TaskEntity();
    entity.setFile("E:/snail/tmp/pick/");
    entity.setType(Type.TORRENT);
    entity.setName("acgist");
    entity.setStatus(Status.AWAIT);
    final List<String> list = new ArrayList<>();
    session.torrent().getInfo().files().stream().filter(TorrentFile::notPaddingFile).forEach(file -> {
        file.selected(true);
        list.add(file.path());
    });
    entity.setDescription(DescriptionWrapper.newEncoder(list).serialize());
    session.upload(TaskSession.newInstance(entity));
    final var group = session.torrentStreamGroup();
    final BitSet peerPieces = new BitSet();
    peerPieces.set(0, session.torrent().getInfo().pieceSize(), true);
    final BitSet suggestPieces = new BitSet();
    this.cost();
    TorrentPiece index;
    final Set<Integer> indexSet = new HashSet<Integer>();
    while ((index = group.pick(peerPieces, suggestPieces)) != null) {
        this.log(index);
        group.done(index.getIndex());
        indexSet.add(index.getIndex());
    }
    assertEquals(session.torrent().getInfo().pieceSize(), indexSet.size());
    this.costed();
}
Also used : TaskEntity(com.acgist.snail.pojo.entity.TaskEntity) ArrayList(java.util.ArrayList) BitSet(java.util.BitSet) TorrentPiece(com.acgist.snail.pojo.bean.TorrentPiece) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test)

Aggregations

TorrentPiece (com.acgist.snail.pojo.bean.TorrentPiece)1 TaskEntity (com.acgist.snail.pojo.entity.TaskEntity)1 ArrayList (java.util.ArrayList)1 BitSet (java.util.BitSet)1 HashSet (java.util.HashSet)1 Test (org.junit.jupiter.api.Test)1