public void PipelineMultipleShareNamesToRemoveTest()
        {
            // TODO: Generate more random names for file shares after the
            // naming rules is settled down.
            int numberOfShares = this.randomProvider.Next(2, 33);

            string[] names = Enumerable.Range(0, numberOfShares)
                             .Select(i => CloudFileUtil.GenerateUniqueFileShareName()).ToArray();
            foreach (var name in names)
            {
                fileUtil.EnsureFileShareExists(name);
            }

            try
            {
                CommandAgent.RemoveFileShareFromPipeline();
                var result = CommandAgent.Invoke(names);

                CommandAgent.AssertNoError();
                result.AssertNoResult();
            }
            finally
            {
                foreach (string fileShareName in names)
                {
                    fileUtil.DeleteFileShareIfExists(fileShareName);
                }
            }
        }
Ejemplo n.º 2
0
 private static IEnumerable <string> BuildShareNamesByPrefix(string prefix, int numberOfShares)
 {
     for (int i = 0; i < numberOfShares; i++)
     {
         yield return(string.Concat(prefix, CloudFileUtil.GenerateUniqueFileShareName()));
     }
 }
Ejemplo n.º 3
0
        public void GetShareSnapshot_ExistTime()
        {
            string shareName = CloudFileUtil.GenerateUniqueFileShareName();

            try
            {
                CloudFileShare share          = fileUtil.EnsureFileShareExists(shareName);
                CloudFileShare shareSnapshot1 = share.Snapshot();


                CommandAgent.GetFileShareByName(shareName, shareSnapshot1.SnapshotTime.Value);
                var result = CommandAgent.Invoke();
                result.AssertObjectCollection(obj => result.AssertCloudFileContainer(obj, shareName, snapshotTime: shareSnapshot1.SnapshotTime.Value), 1);
            }
            finally
            {
                try
                {
                    fileUtil.DeleteFileShareIfExists(shareName);
                }
                catch (Exception e)
                {
                    Test.Warn("Unexpected exception when cleanup file share {0}: {1}", shareName, e);
                }
            }
        }
Ejemplo n.º 4
0
        public void GetShareSnapshot_CheckIncludeSnapshot()
        {
            string shareName = CloudFileUtil.GenerateUniqueFileShareName();
            string fileName  = CloudFileUtil.GenerateUniqueFileName();

            try
            {
                CloudFileShare share          = fileUtil.EnsureFileShareExists(shareName);
                CloudFileShare shareSnapshot1 = share.Snapshot();
                fileUtil.CreateFile(share, fileName);
                CloudFileShare shareSnapshot2 = share.Snapshot();

                CommandAgent.GetFileShareByName("");
                var result = CommandAgent.Invoke();

                List <DateTimeOffset> snapshotTimes = new List <DateTimeOffset>();
                snapshotTimes.Add(shareSnapshot1.SnapshotTime.Value);
                snapshotTimes.Add(shareSnapshot2.SnapshotTime.Value);

                result.AssertCloudFileContainersExist(shareName, snapshotTimes);
            }
            finally
            {
                try
                {
                    fileUtil.DeleteFileShareIfExists(shareName);
                }
                catch (Exception e)
                {
                    Test.Warn("Unexpected exception when cleanup file share {0}: {1}", shareName, e);
                }
            }
        }
Ejemplo n.º 5
0
        public void GetShareSnapshot_notExistTime()
        {
            string shareName = CloudFileUtil.GenerateUniqueFileShareName();

            try
            {
                CloudFileShare share          = fileUtil.EnsureFileShareExists(shareName);
                CloudFileShare shareSnapshot1 = share.Snapshot();

                CommandAgent.GetFileShareByName(shareName, DateTime.Now.AddDays(-1));
                var result = CommandAgent.Invoke();


                CommandAgent.AssertErrors(record => record.AssertError(AssertUtil.ResourceNotFoundFullQualifiedErrorId));
                result.AssertNoResult();
            }
            finally
            {
                try
                {
                    fileUtil.DeleteFileShareIfExists(shareName);
                }
                catch (Exception e)
                {
                    Test.Warn("Unexpected exception when cleanup file share {0}: {1}", shareName, e);
                }
            }
        }
Ejemplo n.º 6
0
        public void GetFileShareUsageTest()
        {
            string fileShareName = CloudFileUtil.GenerateUniqueFileShareName();
            string cloudFileName = CloudFileUtil.GenerateUniqueFileName();
            var    fileShare     = fileUtil.EnsureFileShareExists(fileShareName);

            try
            {
                CommandAgent.GetFileShareByName(fileShareName);

                var result = CommandAgent.Invoke();

                CommandAgent.AssertNoError();
                result.AssertObjectCollection(obj => result.AssertCloudFileContainer(obj, fileShareName), 1);

                fileUtil.CreateFile(fileShare.GetRootDirectoryReference(), cloudFileName);

                CommandAgent.Clear();
                CommandAgent.GetFileShareByName(fileShareName);

                result = CommandAgent.Invoke();
                CommandAgent.AssertNoError();
                result.AssertObjectCollection(obj => result.AssertCloudFileContainer(obj, fileShareName, 1), 1);
            }
            finally
            {
                fileUtil.DeleteFileShareIfExists(fileShareName);
            }
        }
Ejemplo n.º 7
0
        public void GetShareByPrefixUsingWildCardTest()
        {
            string shareName = string.Concat("*", CloudFileUtil.GenerateUniqueFileShareName());

            CommandAgent.GetFileShareByPrefix(shareName);
            CommandAgent.Invoke();
            CommandAgent.AssertErrors(err => err.AssertError(AssertUtil.InvalidArgumentFullQualifiedErrorId));
        }
        public void RemoveDirectoryUnderNonExistingShareTest()
        {
            string shareName = CloudFileUtil.GenerateUniqueFileShareName();
            string dir       = CloudFileUtil.GenerateUniqueDirectoryName();

            fileUtil.DeleteFileShareIfExists(shareName);
            CommandAgent.RemoveDirectory(shareName, dir);
            var result = CommandAgent.Invoke();

            CommandAgent.AssertErrors(record => record.AssertError(AssertUtil.ShareNotFoundFullQualifiedErrorId));
        }
        public void CreateDirectoryUnderNonExistingFileShareTest()
        {
            string nonExistingFileShareName = CloudFileUtil.GenerateUniqueFileShareName();

            fileUtil.DeleteFileShareIfExists(nonExistingFileShareName);
            string dirName = CloudFileUtil.GenerateUniqueDirectoryName();

            CommandAgent.NewDirectory(nonExistingFileShareName, dirName);
            var result = CommandAgent.Invoke();

            CommandAgent.AssertErrors(err => err.AssertError(AssertUtil.ShareNotFoundFullQualifiedErrorId));
        }
Ejemplo n.º 10
0
        public void GetNonExistingShareTest()
        {
            string shareName = CloudFileUtil.GenerateUniqueFileShareName();

            fileUtil.DeleteFileShareIfExists(shareName);
            CommandAgent.GetFileShareByName(shareName);
            CommandAgent.Invoke();
            CommandAgent.AssertErrors(err => err.AssertError(
                                          AssertUtil.ResourceNotFoundFullQualifiedErrorId,
                                          AssertUtil.ShareNotFoundFullQualifiedErrorId,
                                          AssertUtil.ShareBeingDeletedFullQualifiedErrorId));
        }
        public void CreateDirectoryUnderNonExistingShare()
        {
            string shareName = CloudFileUtil.GenerateUniqueFileShareName();
            string dirName   = CloudFileUtil.GenerateUniqueDirectoryName();

            fileUtil.DeleteFileShareIfExists(shareName);
            this.CreateDirectoryInternal(
                () => CommandAgent.NewDirectory(shareName, dirName),
                dirName,
                false);
            CommandAgent.AssertErrors(err => err.AssertError(AssertUtil.ShareNotFoundFullQualifiedErrorId));
        }
Ejemplo n.º 12
0
        public void CreateAlreadyExistsShareTest()
        {
            string shareName = CloudFileUtil.GenerateUniqueFileShareName();

            fileUtil.EnsureFileShareExists(shareName);
            this.CreateShareInternal(
                () => shareName,
                (results, fileShareName) =>
            {
                CommandAgent.AssertErrors(err => err.AssertError(AssertUtil.ShareAlreadyExistsFullQualifiedErrorId));
            },
                false);
        }
Ejemplo n.º 13
0
        public void DownloadingFromNonExistingFileShare()
        {
            string fileShareName = CloudFileUtil.GenerateUniqueFileShareName();

            fileUtil.DeleteFileShareIfExists(fileShareName);

            string cloudFileName = CloudFileUtil.GenerateUniqueFileName();

            CommandAgent.DownloadFile(fileShareName, cloudFileName, Test.Data.Get("TempDir"), true);
            var result = CommandAgent.Invoke();

            CommandAgent.AssertErrors(err => err.AssertError(AssertUtil.InvalidOperationExceptionFullQualifiedErrorId, AssertUtil.PathNotFoundFullQualifiedErrorId, AssertUtil.ResourceNotFoundFullQualifiedErrorId));
        }
Ejemplo n.º 14
0
        public void CreateShareWhichHasJustBeenDeletd()
        {
            string shareName = CloudFileUtil.GenerateUniqueFileShareName();

            fileUtil.EnsureFileShareExists(shareName);
            fileUtil.DeleteFileShareIfExists(shareName);
            this.CreateShareInternal(
                () => shareName,
                (results, fileShareName) =>
            {
                CommandAgent.AssertErrors(err => err.AssertError(AssertUtil.ShareBeingDeletedFullQualifiedErrorId));
            },
                false);
        }
Ejemplo n.º 15
0
        public void GetFilesUsingInvalidFileShareObjectTest()
        {
            var invalidFileShareName = CloudFileUtil.GenerateUniqueFileShareName();

            fileUtil.DeleteFileShareIfExists(invalidFileShareName);

            CommandAgent.GetFile(fileUtil.Client.GetShareReference(invalidFileShareName));
            var result = CommandAgent.Invoke();

            CommandAgent.AssertErrors(err => err.AssertError(
                                          AssertUtil.ShareBeingDeletedFullQualifiedErrorId,
                                          AssertUtil.ShareNotFoundFullQualifiedErrorId,
                                          AssertUtil.ProtocolErrorFullQualifiedErrorId));
        }
        public void RemoveNonExistingFileShareTest()
        {
            string fileShareName = CloudFileUtil.GenerateUniqueFileShareName();

            fileUtil.DeleteFileShareIfExists(fileShareName);

            try
            {
                CommandAgent.RemoveFileShareByName(fileShareName);
                var result = CommandAgent.Invoke();
                CommandAgent.AssertErrors(record => record.AssertError(AssertUtil.ShareNotFoundFullQualifiedErrorId));
            }
            finally
            {
                fileUtil.DeleteFileShareIfExists(fileShareName);
            }
        }
Ejemplo n.º 17
0
        public void DownloadFileFromShareSnapshot_dir()
        {
            string shareName = CloudFileUtil.GenerateUniqueFileShareName();
            string dirName   = CloudFileUtil.GenerateUniqueDirectoryName();
            string fileName  = CloudFileUtil.GenerateUniqueFileName();

            try
            {
                CloudFileShare     share          = fileUtil.EnsureFileShareExists(shareName);
                CloudFileShare     shareSnapshot1 = share.Snapshot();
                CloudFileDirectory dir            = fileUtil.EnsureDirectoryExists(share, dirName);
                CloudFile          file           = fileUtil.CreateFile(dir, fileName);
                CloudFileShare     shareSnapshot2 = share.Snapshot();
                file.Delete();
                dir.Delete();

                //Get File content
                string StorageConnectionString = Test.Data.Get("StorageConnectionString");
                Test.Assert((CommandAgent as PowerShellAgent).InvokePSScript(string.Format(",(New-AzureStorageContext -ConnectionString \"{5}\" | Get-AzureStorageShare -Name {0} -SnapshotTime \"{1}\").GetRootDirectoryReference().GetDirectoryReference(\"{4}\") | Get-AzureStorageFileContent -Path {2} -Destination {3} -Force",
                                                                                           shareName,
                                                                                           shareSnapshot2.SnapshotTime.Value,
                                                                                           fileName,
                                                                                           fileName,
                                                                                           dirName,
                                                                                           StorageConnectionString)),
                            string.Format("Download File {0} from share snapshot {1}, {2} should success.", dirName + "\\" + fileName, shareName, shareSnapshot2.SnapshotTime.Value));

                //validate MD5
                CloudFile file2 = shareSnapshot2.GetRootDirectoryReference().GetDirectoryReference(dirName).GetFileReference(fileName);
                file2.FetchAttributes();
                Test.Assert(file2.Properties.ContentMD5 == FileUtil.GetFileContentMD5(fileName), "Expected MD5: {0}, real MD5: {1}", file2.Properties.ContentMD5, FileUtil.GetFileContentMD5(fileName));
            }
            finally
            {
                try
                {
                    fileUtil.DeleteFileShareIfExists(shareName);
                }
                catch (Exception e)
                {
                    Test.Warn("Unexpected exception when cleanup file share {0}: {1}", shareName, e);
                }
            }
        }
        public void RemoveEmptyFileShareTest()
        {
            string         fileShareName = CloudFileUtil.GenerateUniqueFileShareName();
            CloudFileShare share         = fileUtil.EnsureFileShareExists(fileShareName);

            try
            {
                CommandAgent.RemoveFileShareByName(fileShareName, confirm: true);
                var result = CommandAgent.Invoke();

                CommandAgent.AssertNoError();
                result.AssertNoResult();
                Test.Assert(!share.Exists(), "The share should be removed.");
            }
            finally
            {
                fileUtil.DeleteFileShareIfExists(fileShareName);
            }
        }
        public void RemoveFileShareWithSnapshotTest_NotSetIncludeAllSnapshot()
        {
            string         fileShareName  = CloudFileUtil.GenerateUniqueFileShareName();
            CloudFileShare share          = fileUtil.EnsureFileShareExists(fileShareName);
            CloudFileShare shareSnapshot1 = share.Snapshot();

            try
            {
                CommandAgent.RemoveFileShareByName(fileShareName, confirm: true, includeAllSnapshot: false);
                var result = CommandAgent.Invoke();

                CommandAgent.AssertErrors(record => record.AssertError("HostException"));
                Test.Assert(share.Exists(), "The share should not be removed.");
            }
            finally
            {
                fileUtil.DeleteFileShareIfExists(fileShareName);
            }
        }
        public void RemoveFileShareWithSnapshotTest_NotSetIncludeAllSnapshot_Force()
        {
            string         fileShareName  = CloudFileUtil.GenerateUniqueFileShareName();
            CloudFileShare share          = fileUtil.EnsureFileShareExists(fileShareName);
            CloudFileShare shareSnapshot1 = share.Snapshot();

            try
            {
                CommandAgent.RemoveFileShareByName(fileShareName, includeAllSnapshot: false);
                var result = CommandAgent.Invoke();

                CommandAgent.AssertNoError();
                result.AssertNoResult();
                Test.Assert(!share.Exists(), "The share should be removed.");
            }
            finally
            {
                fileUtil.DeleteFileShareIfExists(fileShareName);
            }
        }
        public void RemoveFileShareWithInvalidKeyValueTest()
        {
            string fileShareName = CloudFileUtil.GenerateUniqueFileShareName();

            fileUtil.EnsureFileShareExists(fileShareName);
            try
            {
                // Creates an storage context object with invalid key value
                var    invalidAccount = CloudFileUtil.MockupStorageAccount(StorageAccount, mockupAccountKey: true);
                object invalidStorageContextObject = CommandAgent.CreateStorageContextObject(invalidAccount.ToString(true));
                CommandAgent.RemoveFileShareByName(fileShareName, false, invalidStorageContextObject);
                var result = CommandAgent.Invoke();
                CommandAgent.AssertErrors(record => record.AssertError(AssertUtil.AuthenticationFailedFullQualifiedErrorId, AssertUtil.ProtocolErrorFullQualifiedErrorId));
                fileUtil.AssertFileShareExists(fileShareName, "File share should not be removed when providing invalid credentials.");
            }
            finally
            {
                fileUtil.DeleteFileShareIfExists(fileShareName);
            }
        }
Ejemplo n.º 22
0
        public void DownloadAFileUsingFileObjectWhichHasJustBeenDeletedTest()
        {
            var share = fileUtil.EnsureFileShareExists(CloudFileUtil.GenerateUniqueFileShareName());

            try
            {
                var file = fileUtil.CreateFile(share, CloudFileUtil.GenerateUniqueFileName());
                file.Delete();
                CommandAgent.DownloadFile(file, Test.Data.Get("TempDir"), true);
                var result = CommandAgent.Invoke();
                result.AssertNoResult();
                CommandAgent.AssertErrors(err => err.AssertError(AssertUtil.InvalidOperationExceptionFullQualifiedErrorId, AssertUtil.InvalidOperationExceptionFullQualifiedErrorId, AssertUtil.ResourceNotFoundFullQualifiedErrorId));
            }
            finally
            {
                if (share != null)
                {
                    share.DeleteIfExists();
                }
            }
        }
Ejemplo n.º 23
0
        public void CreateShareWhichHasBeenDeletedAndGCed()
        {
            const int CreateShareInterval   = 10000;
            const int CreateShareRetryLimit = 10;

            string fileShareName = CloudFileUtil.GenerateUniqueFileShareName();
            var    fileShare     = fileUtil.EnsureFileShareExists(fileShareName);

            // Delete the share first.
            fileShare.Delete();

            Stopwatch watch = Stopwatch.StartNew();

            // Try to create the share
            try
            {
                for (int i = 0; i < CreateShareRetryLimit; i++)
                {
                    Thread.Sleep(CreateShareInterval);
                    Test.Info("Try to create a share which has just been deleted. RetryCount = {0}", i);
                    CommandAgent.NewFileShare(fileShareName);
                    var result = CommandAgent.Invoke();
                    if (!CommandAgent.HadErrors)
                    {
                        Test.Info("Successfully created the file share at round {0}.", i);
                        return;
                    }

                    CommandAgent.AssertErrors(errorRecord => errorRecord.AssertError(AssertUtil.ShareBeingDeletedFullQualifiedErrorId));
                    CommandAgent.Clear();
                }

                Test.Error("Failed to create the file share within the given retry count {0}. Total time passed is {1}", CreateShareRetryLimit, watch.Elapsed);
            }
            finally
            {
                fileUtil.DeleteFileShareIfExists(fileShareName);
            }
        }
        public void RemoveFileShareWhileAFileIsUploading()
        {
            string fileShareName = CloudFileUtil.GenerateUniqueFileShareName();
            var    fileShare     = fileUtil.EnsureFileShareExists(fileShareName);

            var  stream     = new BlockReadUntilSetStream();
            Task uploadTask = null;

            try
            {
                string fileName = CloudFileUtil.GenerateUniqueFileName();
                var    file     = fileUtil.CreateFile(fileShare, fileName);

                // Creates a stream which would block the read operation.
                uploadTask = Task.Factory.StartNew(() => file.UploadFromStream(stream));
                CommandAgent.RemoveFileShareByName(fileShareName);
                var result = CommandAgent.Invoke();
                CommandAgent.AssertNoError();
            }
            finally
            {
                stream.StopBlockingReadOperation();
                if (uploadTask != null)
                {
                    try
                    {
                        uploadTask.Wait();
                    }
                    catch
                    {
                    }
                }

                stream.Dispose();
                fileUtil.DeleteFileShareIfExists(fileShareName);
            }
        }
Ejemplo n.º 25
0
        public void PipelineMultipleShareNamesTest()
        {
            // TODO: Generate more random names for file shares after the
            // naming rules is settled down.
            int numberOfShares = this.randomProvider.Next(2, 33);

            string[] names = Enumerable.Range(0, numberOfShares)
                             .Select(i => CloudFileUtil.GenerateUniqueFileShareName()).ToArray();

            var client = StorageAccount.CreateCloudFileClient();

            // Ensure all file shares are not exists
            for (int i = 0; i < names.Length; i++)
            {
                while (client.GetShareReference(names[i]).Exists())
                {
                    names[i] = CloudFileUtil.GenerateUniqueFileShareName();
                }
            }

            try
            {
                CommandAgent.NewFileShareFromPipeline();
                var result = CommandAgent.Invoke(names);

                CommandAgent.AssertNoError();
                result.AssertObjectCollection(obj => result.AssertCloudFileContainer(obj, new List <string>(names)), numberOfShares);
            }
            finally
            {
                foreach (string fileShareName in names)
                {
                    fileUtil.DeleteFileShareIfExists(fileShareName);
                }
            }
        }
Ejemplo n.º 26
0
 public override void OnTestSetup()
 {
     this.fileShare = fileUtil.EnsureFileShareExists(CloudFileUtil.GenerateUniqueFileShareName());
 }
Ejemplo n.º 27
0
        public void CreateAListOfSharesWhileSomeOfThemAlreadyExistsTest()
        {
            int           numberOfSharesToBeCreated = this.randomProvider.Next(5, 20);
            List <string> shareNames = Enumerable.Range(0, numberOfSharesToBeCreated).Select(x => CloudFileUtil.GenerateUniqueFileShareName()).ToList();
            int           numberOfSharesAlreadyExists = this.randomProvider.Next(1, numberOfSharesToBeCreated - 1);
            List <string> existingShareNames          = shareNames.RandomlySelect(numberOfSharesAlreadyExists, this.randomProvider).ToList();

            foreach (string shareName in shareNames)
            {
                if (fileUtil.FileShareExists(shareName) && (!existingShareNames.Contains(shareName)))
                {
                    existingShareNames.Add(shareName);
                }
            }

            try
            {
                foreach (string shareName in existingShareNames)
                {
                    fileUtil.EnsureFileShareExists(shareName);
                }

                CommandAgent.NewFileShareFromPipeline();
                var result = CommandAgent.Invoke(shareNames);
                CommandAgent.AssertErrors(
                    err => err.AssertError(AssertUtil.ShareAlreadyExistsFullQualifiedErrorId),
                    numberOfSharesAlreadyExists);

                foreach (string shareName in shareNames)
                {
                    fileUtil.AssertFileShareExists(shareName, "File share should exist after created.");
                }
            }
            finally
            {
                foreach (string shareName in shareNames)
                {
                    fileUtil.DeleteFileShareIfExists(shareName);
                }
            }
        }
Ejemplo n.º 28
0
 public override void OnTestSetup()
 {
     this.fileShare        = fileUtil.EnsureFileShareExists(CloudFileUtil.GenerateUniqueFileShareName());
     this.mountedShareRoot = MountShare(this.fileShare.Name);
 }