예제 #1
0
        public async Task UnboundJobCommitAndRefreshWorks()
        {
            using (BatchClient batchClient = ClientUnitTestCommon.CreateDummyClient())
            {
                const string id          = "Bar";
                const string displayName = "Baz";
                var          prepTask    = new Protocol.Models.JobPreparationTask(id);

                Protocol.Models.CloudJob protoJob = new Protocol.Models.CloudJob(
                    id: id,
                    displayName: displayName,
                    jobPreparationTask: prepTask);

                CloudJob job = batchClient.JobOperations.CreateJob(id, new PoolInformation()
                {
                    PoolId = "Foo"
                });

                await job.CommitAsync(additionalBehaviors : InterceptorFactory.CreateAddJobRequestInterceptor());

                await job.RefreshAsync(additionalBehaviors : InterceptorFactory.CreateGetJobRequestInterceptor(protoJob));

                Assert.Equal(id, job.Id);
                Assert.Equal(displayName, job.DisplayName);
                Assert.Null(job.PoolInformation);
                Assert.NotNull(job.JobPreparationTask);
                Assert.Equal(prepTask.Id, job.JobPreparationTask.Id);
            }
        }
예제 #2
0
        public void GetJobManagerTaskWithApplicationPackageReferences()
        {
            const string jobId         = "id-123";
            const string applicationId = "foo";
            const string version       = "beta";

            using (BatchClient client = ClientUnitTestCommon.CreateDummyClient())
            {
                Models.CloudJob protoJob = new Models.CloudJob
                {
                    Id             = jobId,
                    JobManagerTask = new Models.JobManagerTask
                    {
                        ApplicationPackageReferences = new List <Models.ApplicationPackageReference>
                        {
                            new Models.ApplicationPackageReference
                            {
                                Version = version, ApplicationId = applicationId
                            }
                        }
                    }
                };

                var job = client.JobOperations.GetJob(jobId, additionalBehaviors: InterceptorFactory.CreateGetJobRequestInterceptor(protoJob));
                Assert.Equal(applicationId, job.JobManagerTask.ApplicationPackageReferences.First().ApplicationId);
                Assert.Equal(version, job.JobManagerTask.ApplicationPackageReferences.First().Version);
            }
        }
예제 #3
0
        private static void CommonPatchJobTest(
            Protocol.Models.CloudJob startEntity,
            Action <CloudJob> modificationFunction,
            Action <Protocol.Models.JobPatchParameter> assertAction)
        {
            using (BatchClient client = ClientUnitTestCommon.CreateDummyClient())
            {
                CloudJob job = client.JobOperations.GetJob(
                    string.Empty,
                    additionalBehaviors: InterceptorFactory.CreateGetJobRequestInterceptor(startEntity));

                modificationFunction(job);

                var patchInterceptor = ShimPatchJob(assertAction);
                job.CommitChanges(additionalBehaviors: new[] { patchInterceptor });

                //Ensure that the job is in readable but unmodifiable state
                var id       = job.Id;
                var priority = job.Priority;

                Assert.Throws <InvalidOperationException>(() => job.Priority = 5);
            }
        }
        public void CloudJob_WhenReturnedFromServer_HasExpectedBoundProperties()
        {
            const string jobId              = "id-123";
            const string displayName        = "DisplayNameFoo";
            string       applicationVersion = "beta";
            string       applicationId      = "test";

            MetadataItem metadataItem       = new MetadataItem("foo", "bar");
            const int    priority           = 0;
            var          onAllTasksComplete = OnAllTasksComplete.TerminateJob;

            using (BatchClient client = ClientUnitTestCommon.CreateDummyClient())
            {
                DateTime creationTime = DateTime.Now;

                Models.CloudJob protoJob = new Models.CloudJob(
                    jobId,
                    displayName,
                    jobManagerTask: new Models.JobManagerTask()
                {
                    ApplicationPackageReferences = new [] { new Models.ApplicationPackageReference()
                                                            {
                                                                ApplicationId = applicationId, Version = applicationVersion
                                                            } }
                },
                    metadata: new[] { new Models.MetadataItem {
                                          Name = metadataItem.Name, Value = metadataItem.Value
                                      } },
                    creationTime: creationTime,
                    priority: priority,
                    url: ClientUnitTestCommon.DummyBaseUrl,
                    onAllTasksComplete: Models.OnAllTasksComplete.NoAction);

                CloudJob boundJob = client.JobOperations.GetJob(jobId, additionalBehaviors: InterceptorFactory.CreateGetJobRequestInterceptor(protoJob));

                Assert.Equal(jobId, boundJob.Id); // reading is allowed from a job that is returned from the server.
                Assert.Equal(creationTime, boundJob.CreationTime);
                Assert.Equal(displayName, boundJob.DisplayName);
                Assert.Equal(applicationId, boundJob.JobManagerTask.ApplicationPackageReferences.First().ApplicationId);
                Assert.Equal(applicationVersion, boundJob.JobManagerTask.ApplicationPackageReferences.First().Version);

                AssertPatchableJobPropertiesCanBeWritten(boundJob, priority, metadataItem, onAllTasksComplete);

                // Can only read a url from a returned object.
                Assert.Equal(ClientUnitTestCommon.DummyBaseUrl, boundJob.Url);

                // Cannot change a bound displayName, Id and any property on a JobManagerTask.
                Assert.Throws <InvalidOperationException>(() => boundJob.DisplayName = "cannot-change-display-name");
                Assert.Throws <InvalidOperationException>(() => boundJob.Id          = "cannot-change-id");
                Assert.Throws <InvalidOperationException>(() => boundJob.JobManagerTask.ApplicationPackageReferences = new List <ApplicationPackageReference>());
                Assert.Throws <InvalidOperationException>(() => boundJob.JobManagerTask = new JobManagerTask());
            }
        }
예제 #5
0
        public void CreateCloudTaskWithApplicationPackageReferences()
        {
            const string jobId              = "id-123";
            const string taskId             = "id-123";
            const string applicationId      = "testApp";
            const string applicationVersion = "beta";

            using (BatchClient client = ClientUnitTestCommon.CreateDummyClient())
            {
                Models.CloudJob returnFakeJob = new Models.CloudJob(jobId);
                var             job           = client.JobOperations.GetJob(jobId, additionalBehaviors: InterceptorFactory.CreateGetJobRequestInterceptor(returnFakeJob));

                var verifyAPRs = ClientUnitTestCommon.SimulateServiceResponse <Models.TaskAddParameter, Models.TaskAddOptions, AzureOperationHeaderResponse <Models.TaskAddHeaders> >(
                    (parameters, options) =>
                {
                    Assert.Equal(applicationId, parameters.ApplicationPackageReferences.First().ApplicationId);
                    Assert.Equal(applicationVersion, parameters.ApplicationPackageReferences.First().Version);

                    return(new AzureOperationHeaderResponse <Models.TaskAddHeaders>
                    {
                        Response = new HttpResponseMessage(HttpStatusCode.Accepted)
                    });
                });

                var taskWithAPRs = new CloudTask(taskId, "cmd /c hostname")
                {
                    ApplicationPackageReferences = new List <ApplicationPackageReference>
                    {
                        new ApplicationPackageReference
                        {
                            ApplicationId = applicationId,
                            Version       = applicationVersion
                        }
                    }
                };

                job.AddTask(taskWithAPRs, additionalBehaviors: verifyAPRs);  // assertions happen in the callback
            }
        }
예제 #6
0
        public async Task ExitConditionsAreSentOnTask()
        {
            const string jobId  = "id-123";
            const string taskId = "id-001";

            using (BatchClient client = ClientUnitTestCommon.CreateDummyClient())
            {
                Models.CloudJob protoJob = new Models.CloudJob(id: jobId, onAllTasksComplete: Models.OnAllTasksComplete.NoAction, onTaskFailure: Models.OnTaskFailure.PerformExitOptionsJobAction);

                var fakeAddTaskResponse = ClientUnitTestCommon.SimulateServiceResponse <Models.TaskAddParameter, Models.TaskAddOptions, AzureOperationHeaderResponse <Models.TaskAddHeaders> >((parameters, options) =>
                {
                    Assert.Equal((Models.JobAction?)JobAction.Terminate, parameters.ExitConditions.DefaultProperty.JobAction);
                    Assert.Equal(0, parameters.ExitConditions.ExitCodeRanges.First().Start);
                    Assert.Equal(4, parameters.ExitConditions.ExitCodeRanges.First().End);
                    Assert.Equal((Models.JobAction?)JobAction.Disable, parameters.ExitConditions.ExitCodeRanges.First().ExitOptions.JobAction);
                    // These need to be compared as strings because they are different types but we are interested in the values being the same.
                    Assert.Equal(DependencyAction.Satisfy.ToString(), parameters.ExitConditions.ExitCodeRanges.First().ExitOptions.DependencyAction.ToString());
                    Assert.Equal(3, parameters.ExitConditions.ExitCodes.First().Code);
                    Assert.Equal((Models.JobAction?)JobAction.None, parameters.ExitConditions.ExitCodes.First().ExitOptions.JobAction);
                    Assert.Equal((Models.JobAction?)JobAction.Terminate, parameters.ExitConditions.FileUploadError.JobAction);

                    return(new AzureOperationHeaderResponse <Models.TaskAddHeaders>()
                    {
                        Response = new HttpResponseMessage(HttpStatusCode.Accepted)
                    });
                });

                CloudJob boundJob = await client.JobOperations.GetJobAsync(string.Empty, additionalBehaviors : InterceptorFactory.CreateGetJobRequestInterceptor(protoJob));

                boundJob.OnAllTasksComplete = OnAllTasksComplete.TerminateJob;

                CloudTask cloudTask = new CloudTask(taskId, "cmd /c echo hello world");

                cloudTask.ExitConditions = new ExitConditions()
                {
                    Default = new ExitOptions()
                    {
                        JobAction = JobAction.Terminate
                    },
                    ExitCodeRanges = new List <ExitCodeRangeMapping>()
                    {
                        new ExitCodeRangeMapping(0, 4, new ExitOptions()
                        {
                            DependencyAction = DependencyAction.Satisfy, JobAction = JobAction.Disable,
                        })
                    },
                    ExitCodes = new List <ExitCodeMapping>()
                    {
                        new ExitCodeMapping(3, new ExitOptions()
                        {
                            JobAction = JobAction.None
                        })
                    },
                    PreProcessingError = new ExitOptions()
                    {
                        JobAction = JobAction.Terminate
                    },
                    FileUploadError = new ExitOptions()
                    {
                        JobAction = JobAction.Terminate
                    }
                };

                boundJob.AddTask(cloudTask, additionalBehaviors: fakeAddTaskResponse);
            }
        }
예제 #7
0
        public async Task UpdateBoundJobWithNewAutoTerminationPropertiesTest()
        {
            using (BatchClient client = ClientUnitTestCommon.CreateDummyClient())
            {
                Models.CloudJob protoJob = new Models.CloudJob(id: "id", onAllTasksComplete: Models.OnAllTasksComplete.NoAction, onTaskFailure: Models.OnTaskFailure.PerformExitOptionsJobAction);

                CloudJob boundJob = await client.JobOperations.GetJobAsync(string.Empty, additionalBehaviors : InterceptorFactory.CreateGetJobRequestInterceptor(protoJob));

                Assert.Equal(OnAllTasksComplete.NoAction, boundJob.OnAllTasksComplete);
                Assert.Equal(OnTaskFailure.PerformExitOptionsJobAction, boundJob.OnTaskFailure);

                // Can update job's auto complete properties.
                boundJob.OnAllTasksComplete = OnAllTasksComplete.TerminateJob;
                Assert.Equal(OnAllTasksComplete.TerminateJob, boundJob.OnAllTasksComplete);
            }
        }
예제 #8
0
        public async Task CreateTaskWithExitConditionsTest()
        {
            const string jobId  = "id-123";
            const string taskId = "id-001";

            BatchSharedKeyCredentials credentials = ClientUnitTestCommon.CreateDummySharedKeyCredential();

            using (BatchClient client = await BatchClient.OpenAsync(credentials))
            {
                Models.CloudJob protoJob = new Models.CloudJob(id: jobId, onAllTasksComplete: Models.OnAllTasksComplete.NoAction, onTaskFailure: Models.OnTaskFailure.PerformExitOptionsJobAction);

                var fakeAddTaskResponse = ClientUnitTestCommon.SimulateServiceResponse <Models.TaskAddParameter, Models.TaskAddOptions, AzureOperationHeaderResponse <Models.TaskAddHeaders> >((parameters, options) =>
                {
                    Assert.Equal((Models.JobAction?)JobAction.Terminate, parameters.ExitConditions.DefaultProperty.JobAction);
                    Assert.Equal(0, parameters.ExitConditions.ExitCodeRanges.First().Start);
                    Assert.Equal(4, parameters.ExitConditions.ExitCodeRanges.First().End);
                    Assert.Equal((Models.JobAction?)JobAction.Disable, parameters.ExitConditions.ExitCodeRanges.First().ExitOptions.JobAction);
                    Assert.Equal(3, parameters.ExitConditions.ExitCodes.First().Code);
                    Assert.Equal((Models.JobAction?)JobAction.None, parameters.ExitConditions.ExitCodes.First().ExitOptions.JobAction);

                    return(new AzureOperationHeaderResponse <Models.TaskAddHeaders>()
                    {
                        Response = new HttpResponseMessage(HttpStatusCode.Accepted)
                    });
                });

                CloudJob boundJob = await client.JobOperations.GetJobAsync(string.Empty, additionalBehaviors : InterceptorFactory.CreateGetJobRequestInterceptor(protoJob));

                boundJob.OnAllTasksComplete = OnAllTasksComplete.TerminateJob;

                // Cannot change OnTaskFailure on a bound job
                Assert.Throws <InvalidOperationException>(() => boundJob.OnTaskFailure = OnTaskFailure.NoAction);

                CloudTask cloudTask = new CloudTask(taskId, "cmd /c echo hello world");

                cloudTask.ExitConditions = new ExitConditions()
                {
                    Default = new ExitOptions()
                    {
                        JobAction = JobAction.Terminate
                    },
                    ExitCodeRanges = new List <ExitCodeRangeMapping>()
                    {
                        new ExitCodeRangeMapping(0, 4, new ExitOptions()
                        {
                            JobAction = JobAction.Disable
                        })
                    },
                    ExitCodes = new List <ExitCodeMapping>()
                    {
                        new ExitCodeMapping(3, new ExitOptions()
                        {
                            JobAction = JobAction.None
                        })
                    },
                    SchedulingError = new ExitOptions()
                    {
                        JobAction = JobAction.Terminate
                    },
                };

                boundJob.AddTask(cloudTask, additionalBehaviors: fakeAddTaskResponse);
            }
        }