public async Task UploadMemPerfTestAsync_File_50GB()
        {
            var startMemory = Process.GetCurrentProcess().PeakWorkingSet64;

            CloudFileShare share = GetRandomShareReference();
            string         path  = Path.GetTempFileName();

            try
            {
                await share.CreateAsync();

                using (var fs = new FileStream(path, FileMode.Create, FileAccess.Write, FileShare.None))
                {
                    fs.SetLength(50 * Constants.GB);
                }
                CloudFile file = share.GetRootDirectoryReference().GetFileReference(Path.GetFileName(path));
                await file.UploadFromFileAsync(
                    path,
                    default(AccessCondition),
                    new FileRequestOptions { UseTransactionalMD5 = true, ParallelOperationThreadCount = 1 },
                    default(OperationContext)
                    );
            }
            finally
            {
                System.IO.File.Delete(path);
                await share.DeleteIfExistsAsync();
            }

            Assert.IsTrue(Process.GetCurrentProcess().PeakWorkingSet64 - startMemory < 128 * Constants.MB, "Memory usage high");
        }
Exemplo n.º 2
0
        public async Task CloudFileUploadDownloadFileAsyncWithFailures()
        {
            CloudFile file     = this.testShare.GetRootDirectoryReference().GetFileReference("file1");
            CloudFile nullFile = this.testShare.GetRootDirectoryReference().GetFileReference("null");

            await this.DoUploadDownloadFileAsync(file, 0);

            await this.DoUploadDownloadFileAsync(file, 4096);

            await TestHelper.ExpectedExceptionAsync <IOException>(
                async() => await file.UploadFromFileAsync("non_existentCloudFileUploadDownloadFileAsyncWithFailures.file"),
                "UploadFromFile requires an existing file");

            await TestHelper.ExpectedExceptionAsync <StorageException>(
                async() => await nullFile.DownloadToFileAsync("garbageCloudFileUploadDownloadFileAsyncWithFailures.file", FileMode.Create),
                "DownloadToFile should not leave an empty file behind after failing.");

            Assert.IsFalse(System.IO.File.Exists("garbageCloudFileUploadDownloadFileAsyncWithFailures.file"));

            await TestHelper.ExpectedExceptionAsync <StorageException>(
                async() => await nullFile.DownloadToFileAsync("garbageCloudFileUploadDownloadFileAsyncWithFailures.file", FileMode.CreateNew),
                "DownloadToFile should not leave an empty file behind after failing.");

            Assert.IsFalse(System.IO.File.Exists("garbageCloudFileUploadDownloadFileAsyncWithFailures.file"));

            byte[] buffer = GetRandomBuffer(100);
            using (FileStream systemFile = new FileStream("garbageCloudFileUploadDownloadFileAsyncWithFailures.file", FileMode.Create, FileAccess.Write))
            {
                systemFile.Write(buffer, 0, buffer.Length);
            }
            await TestHelper.ExpectedExceptionAsync <IOException>(
                async() => await nullFile.DownloadToFileAsync("garbageCloudFileUploadDownloadFileAsyncWithFailures.file", FileMode.CreateNew),
                "DownloadToFileAsync should leave an empty file behind after failing, depending on the mode.");

            Assert.IsTrue(System.IO.File.Exists("garbageCloudFileUploadDownloadFileAsyncWithFailures.file"));
            System.IO.File.Delete("garbageCloudFileUploadDownloadFileAsyncWithFailures.file");

            await TestHelper.ExpectedExceptionAsync <StorageException>(
                async() => await nullFile.DownloadToFileAsync("garbageCloudFileUploadDownloadFileAsyncWithFailures.file", FileMode.Append),
                "DownloadToFile should leave an empty file behind after failing depending on file mode.");

            Assert.IsTrue(System.IO.File.Exists("garbageCloudFileUploadDownloadFileAsyncWithFailures.file"));
            System.IO.File.Delete("garbageCloudFileUploadDownloadFileAsyncWithFailures.file");
        }
Exemplo n.º 3
0
        private async Task DoUploadDownloadFileAsync(CloudFile file, int fileSize)
        {
#if NETCORE
            string inputFileName  = Path.GetTempFileName();
            string outputFileName = Path.GetTempFileName();
            if (System.IO.File.Exists(outputFileName))
            {
                System.IO.File.Delete(outputFileName);
            }
            try
            {
                byte[] buffer = GetRandomBuffer(fileSize);
                using (FileStream localFile = new FileStream(inputFileName, FileMode.Create, FileAccess.Write))
                {
                    await localFile.WriteAsync(buffer, 0, buffer.Length);
                }

#if !FACADE_NETCORE
                await file.UploadFromFileAsync(inputFileName);

                OperationContext context = new OperationContext();
                await file.UploadFromFileAsync(inputFileName, null, null, context);

                Assert.IsNotNull(context.LastResult.ServiceRequestID);

                context = new OperationContext();
                await file.DownloadToFileAsync(outputFileName, FileMode.CreateNew, null, null, context);

                Assert.IsNotNull(context.LastResult.ServiceRequestID);
#endif
                using (FileStream inputFile = new FileStream(inputFileName, FileMode.Open, FileAccess.Read),
                       outputFile = new FileStream(outputFileName, FileMode.Open, FileAccess.Read))
                {
                    TestHelper.AssertStreamsAreEqual(inputFile, outputFile);
                }
            }
            finally
            {
                System.IO.File.Delete(inputFileName);
                System.IO.File.Delete(outputFileName);
            }
#else
            StorageFolder tempFolder = ApplicationData.Current.TemporaryFolder;
            StorageFile   inputFile  = await tempFolder.CreateFileAsync("input.file", CreationCollisionOption.GenerateUniqueName);

            StorageFile outputFile = await tempFolder.CreateFileAsync("output.file", CreationCollisionOption.GenerateUniqueName);

            try
            {
                byte[] buffer = GetRandomBuffer(fileSize);
                using (Stream localFile = await inputFile.OpenStreamForWriteAsync())
                {
                    await localFile.WriteAsync(buffer, 0, buffer.Length);
                }

                await file.UploadFromFileAsync(inputFile);

                OperationContext context = new OperationContext();
                await file.UploadFromFileAsync(inputFile, null, null, context);

                Assert.IsNotNull(context.LastResult.ServiceRequestID);

                context = new OperationContext();
                await file.DownloadToFileAsync(outputFile, null, null, context);

                Assert.IsNotNull(context.LastResult.ServiceRequestID);

                using (Stream inputFileStream = await inputFile.OpenStreamForReadAsync(),
                       outputFileStream = await outputFile.OpenStreamForReadAsync())
                {
                    TestHelper.AssertStreamsAreEqual(inputFileStream, outputFileStream);
                }
            }
            finally
            {
                inputFile.DeleteAsync().AsTask().Wait();
                outputFile.DeleteAsync().AsTask().Wait();
            }
#endif
        }