public void GetJobWithIdProvided() { // Update HDInsight Management properties for Job. SetupManagementClientForJobTests(); var jobId = "jobid_1984120_001"; var cmdlet = GetJobCommandDefinition(); cmdlet.JobId = jobId; // Setup Job Management mocks var jobResponse = new JobGetResponse { JobDetail = new JobDetailRootJsonObject { Id = jobId, Status = new Status(), Userargs = new Userargs() } }; hdinsightJobManagementMock.Setup(c => c.GetJob(It.IsAny<string>())) .Returns(jobResponse) .Verifiable(); cmdlet.ExecuteCmdlet(); commandRuntimeMock.VerifyAll(); commandRuntimeMock.Verify( f => f.WriteObject(It.Is<AzureHDInsightJob>(job => job.JobId.Equals(jobId)))); }
public void StartJob() { // Update HDInsight Management properties for Job. SetupManagementClientForJobTests(); var cmdlet = new StartAzureHDInsightJobCommand { CommandRuntime = commandRuntimeMock.Object, HDInsightJobClient = hdinsightJobManagementMock.Object, HDInsightManagementClient = hdinsightManagementMock.Object, HttpCredential = new PSCredential("httpuser", string.Format("Password1!").ConvertToSecureString()), ClusterName = ClusterName }; var args = new[] {"arg1", "arg2"}; const string query = "show tables;"; const string name = "hivejob"; var hivedef = new AzureHDInsightHiveJobDefinition { JobName = name, Query = query, }; foreach (var arg in args) { hivedef.Arguments.Add(arg); } cmdlet.JobDefinition = hivedef; const string jobid = "jobid_1984120_001"; var jobsub = new JobSubmissionResponse { JobSubmissionJsonResponse = new JobSubmissionJsonResponse { Id = jobid }, StatusCode = HttpStatusCode.OK }; hdinsightJobManagementMock.Setup( c => c.SubmitHiveJob( It.Is<AzureHDInsightHiveJobDefinition>( def => def.JobName == name && def.Query == query && def.Arguments.Count == args.Length))) .Returns(jobsub) .Verifiable(); var getresponse = new JobGetResponse { StatusCode = HttpStatusCode.OK, JobDetail = new JobDetailRootJsonObject { Completed = "false", User = cmdlet.HttpCredential.UserName, Id = jobid, Status = new Status(), Userargs = new Userargs() } }; hdinsightJobManagementMock.Setup(c => c.GetJob(jobsub.JobSubmissionJsonResponse.Id)).Returns(getresponse).Verifiable(); cmdlet.ExecuteCmdlet(); commandRuntimeMock.VerifyAll(); commandRuntimeMock.Verify( f => f.WriteObject( It.Is<AzureHDInsightJob>( job => job.Cluster == ClusterName && job.JobId == jobid && job.Completed == "false"))); }
public JobGetResponse MockJobCompletion(string jobId, JobCompletionType type) { var jobResponse = new JobGetResponse { JobDetail = new JobDetailRootJsonObject { Id = jobId, Status = new Status(), Userargs = new Userargs() } }; switch (type) { case JobCompletionType.Success: break; case JobCompletionType.Fail: throw new CloudException("Some Failure"); case JobCompletionType.TimeOut: throw new TimeoutException("Some Failure"); default: break; } return jobResponse; }