예제 #1
0
        private static async Task MutateJobAsync(string jobId, Func <CloudJob, Task> jobAction)
        {
            using (BatchClient batchCli = await TestUtilities.OpenBatchClientFromEnvironmentAsync().ConfigureAwait(false))
            {
                const string newPoolId           = "Bar";
                const string metadataKey         = "Foo";
                const string metadataValue       = "Bar";
                TimeSpan     newMaxWallClockTime = TimeSpan.FromDays(1);
                try
                {
                    CloudJob job = batchCli.JobOperations.CreateJob(
                        jobId,
                        new PoolInformation()
                    {
                        PoolId = "Temp"
                    });

                    await job.CommitAsync().ConfigureAwait(false);

                    await job.RefreshAsync().ConfigureAwait(false);

                    //Disable the job so that we can update the pool info
                    await job.DisableAsync(DisableJobOption.Requeue).ConfigureAwait(false);

                    await TestUtilities.WaitForJobStateAsync(job, TimeSpan.FromMinutes(1), JobState.Disabled).ConfigureAwait(false);

                    job.Constraints = new JobConstraints(maxWallClockTime: newMaxWallClockTime);
                    job.Metadata    = new List <MetadataItem>()
                    {
                        new MetadataItem(metadataKey, metadataValue)
                    };
                    job.PoolInformation.PoolId = newPoolId;

                    await jobAction(job).ConfigureAwait(false);

                    await job.RefreshAsync().ConfigureAwait(false);

                    Assert.Equal(newMaxWallClockTime, job.Constraints.MaxWallClockTime);
                    Assert.Equal(newPoolId, job.PoolInformation.PoolId);
                    Assert.Equal(metadataKey, job.Metadata.Single().Name);
                    Assert.Equal(metadataValue, job.Metadata.Single().Value);
                }
                finally
                {
                    await TestUtilities.DeleteJobIfExistsAsync(batchCli, jobId).ConfigureAwait(false);
                }
            }
        }