Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
        private void WaitForJobCompletion_Internal(JobCompletionType completionType, string expectedMessageFormat)
        {
            var cmdlet = GetWaitAzureHDInsightJobCommandDefinition(completionType);

            bool success = false;

            try
            {
                cmdlet.ExecuteCmdlet();
            }
            catch (CloudException ex)
            {
                var expectedExceptionMessage = string.Format(CultureInfo.InvariantCulture, expectedMessageFormat, cmdlet.JobId, cmdlet.TimeoutInSeconds);
                if (ex.Message.Equals(expectedExceptionMessage))
                {
                    success = true;
                }
            }

            if (!success)
            {
                throw new Exception("Operation didn't fail");
            }
        }
Exemplo n.º 3
0
        public WaitAzureHDInsightJobCommand GetWaitAzureHDInsightJobCommandDefinition(JobCompletionType jobCompetionType)
        {
            // Update HDInsight Management properties for Job.
            SetupManagementClientForJobTests();

            // Setup Job Management mocks
            const string jobId = "jobid_1984120_001";

            var cmdlet = new WaitAzureHDInsightJobCommand
            {
                CommandRuntime            = commandRuntimeMock.Object,
                HDInsightJobClient        = hdinsightJobManagementMock.Object,
                HDInsightManagementClient = hdinsightManagementMock.Object,
                HttpCredential            = new PSCredential("httpuser", string.Format("Password1!").ConvertToSecureString()),
                ClusterName      = ClusterName,
                JobId            = jobId,
                TimeoutInSeconds = 10
            };

            JobGetResponse jobDetails  = null;
            TimeSpan?      jobDuration = TimeSpan.FromSeconds(10);

            hdinsightJobManagementMock.Setup(c => c.WaitForJobCompletion(It.IsAny <string>(), It.IsAny <TimeSpan?>(), null))
            .Callback((string id, TimeSpan? duration, TimeSpan? interval) => { jobDetails = MockJobCompletion(id, jobCompetionType); })
            .Returns(() => jobDetails);

            return(cmdlet);
        }
Exemplo n.º 4
0
        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;
        }
Exemplo n.º 5
0
        public WaitAzureHDInsightJobCommand GetWaitAzureHDInsightJobCommandDefinition(JobCompletionType jobCompetionType)
        {
            // Update HDInsight Management properties for Job.
            SetupManagementClientForJobTests();

            // Setup Job Management mocks
            const string jobId = "jobid_1984120_001";

            var cmdlet = new WaitAzureHDInsightJobCommand
            {
                CommandRuntime = commandRuntimeMock.Object,
                HDInsightJobClient = hdinsightJobManagementMock.Object,
                HDInsightManagementClient = hdinsightManagementMock.Object,
                HttpCredential = new PSCredential("httpuser", string.Format("Password1!").ConvertToSecureString()),
                ClusterName = ClusterName,
                JobId = jobId,
                TimeoutInSeconds = 10
            };

            JobGetResponse jobDetails = null;
            TimeSpan? jobDuration = TimeSpan.FromSeconds(10);
            hdinsightJobManagementMock.Setup(c => c.WaitForJobCompletion(It.IsAny<string>(), It.IsAny<TimeSpan?>(), null))
                .Callback((string id, TimeSpan? duration, TimeSpan? interval) => { jobDetails = MockJobCompletion(id, jobCompetionType); })
                .Returns(() => jobDetails);

            return cmdlet;
        }
Exemplo n.º 6
0
        public void WaitForJobCompletion_Internal(JobCompletionType completionType, string expectedMessageFormat)
        {
            var cmdlet = GetWaitAzureHDInsightJobCommandDefinition(completionType);

            bool success = false;

            try
            {
                cmdlet.ExecuteCmdlet();
            }
            catch (CloudException ex)
            {
                var expectedExceptionMessage = string.Format(CultureInfo.InvariantCulture, expectedMessageFormat, cmdlet.JobId, cmdlet.TimeoutInSeconds);
                if (ex.Message.Equals(expectedExceptionMessage))
                {
                    success = true;
                }
            }

            if (!success)
            {
                throw new Exception("Operation didn't fail");
            }
        }