Exemple #1
0
        /// <summary>
        /// Run one powershell cmdlet and return the time cost in millisecond
        /// </summary>
        /// <param name="methodType">cmdlet type</param>
        /// <param name="sNames">a list of names(by pipeline)</param>
        /// <param name="prefix">the preffix of the names</param>
        /// <returns>The milliseconds of running the cmdlets</returns>
        private long DoPerfOperation(string methodType, string[] sNames, string prefix)
        {
            DoInit(methodType, sNames, prefix, ref CLIPerf.sharedObject);

            Stopwatch sw = new Stopwatch();

            sw.Start();

            switch (methodType)
            {
            case PsTag.NewContainer:
            {
                Test.Assert(CommandAgent.NewAzureStorageContainer(sNames), Utility.GenComparisonData("NewAzureStorageContainer", true));
            }
            break;

            case PsTag.NewQueue:
            {
                Test.Assert(CommandAgent.NewAzureStorageQueue(sNames), Utility.GenComparisonData("NewAzureStorageQueue", true));
            }
            break;

            case PsTag.NewTable:
            {
                Test.Assert(CommandAgent.NewAzureStorageTable(sNames), Utility.GenComparisonData("NewAzureStorageTable", true));
            }
            break;

            case PsTag.NewShare:
            {
                Test.Assert(CommandAgent.NewFileShares(sNames), Utility.GenComparisonData("NewFileShare", true));
            }
            break;

            case PsTag.NewDirectory:
            {
                Test.Assert(CommandAgent.NewDirectories(CLIPerf.sharedObject as string, sNames), Utility.GenComparisonData("NewDirectory", true));
            }
            break;

            case PsTag.GetDirectory:
            {
                Test.Assert(CommandAgent.ListDirectories(CLIPerf.sharedObject as string), Utility.GenComparisonData("ListDirectory", true));
            }
            break;

            case PsTag.RemoveDirectory:
            {
                Test.Assert(CommandAgent.ListDirectories(CLIPerf.sharedObject as string), Utility.GenComparisonData("ListDirectory", true));
            }
            break;

            case PsTag.GetContainer:
            {
                Test.Assert(CommandAgent.GetAzureStorageContainerByPrefix(prefix), Utility.GenComparisonData("GetAzureStorageContainer", true));
            }
            break;

            case PsTag.GetShare:
            {
                Test.Assert(CommandAgent.GetFileSharesByPrefix(prefix), Utility.GenComparisonData("GetFileShare", true));
            }
            break;

            case PsTag.GetQueue:
            {
                Test.Assert(CommandAgent.GetAzureStorageQueueByPrefix(prefix), Utility.GenComparisonData("GetAzureStorageQueue", true));
            }
            break;

            case PsTag.GetTable:
            {
                Test.Assert(CommandAgent.GetAzureStorageTableByPrefix(prefix), Utility.GenComparisonData("GetAzureStorageTable", true));
            }
            break;

            case PsTag.RemoveContainer:
            {
                // use PowerShellAgent to remove a large number of containers in order to save time
                Test.Assert((new PowerShellAgent()).RemoveAzureStorageContainer(sNames), Utility.GenComparisonData("RemoveAzureStorageContainer", true));
            }
            break;

            case PsTag.RemoveShare:
            {
                Test.Assert(CommandAgent.RemoveFileShares(sNames), Utility.GenComparisonData("RemoveFileShare", true));
            }
            break;

            case PsTag.RemoveQueue:
            {
                Test.Assert(CommandAgent.RemoveAzureStorageQueue(sNames), Utility.GenComparisonData("RemoveAzureStorageQueue", true));
            }
            break;

            case PsTag.RemoveTable:
            {
                Test.Assert(CommandAgent.RemoveAzureStorageTable(sNames), Utility.GenComparisonData("RemoveAzureStorageTable", true));
            }
            break;

            case PsTag.SetContainerAcl:
            {
                Test.Assert(CommandAgent.SetAzureStorageContainerACL(sNames, BlobContainerPublicAccessType.Container), Utility.GenComparisonData("SetAzureStorageContainerACL", true));
            }
            break;

            default:
                Test.Assert(false, "Wrong method type!");
                break;
            }

            sw.Stop();

            DoCleanup(methodType, sNames, prefix, CLIPerf.sharedObject);

            // Verification for returned values
            int nCount = sNames.Length;

            switch (methodType)
            {
            case PsTag.NewContainer:
            case PsTag.NewQueue:
            case PsTag.NewTable:
            case PsTag.NewShare:
            case PsTag.NewDirectory:
            case PsTag.SetContainerAcl:
            {
                if (!(CommandAgent is NodeJSAgent))
                {
                    // no need to check for Node.js commands as it does not support pipeline
                    Test.Assert(CommandAgent.Output.Count == nCount, "{0} row returned : {1}", nCount, CommandAgent.Output.Count);
                    if (CommandAgent.Output.Count != nCount)
                    {
                        //only for debug
                        Test.Assert(false, "error found! terminate instantly for debug!");
                        Environment.Exit(0);
                    }
                }
            }
            break;

            case PsTag.GetContainer:
            {
                CommandAgent.OutputValidation(StorageAccount.CreateCloudBlobClient().ListContainers(prefix, ContainerListingDetails.All));
            }
            break;

            case PsTag.GetShare:
            {
                CommandAgent.OutputValidation(StorageAccount.CreateCloudFileClient().ListShares(
                                                  prefix: prefix,
                                                  detailsIncluded: Microsoft.WindowsAzure.Storage.File.ShareListingDetails.All));
            }
            break;

            case PsTag.GetDirectory:
            {
                CommandAgent.OutputValidation(StorageAccount.CreateCloudFileClient().GetShareReference(CLIPerf.sharedObject as string).GetRootDirectoryReference().ListFilesAndDirectories());
            }
            break;

            case PsTag.GetQueue:
            {
                CommandAgent.OutputValidation(StorageAccount.CreateCloudQueueClient().ListQueues(prefix, QueueListingDetails.All));
            }
            break;

            case PsTag.GetTable:
            {
                CommandAgent.OutputValidation(StorageAccount.CreateCloudTableClient().ListTables(prefix));
            }
            break;

            case PsTag.RemoveContainer:
            case PsTag.RemoveQueue:
            case PsTag.RemoveShare:
            case PsTag.RemoveDirectory:
            case PsTag.RemoveTable:
            {
                // No need to check the return object count now as it won't return any object for remove cmdlets
                //Test.Assert(agent.Output.Count == nContainerCount, "{0} row returned : {1}", nContainerCount, agent.Output.Count);
            }
            break;

            default:
                Test.Assert(false, "Wrong method type!");
                break;
            }

            return(sw.ElapsedMilliseconds);
        }