public void PickHighestPriority() { var data = CreateTorrentInfo(); ReadOnlyBitField ignoringBitfield = new BitField(data.TorrentInfo.PieceCount()) .SetAll(false); var requester = new StreamingPieceRequester(); requester.Initialise(data, new[] { ignoringBitfield }); requester.SeekToPosition(data.Files[0], data.TorrentInfo.PieceLength * 3); var peer = PeerId.CreateNull(ignoringBitfield.Length, true, false, true); requester.AddRequests(peer, Array.Empty <IPeerWithMessaging> ()); Assert.AreEqual(4, peer.AmRequestingPiecesCount); var requests = peer.Requests; Assert.AreEqual(4, requests.Count); Assert.IsTrue(requests.All(r => r.PieceIndex == 3)); }
public void PickFromBeforeHighPrioritySet() { var data = new TorrentData(); var ignoringBitfield = new MutableBitField(data.PieceCount()) .SetAll(true) .Set(0, false); var requester = new StreamingPieceRequester(); requester.Initialise(data, new[] { ignoringBitfield }); requester.SeekToPosition(data.Files[0], data.PieceLength * 3); var peer = PeerId.CreateNull(ignoringBitfield.Length, true, false, true); requester.AddRequests(peer, Array.Empty <IPeerWithMessaging> ()); Assert.AreEqual(2, peer.AmRequestingPiecesCount); var requests = peer.Requests; Assert.AreEqual(2, requests.Count); Assert.IsTrue(requests.All(r => r.PieceIndex == 0)); }