Ejemplo n.º 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);
        }
Ejemplo n.º 2
0
        public void QueueListOperations()
        {
            string PREFIX = Utility.GenNameString("uniqueprefix-") + "-";

            string[] QUEUE_NAMES = new string[] { Utility.GenNameString(PREFIX), Utility.GenNameString(PREFIX), Utility.GenNameString(PREFIX) };

            // PART_EXISTING_NAMES differs only the last element with Queue_NAMES
            string[] PARTLY_EXISTING_NAMES = new string[QUEUE_NAMES.Length];
            Array.Copy(QUEUE_NAMES, PARTLY_EXISTING_NAMES, QUEUE_NAMES.Length - 1);
            PARTLY_EXISTING_NAMES[QUEUE_NAMES.Length - 1] = Utility.GenNameString(PREFIX);

            string[] MERGED_NAMES = QUEUE_NAMES.Union(PARTLY_EXISTING_NAMES).ToArray();
            Array.Sort(MERGED_NAMES);

            bool multiOutput = lang == Language.PowerShell;

            // Generate the comparison data
            Collection <Dictionary <string, object> > comp = new Collection <Dictionary <string, object> >();

            foreach (string name in MERGED_NAMES)
            {
                comp.Add(Utility.GenComparisonData(StorageObjectType.Queue, name));
            }

            CloudQueueClient queueClient = StorageAccount.CreateCloudQueueClient();

            // Check if all the above Queues have been removed
            foreach (string name in MERGED_NAMES)
            {
                CloudQueue Queue = queueClient.GetQueueReference(name);
                Queue.DeleteIfExists();
            }

            //--------------1. New operation--------------
            Test.Assert(CommandAgent.NewAzureStorageQueue(QUEUE_NAMES), Utility.GenComparisonData("NewAzureStorageQueue", true));
            if (multiOutput)
            {
                // Verification for returned values
                Test.Assert(CommandAgent.Output.Count == 3, "3 row returned : {0}", CommandAgent.Output.Count);
            }

            // Check if all the above queues have been created
            foreach (string name in QUEUE_NAMES)
            {
                CloudQueue queue = queueClient.GetQueueReference(name);
                Test.Assert(queue.Exists(), "queue {0} should exist", name);
            }

            try
            {
                //--------------2. New operation--------------
                if (multiOutput)
                {
                    Test.Assert(!CommandAgent.NewAzureStorageQueue(QUEUE_NAMES), Utility.GenComparisonData("NewAzureStorageQueue", false));
                    // Verification for returned values
                    Test.Assert(CommandAgent.Output.Count == 0, "0 row returned : {0}", CommandAgent.Output.Count);

                    int i = 0;
                    foreach (string name in QUEUE_NAMES)
                    {
                        Test.Assert(CommandAgent.ErrorMessages[i].Contains(String.Format("Queue '{0}' already exists.", name)), CommandAgent.ErrorMessages[i]);
                        ++i;
                    }

                    //--------------3. New operation--------------
                    Test.Assert(!CommandAgent.NewAzureStorageQueue(PARTLY_EXISTING_NAMES), Utility.GenComparisonData("NewAzureStorageQueue", false));
                    Test.Assert(CommandAgent.Output.Count == 1, "1 row returned : {0}", CommandAgent.Output.Count);
                }
                else
                {
                    // Queue with the same could be created as long as the metadata is the same.
                    // http://msdn.microsoft.com/en-us/library/azure/dd179342.aspx
                    Test.Assert(CommandAgent.NewAzureStorageQueue(QUEUE_NAMES), Utility.GenComparisonData("NewAzureStorageQueue", true));

                    Test.Assert(CommandAgent.NewAzureStorageQueue(PARTLY_EXISTING_NAMES), Utility.GenComparisonData("NewAzureStorageQueue", true));
                    Test.Assert(CommandAgent.Output.Count == 1, "1 row returned : {0}", CommandAgent.Output.Count);
                }

                // Check if all the above queues have been created
                foreach (string name in QUEUE_NAMES)
                {
                    CloudQueue queue = queueClient.GetQueueReference(name);
                    Test.Assert(queue.Exists(), "queue {0} should exist", name);
                }

                //--------------4. Get operation--------------
                if (multiOutput)
                {
                    Test.Assert(CommandAgent.GetAzureStorageQueue("*" + PREFIX + "*"), Utility.GenComparisonData("GetAzureStorageQueue", true));
                    // Verification for returned values
                    CommandAgent.OutputValidation(StorageAccount.CreateCloudQueueClient().ListQueues(PREFIX, QueueListingDetails.All));
                }

                // use Prefix parameter
                Test.Assert(CommandAgent.GetAzureStorageQueueByPrefix(PREFIX), Utility.GenComparisonData("GetAzureStorageQueueByPrefix", true));
                // Verification for returned values
                CommandAgent.OutputValidation(StorageAccount.CreateCloudQueueClient().ListQueues(PREFIX, QueueListingDetails.All));
            }
            finally
            {
                //--------------5. Remove operation--------------
                Test.Assert(CommandAgent.RemoveAzureStorageQueue(MERGED_NAMES), Utility.GenComparisonData("RemoveAzureStorageQueue", true));
                // Check if all the above queues have been removed
                foreach (string name in QUEUE_NAMES)
                {
                    CloudQueue queue = queueClient.GetQueueReference(name);
                    Test.Assert(!queue.Exists(), "queue {0} should not exist", name);
                }
            }
        }