示例#1
0
        public void ListJobsAndGetJobTest()
        {
            using (UndoContext context = UndoContext.Current)
            {
                context.Start();

                string resourceNamespace = null;

                if (string.IsNullOrEmpty(resourceNamespace))
                {
                    resourceNamespace = ConfigurationManager.AppSettings["ResourceNamespace"];
                }

                var client = GetServiceClient<RecoveryServicesBackupManagementClient>(resourceNamespace);

                CommonJobQueryFilters commonFilters = new CommonJobQueryFilters();
                commonFilters.BackupManagementType = BackupManagementType.AzureIaasVM.ToString();
                commonFilters.StartTime = (new DateTime(2016, 4, 12, 20, 0, 0)).ToUniversalTime().ToString("yyyy-MM-dd hh:mm:ss tt");
                commonFilters.EndTime = (new DateTime(2016, 4, 13, 20, 0, 0)).ToUniversalTime().ToString("yyyy-MM-dd hh:mm:ss tt");

                JobTestHelper helper = new JobTestHelper(client);
                var jobList = helper.ListJobs(commonFilters, null);

                foreach (var job in jobList.ItemList.Value)
                {
                    Assert.NotNull(job.Id);
                    Assert.NotNull(job.Name);
                    helper.ValidateJobResponse(job.Properties, commonFilters);

                    // validating getjob
                    var jobDetalis = helper.GetJob(job.Name);
                    Assert.NotNull(jobDetalis);
                    Assert.NotNull(jobDetalis.Item);
                    helper.ValidateJobResponse(jobDetalis.Item.Properties, null);
                }
            }
        }
示例#2
0
        public void CancelJobTest()
        {
            using (UndoContext context = UndoContext.Current)
            {
                context.Start();

                string resourceNamespace = null;

                if (string.IsNullOrEmpty(resourceNamespace))
                {
                    resourceNamespace = ConfigurationManager.AppSettings["ResourceNamespace"];
                }

                var client = GetServiceClient<RecoveryServicesBackupManagementClient>(resourceNamespace);

                // take a protected item, and trigger backup
                // wait for it to complete. cancel it.
                CommonJobQueryFilters commonFilters = new CommonJobQueryFilters();
                commonFilters.Status = JobStatus.InProgress.ToString();
                commonFilters.Operation = JobOperation.Backup.ToString();

                JobTestHelper helper = new JobTestHelper(client);
                var jobList = helper.ListJobs(commonFilters, null);

                if (jobList.ItemList.Value.Count > 0)
                {
                    string jobId, opId;
                    jobId = jobList.ItemList.Value[0].Name;
                    // cancel the first job
                    var cancelResponse = helper.CancelJob(jobId);
                    opId = helper.GetOpId(cancelResponse.Location);
                    var opStatus = helper.GetJobOperationStatus(jobId, opId);

                    while (opStatus.StatusCode == HttpStatusCode.Accepted)
                    {
                        if (HttpMockServer.Mode == HttpRecorderMode.Record)
                        {
                            Thread.Sleep(15 * 1000);
                        }
                        opStatus = helper.GetJobOperationStatus(jobId, opId);
                    }
                }
            }
        }