/// <summary> /// Performs a simple AddTask test, adding the specified task count using the specified parallelOptions and resultHandlerFunc /// </summary> /// <returns></returns> private async System.Threading.Tasks.Task AddTasksSimpleTestAsync( BatchClient batchCli, string testName, int taskCount, BatchClientParallelOptions parallelOptions, Func <AddTaskResult, CancellationToken, AddTaskResultStatus> resultHandlerFunc, StagingStorageAccount storageCredentials, IEnumerable <string> localFilesToStage, ConcurrentBag <ConcurrentDictionary <Type, IFileStagingArtifact> > fileStagingArtifacts = null, TimeSpan?timeout = null, bool useJobOperations = true) { JobOperations jobOperations = batchCli.JobOperations; string jobId = "Bulk-" + TestUtilities.GetMyName() + "-" + testName + "-" + useJobOperations; try { CloudJob unboundJob = jobOperations.CreateJob(); this.testOutputHelper.WriteLine("Initial job commit for job: {0}", jobId); unboundJob.PoolInformation = new PoolInformation() { PoolId = "DummyPool" }; unboundJob.Id = jobId; await unboundJob.CommitAsync().ConfigureAwait(false); CloudJob boundJob = await jobOperations.GetJobAsync(jobId).ConfigureAwait(false); // // Add a simple set of tasks // IEnumerable <string> taskNames = GenerateTaskIds(taskCount); List <CloudTask> tasksToAdd = new List <CloudTask>(); List <CloudTask> tasksToValidateWith = new List <CloudTask>(); IList <IFileStagingProvider> lastFilesToStageList = null; foreach (string taskName in taskNames) { CloudTask myTask = new CloudTask(taskName, "cmd /c echo hello world"); CloudTask duplicateReadableTask = new CloudTask(taskName, "cmd /c echo hello world"); if (localFilesToStage != null && storageCredentials != null) { myTask.FilesToStage = new List <IFileStagingProvider>(); lastFilesToStageList = myTask.FilesToStage; duplicateReadableTask.FilesToStage = new List <IFileStagingProvider>(); foreach (string fileToStage in localFilesToStage) { duplicateReadableTask.FilesToStage.Add(new FileToStage(fileToStage, storageCredentials)); myTask.FilesToStage.Add(new FileToStage(fileToStage, storageCredentials)); } } tasksToAdd.Add(myTask); tasksToValidateWith.Add(duplicateReadableTask); } List <BatchClientBehavior> behaviors = new List <BatchClientBehavior>(); if (resultHandlerFunc != null) { behaviors.Add(new AddTaskCollectionResultHandler(resultHandlerFunc)); } //Add the tasks Stopwatch stopwatch = new Stopwatch(); this.testOutputHelper.WriteLine("Starting task add"); stopwatch.Start(); if (useJobOperations) { await jobOperations.AddTaskAsync( jobId, tasksToAdd, parallelOptions : parallelOptions, fileStagingArtifacts : fileStagingArtifacts, timeout : timeout, additionalBehaviors : behaviors).ConfigureAwait(continueOnCapturedContext: false); } else { await boundJob.AddTaskAsync( tasksToAdd, parallelOptions : parallelOptions, fileStagingArtifacts : fileStagingArtifacts, timeout : timeout, additionalBehaviors : behaviors).ConfigureAwait(continueOnCapturedContext: false); } stopwatch.Stop(); this.testOutputHelper.WriteLine("Task add finished, took: {0}", stopwatch.Elapsed); if (lastFilesToStageList != null) { Assert.Throws <InvalidOperationException>(() => lastFilesToStageList.Add(new FileToStage("test", null))); } //Ensure the task lists match List <CloudTask> tasksFromService = await jobOperations.ListTasks(jobId).ToListAsync().ConfigureAwait(false); EnsureTasksListsMatch(tasksToValidateWith, tasksFromService); } catch (Exception e) { this.testOutputHelper.WriteLine("Exception: {0}", e.ToString()); throw; } finally { TestUtilities.DeleteJobIfExistsAsync(batchCli, jobId).Wait(); } }