public void GivenWrongLengthWillNotFixIfTurnedOff()
        {
            string newFile    = DownloadTests.SafePath("testing.test");
            var    parameters = new LargeFileDownloadParameters(new Uri(Constants.ONE_GIG_FILE_S_SL), newFile, 1, verifyLength: false);

            Assert.AreEqual(1, parameters.FileSize);
        }
        public void SparseFileIsCreatedOnWindows()
        {
            string newFile = DownloadTests.SafePath("testing.test");

            try
            {
                var timer = new Stopwatch();
                timer.Start();
                var parameters = new LargeFileDownloadParameters(new Uri(Constants.ONE_GIG_FILE_S_SL), newFile,
                                                                 Constants.ONE_GIG_FILE_LENGTH);
                Stream s = parameters.GetOutputStream();
                //write to the end of the file
                s.Seek((Constants.ONE_GIG_FILE_LENGTH) - 100, SeekOrigin.Begin);
                var    encoding = new System.Text.ASCIIEncoding();
                Byte[] bytes    = encoding.GetBytes("hello");
                s.Write(bytes, 0, bytes.Length);
                s.Close();

                var info = new FileInfo(newFile);
                timer.Stop();
                //we should've pre-allocated file length
                Assert.AreEqual(info.Length, Constants.ONE_GIG_FILE_LENGTH);
                Assert.True(timer.ElapsedMilliseconds < 1500);      //should happen in less than a second since it's sparse
            }
            finally
            {
                File.Delete(newFile);
            }
        }
        public void GivenWrongLengthWillFix()
        {
            string newFile    = DownloadTests.SafePath("testing.test");
            var    parameters = new LargeFileDownloadParameters(new Uri(Constants.ONE_GIG_FILE_S_SL), newFile, 1);

            Assert.AreEqual(Constants.ONE_GIG_FILE_LENGTH, parameters.FileSize);
        }
Beispiel #4
0
        public void DownloadSmallFilesWithNonOptimizedStream(int threadCount)
        {
            var             uri    = new Uri(Constants.TWENTY_MEG_FILE);
            var             path   = DownloadTests.SafePath("sites_vcf.gz");
            Action <string> logger = (message) => { };
            var             timer  = new Stopwatch();

            timer.Start();
            var manager = new BufferManager(new[] { new BufferQueueSetting(SimpleHttpGetByRangeClient.BUFFER_SIZE, (uint)threadCount), new BufferQueueSetting(LargeFileDownloadParameters.DEFAULT_MAX_CHUNK_SIZE) });

            LargeFileDownloadParameters.EnsureCleanFile(path, true);
            using (var stream = new FileStream(path, FileMode.OpenOrCreate))
            {
                ILargeFileDownloadParameters parameters = new LargeFileDownloadWithStreamParameters(uri, stream,
                                                                                                    Constants.TWENTY_MEG_FILE_LENGTH,
                                                                                                    maxThreads:
                                                                                                    threadCount);
                Task task = parameters.DownloadAsync(logger: logger, bufferManager: manager);
                task.Wait(TimeSpan.FromMinutes(5));
                timer.Stop();

                Debug.WriteLine("Took {0} threads {1} ms", threadCount, timer.ElapsedMilliseconds);
                //try to open the file
                DownloadTests.ValidateGZip(path, parameters.FileSize, Constants.TWENTY_CHECKSUM);
            }
        }
Beispiel #5
0
        public void CanReadTheWholeFile()
        {
            var stream = new SeekableNetworkStream(Constants.TWENTY_MEG_FILE);

            byte[] source = new byte[stream.Length];
            stream.Read(source, 0, (int)stream.Length);
            string tempFile = Path.GetTempFileName();

            try
            {
                File.WriteAllBytes(tempFile, source);
                string checkSum = DownloadTests.Md5SumByProcess(tempFile);
                Assert.True(checkSum == Constants.TWENTY_CHECKSUM);
            }
            finally
            {
                File.Delete(tempFile);
            }
        }