Ejemplo n.º 1
0
        public async Task StartTwice()
        {
            var provider = new StreamProvider(Engine, "testDir", Torrent);
            await provider.StartAsync();

            Assert.ThrowsAsync <InvalidOperationException> (() => provider.StartAsync());
        }
Ejemplo n.º 2
0
 public async Task StartNormally ()
 {
     var provider = new StreamProvider (Engine, "testDir", Torrent);
     Assert.IsEmpty (Engine.Torrents);
     await provider.StartAsync ();
     CollectionAssert.Contains (Engine.Torrents, provider.Manager);
 }
Ejemplo n.º 3
0
 public async Task StopNormally ()
 {
     var provider = new StreamProvider (Engine, "testDir", Torrent);
     await provider.StartAsync ();
     await provider.StopAsync ();
     Assert.IsEmpty (Engine.Torrents);
 }
Ejemplo n.º 4
0
 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);
 }
Ejemplo n.º 5
0
 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));
 }
Ejemplo n.º 6
0
 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 ());
 }
Ejemplo n.º 7
0
 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);
 }
Ejemplo n.º 8
0
        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);
        }
Ejemplo n.º 9
0
 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], false, CancellationToken.None);

            Assert.IsNotNull(stream);
        }
Ejemplo n.º 11
0
        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);
        }
Ejemplo n.º 12
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);
        }
Ejemplo n.º 13
0
 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);
 }
Ejemplo n.º 14
0
        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 ());
        }
Ejemplo n.º 15
0
        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);
        }
Ejemplo n.º 16
0
        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 ());
        }
Ejemplo n.º 17
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);
        }