public async Task CreateStreamTwice ()
 {
     var provider = new StreamProvider (Engine, "testDir", Torrent);
     await provider.StartAsync ();
     using var stream = await provider.CreateStreamAsync (provider.Files[0], false, CancellationToken.None);
     Assert.ThrowsAsync<InvalidOperationException> (() => provider.CreateStreamAsync (provider.Files[0], false, CancellationToken.None));
 }
 public async Task StopNormally ()
 {
     var provider = new StreamProvider (Engine, "testDir", Torrent);
     await provider.StartAsync ();
     await provider.StopAsync ();
     Assert.IsEmpty (Engine.Torrents);
 }
 public async Task StartNormally ()
 {
     var provider = new StreamProvider (Engine, "testDir", Torrent);
     Assert.IsEmpty (Engine.Torrents);
     await provider.StartAsync ();
     CollectionAssert.Contains (Engine.Torrents, provider.Manager);
 }
 public async Task StopTwice ()
 {
     var provider = new StreamProvider (Engine, "testDir", Torrent);
     await provider.StartAsync ();
     await provider.StopAsync ();
     Assert.ThrowsAsync<InvalidOperationException> (() => provider.StopAsync ());
 }
 public async Task UsesStreamingPicker ()
 {
     var provider = new StreamProvider (Engine, "testDir", Torrent);
     Assert.IsInstanceOf<StreamingPiecePicker> (provider.Manager.PieceManager.Picker.BasePicker.BasePicker.BasePicker);
     await provider.StartAsync ();
     Assert.IsInstanceOf<StreamingPiecePicker> (provider.Manager.PieceManager.Picker.BasePicker.BasePicker.BasePicker);
 }
 public async Task SeekPastEnd ()
 {
     var provider = new StreamProvider (Engine, "testDir", Torrent);
     await provider.StartAsync ();
     using var stream = await provider.CreateStreamAsync (provider.Files[0], prebuffer: false, CancellationToken.None).WithTimeout ();
     stream.Seek (stream.Length + 100, SeekOrigin.Begin);
     Assert.AreEqual (stream.Length, stream.Position);
 }
 public async Task ReadPastEndOfStream ()
 {
     var provider = new StreamProvider (Engine, "testDir", Torrent);
     await provider.StartAsync ();
     using var stream = await provider.CreateStreamAsync (provider.Files[0], prebuffer: false, CancellationToken.None).WithTimeout ();
     stream.Seek (0, SeekOrigin.End);
     Assert.AreEqual (0, await stream.ReadAsync (new byte[1], 0, 1).WithTimeout ());
 }
        public async Task DownloadMagnetLink ()
        {
            var provider = new StreamProvider (Engine, "testDir", MagnetLink, "magnetLinkDir");
            Assert.IsNull (provider.Files);

            await provider.StartAsync ();
            CollectionAssert.Contains (Engine.Torrents, provider.Manager);
        }
 public async Task Pause ()
 {
     var provider = new StreamProvider (Engine, "testDir", Torrent);
     await provider.StartAsync ();
     await provider.PauseAsync ();
     Assert.IsTrue (provider.Active);
     Assert.IsTrue (provider.Paused);
 }
 public async Task CreateStream ()
 {
     var provider = new StreamProvider (Engine, "testDir", Torrent);
     await provider.StartAsync ();
     using var stream = await provider.CreateStreamAsync (provider.Files[0], prebuffer: false, CancellationToken.None);
     Assert.IsNotNull (stream);
     Assert.AreEqual (0, stream.Position);
     Assert.AreEqual (provider.Files[0].Length, stream.Length);
 }
Exemple #11
0
        public async Task UsesStreamingPicker()
        {
            var provider = new StreamProvider(Engine, "testDir", Torrent);
            // FIXME: Reinstate this API in some form!
            //Assert.IsInstanceOf<StreamingPiecePicker> (provider.Manager.PieceManager.Picker.BasePicker.BasePicker.BasePicker);
            await provider.StartAsync();

            //Assert.IsInstanceOf<StreamingPiecePicker> (provider.Manager.PieceManager.Picker.BasePicker.BasePicker.BasePicker);
        }
        public async Task CreateStream()
        {
            var provider = new StreamProvider(Engine, "testDir", Torrent);
            await provider.StartAsync();

            using var stream = await provider.CreateStreamAsync(provider.Files[0], false, CancellationToken.None);

            Assert.IsNotNull(stream);
        }
        public async Task WaitForMetadata_Cancellation ()
        {
            var provider = new StreamProvider (Engine, "testDir", MagnetLink, "magnetDir");
            await provider.StartAsync ();

            var metadataTask = provider.WaitForMetadataAsync ();
            await provider.StopAsync ();
            Assert.ThrowsAsync<TaskCanceledException> (() => metadataTask);
        }
        public async Task StartManagerManually ()
        {
            var provider = new StreamProvider (Engine, "testDir", Torrent);
            // It hasn't been registered with the engine
            Assert.ThrowsAsync<TorrentException> (() => provider.Manager.StartAsync ());
            await Engine.Register (provider.Manager);
            await provider.Manager.StartAsync ();

            // People should not register and start the manager manually.
            Assert.ThrowsAsync<InvalidOperationException> (() => provider.StartAsync ());
        }
        public async Task CreateStream_Prebuffer ()
        {
            var provider = new StreamProvider (Engine, "testDir", Torrent);
            await provider.StartAsync ();
            await provider.Manager.WaitForState (TorrentState.Downloading);
            provider.Manager.Bitfield.SetAll (true); // should not be allowed by public API.

            using var stream = await provider.CreateStreamAsync (provider.Files[0], prebuffer: true, CancellationToken.None);
            Assert.IsNotNull (stream);
            Assert.AreEqual (0, stream.Position);
            Assert.AreEqual (provider.Files[0].Length, stream.Length);
        }
 public void DownloadMagnetLink_CachedTorrent ()
 {
     var metadataCacheDir = Path.Combine (Path.GetTempPath (), "magnetLinkDir");
     var filePath = Path.Combine (metadataCacheDir, $"{MagnetLink.InfoHash.ToHex()}.torrent");
     Directory.CreateDirectory (metadataCacheDir);
     try {
         File.WriteAllBytes (filePath, torrentInfo.Encode ());
         var provider = new StreamProvider (Engine, "testDir", MagnetLink, metadataCacheDir);
         Assert.IsNotNull (provider.Files);
     } finally {
         Directory.Delete (metadataCacheDir, true);
     }
 }
        public async Task ReadLastByte ()
        {
            var provider = new StreamProvider (Engine, "testDir", Torrent);
            await provider.StartAsync ();
            await provider.Manager.WaitForState (TorrentState.Downloading).WithTimeout ();
            provider.Manager.Bitfield.SetAll (true); // the public API shouldn't allow this.

            using var stream = await provider.CreateStreamAsync (provider.Files[0], prebuffer: false, CancellationToken.None).WithTimeout ();
            stream.Seek (1, SeekOrigin.End);
            Assert.AreEqual (1, await stream.ReadAsync (new byte[1], 0, 1).WithTimeout ());

            stream.Seek (1, SeekOrigin.End);
            Assert.AreEqual (1, await stream.ReadAsync (new byte[5], 0, 5).WithTimeout ());
        }
 public void DownloadMagnetLink_IncorrectCachedTorrent ()
 {
     var magnetLinkOtherInfoHash = new MagnetLink (new InfoHash (new byte[20]), "OtherHash");
     var metadataCacheDir = Path.Combine (Path.GetTempPath (), "magnetLinkDir");
     var filePath = Path.Combine (metadataCacheDir, $"{magnetLinkOtherInfoHash.InfoHash.ToHex ()}.torrent");
     Directory.CreateDirectory (metadataCacheDir);
     try {
         // Write the data for one info hash into a torrent for another info hash.
         File.WriteAllBytes (filePath, torrentInfo.Encode ());
         var provider = new StreamProvider (Engine, "testDir", magnetLinkOtherInfoHash, metadataCacheDir);
         Assert.IsNull (provider.Files);
     } finally {
         Directory.Delete (metadataCacheDir, true);
     }
 }
Exemple #19
0
        public async Task SeekToMiddle()
        {
            var provider = new StreamProvider(Engine, "testDir", Torrent);

            await provider.StartAsync();

            await provider.Manager.WaitForState(TorrentState.Downloading);

            provider.Manager.Bitfield.SetAll(true);  // should not be allowed by public API.

            using var stream = await provider.CreateStreamAsync(provider.Files[0], prebuffer : false, CancellationToken.None);

            stream.Seek(12345, SeekOrigin.Begin);
            Assert.AreEqual(provider.Manager.ByteOffsetToPieceIndex(12345), provider.Requester.HighPriorityPieceIndex);
        }
 public void CreateStreamBeforeStart ()
 {
     var provider = new StreamProvider (Engine, "testDir", Torrent);
     Assert.ThrowsAsync<InvalidOperationException> (() => provider.CreateHttpStreamAsync (provider.Files[0]));
 }
 public void PauseWithoutStarting ()
 {
     var provider = new StreamProvider (Engine, "testDir", Torrent);
     Assert.ThrowsAsync<InvalidOperationException> (() => provider.PauseAsync ());
 }