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();
}
Aggregations