Beispiel #1
0
        public void IdIsAssignedWhenNotSupplied()
        {
            var parameters = new LargeFileDownloadWithStreamParameters(new Uri("http://blah.com"), new MemoryStream(), 20, verifyLength: false, maxChunkSize: 1);

            Assert.NotNull(parameters.Id);
            Assert.True(parameters.Id.Length > 10);
        }
        public void DownloadSmallerFileWriteToStream()
        {
            //8 threads
            //MaxChunkSize = 1048576
            //FileSize = 5242880

            var             uri    = new Uri(Constants.FIVE_MEG_FILE);
            var             path   = SafePath("sites_vcf.gz");
            Action <string> logger = (message) => { };
            var             timer  = new Stopwatch();

            timer.Start();
            using (var fs = new FileStream(path, FileMode.OpenOrCreate))
            {
                ILargeFileDownloadParameters parameters = new LargeFileDownloadWithStreamParameters(uri, fs, 1048576,
                                                                                                    maxThreads: 8);
                Task task = parameters.DownloadAsync(logger: logger);
                task.Wait(TimeSpan.FromMinutes(1));
                timer.Stop();
                Debug.WriteLine("Took {0} threads {1} ms", 8, timer.ElapsedMilliseconds);

                //try to open the file
                ValidateGZip(path, parameters.FileSize, Constants.FIVE_MEG_CHECKSUM);
            }
        }
Beispiel #3
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);
            }
        }
        public DownloadFileCommand(BaseSpaceClient client, string fileId, Stream stream, IClientSettings settings, CancellationToken token = new CancellationToken(), IWebProxy proxy = null, bool enableLogging = true)
        {
            DateTime expiration;
            string   url = GetFileContentUrl(client, fileId, out expiration);

#pragma warning disable 618
            ILargeFileDownloadParameters parameters = new LargeFileDownloadWithStreamParameters(new Uri(url), stream, 0, id: fileId, maxThreads: DEFAULT_THREADS, maxChunkSize: (int)settings.FileDownloadMultipartSizeThreshold, autoCloseStream: false, verifyLength: true);
#pragma warning restore 618
            _parameters    = parameters;
            _token         = token;
            _proxy         = proxy;
            _enableLogging = enableLogging;
        }
        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 #6
0
        public void MaxChunkSizeCalculation(int fileSize, int chunkSize, int expected)
        {
            var parameters = new LargeFileDownloadWithStreamParameters(new Uri("http://blah.com"), new MemoryStream(), fileSize, verifyLength: false, maxChunkSize: chunkSize);

            Assert.AreEqual(expected, parameters.MaxChunkSize);
        }
 public void MaxChunkSizeCalculation(int fileSize, int chunkSize, int expected)
 {
     var parameters = new LargeFileDownloadWithStreamParameters(new Uri("http://blah.com"),new MemoryStream(),fileSize,verifyLength:false,maxChunkSize:chunkSize);
     Assert.AreEqual(expected, parameters.MaxChunkSize);
 }
 public void IdIsAssignedWhenSupplied()
 {
     var parameters = new LargeFileDownloadWithStreamParameters(new Uri("http://blah.com"), new MemoryStream(), 20, verifyLength: false, maxChunkSize: 1, id: "test");
     Assert.True(parameters.Id == "test");
 }
        public void DownloadSmallerFileWriteToStream()
        {
            //8 threads
            //MaxChunkSize = 1048576
            //FileSize = 5242880

            var uri = new Uri(Constants.FIVE_MEG_FILE);
            var path = SafePath("sites_vcf.gz");
            Action<string> logger = (message) => { };
            var timer = new Stopwatch();
            timer.Start();
            using (var fs = new FileStream(path, FileMode.OpenOrCreate))
            {
                ILargeFileDownloadParameters parameters = new LargeFileDownloadWithStreamParameters(uri,fs , 1048576,
                                                                                                    maxThreads: 8);
                Task task = parameters.DownloadAsync(logger: logger);
                task.Wait(TimeSpan.FromMinutes(1));
                timer.Stop();
                Debug.WriteLine("Took {0} threads {1} ms", 8, timer.ElapsedMilliseconds);

            //try to open the file
            ValidateGZip(path, parameters.FileSize, Constants.FIVE_MEG_CHECKSUM);
                 }
        }