public void RunJob(string xmlFile, string jobName, UnityLoader loader, bool shouldFail) { // Flush output file GetFileNamesOut().ForEach(s => { if (File.Exists(s)) { File.Delete(s); } }); // Prerequisites GetFileNamesIn().ForEach(s => Assert.IsTrue(new FileInfo(s).Exists, "Job input file " + s + " does not exist, job can't be run")); GetFileNamesOut().ForEach(s => Assert.IsFalse(new FileInfo(s).Exists, "Job output file " + s + " should have been deleted before test")); XmlJob job = XmlJobParser.LoadJob(xmlFile); IJobOperator jobOperator = BatchRuntime.GetJobOperator(loader, job); Assert.IsNotNull(jobOperator); long?executionId = jobOperator.StartNextInstance(jobName); Assert.IsNotNull(executionId); JobExecution jobExecution = ((SimpleJobOperator)jobOperator).JobExplorer.GetJobExecution((long)executionId); //job SHOULD BE FAILED because of rollback having occured if (shouldFail) { Assert.IsTrue(jobExecution.Status.IsUnsuccessful()); } else { Assert.IsFalse(jobExecution.Status.IsUnsuccessful()); } Assert.IsFalse(jobExecution.Status.IsRunning()); }
public void RunJobWithTaskletMergeCopy() { //prepare stuff if (!Directory.Exists(TestDataDirectoryToMerge)) { Directory.CreateDirectory(TestDataDirectoryToMerge); } FileInfo ofi = new FileInfo(Path.Combine(TestDataDirectoryToMerge, "report1_merged_copy.txt")); if (!ofi.Exists) { using (FileStream fs = File.OpenRead(Path.Combine(TestDataDirectoryIn, "report0.txt"))) using (FileStream ofs = File.OpenWrite(Path.Combine(TestDataDirectoryToMerge, "report1_merged_copy.txt"))) { fs.CopyTo(ofs); } } XmlJob job = XmlJobParser.LoadJob("Job1.xml"); IJobOperator jobOperator = BatchRuntime.GetJobOperator(new MyUnityLoaderJob1MergeCopy(), job); Assert.IsNotNull(jobOperator); long?executionId = jobOperator.StartNextInstance(job.Id); Assert.IsNotNull(executionId); JobExecution jobExecution = ((SimpleJobOperator)jobOperator).JobExplorer.GetJobExecution((long)executionId); Assert.IsFalse(jobExecution.Status.IsUnsuccessful()); Assert.IsFalse(jobExecution.Status.IsRunning()); }
public void RunTestWithSuppliedDbConfig() { IJobOperator jobOperator = BatchRuntime.GetJobOperator(new MyDbUnityLoader()); Assert.IsInstanceOfType(jobOperator, typeof(SimpleJobOperator)); Type t = jobOperator.GetType(); PropertyInfo f = t.GetProperty("JobLauncher", BindingFlags.Instance | BindingFlags.Public); IJobLauncher jobLauncher = (IJobLauncher)f.GetValue(jobOperator); Assert.IsNotNull(jobLauncher); Assert.IsInstanceOfType(jobLauncher, typeof(SimpleJobLauncher)); PropertyInfo f2 = t.GetProperty("JobRepository", BindingFlags.Instance | BindingFlags.Public); IJobRepository jobRepository = (IJobRepository)f2.GetValue(jobOperator); Assert.IsNotNull(jobRepository); Assert.IsInstanceOfType(jobRepository, typeof(SimpleJobRepository)); PropertyInfo f3 = t.GetProperty("JobRegistry", BindingFlags.Instance | BindingFlags.Public); IListableJobLocator jobRegistry = (IListableJobLocator)f3.GetValue(jobOperator); Assert.IsNotNull(jobRegistry); Assert.IsInstanceOfType(jobRegistry, typeof(MapJobRegistry)); PropertyInfo f4 = t.GetProperty("JobExplorer", BindingFlags.Instance | BindingFlags.Public); IJobExplorer jobExplorer = (IJobExplorer)f4.GetValue(jobOperator); Assert.IsNotNull(jobExplorer); Assert.IsInstanceOfType(jobExplorer, typeof(SimpleJobExplorer)); FieldInfo f5 = jobRepository.GetType().GetField("_jobInstanceDao", BindingFlags.Instance | BindingFlags.NonPublic); IJobInstanceDao dao = (IJobInstanceDao)f5.GetValue(jobRepository); Assert.IsNotNull(dao); Assert.IsInstanceOfType(dao, typeof(DbJobInstanceDao)); }
public void RunJobWithTasklet() { XmlJob job = XmlJobParser.LoadJob("Job1.xml"); IJobOperator jobOperator = BatchRuntime.GetJobOperator(new MyUnityLoaderJob1(), job); Assert.IsNotNull(jobOperator); Assert.AreEqual(1, jobOperator.StartNextInstance(job.Id)); }
public void RunJobWithTasklet() { XmlJob job = XmlJobParser.LoadJob("JobSqlScript.xml"); IJobOperator jobOperator = BatchRuntime.GetJobOperator(new MyUnityLoaderJob1(), job); Assert.IsNotNull(jobOperator); Assert.AreEqual(1, jobOperator.StartNextInstance(job.Id)); JobExecution jobExecution = ((SimpleJobOperator)jobOperator).JobExplorer.GetJobExecution(1); Assert.IsFalse(jobExecution.Status.IsUnsuccessful()); }
public void PowerShellExitStatus() { XmlJob job = XmlJobParser.LoadJob("JobPowerShellExitStatus.xml"); IJobOperator jobOperator = BatchRuntime.GetJobOperator(new MyUnityLoaderPowerShellExitStatus(), job); Assert.IsNotNull(jobOperator); long?executionId = jobOperator.StartNextInstance(job.Id); Assert.IsNotNull(executionId); JobExecution jobExecution = ((SimpleJobOperator)jobOperator).JobExplorer.GetJobExecution((long)executionId); Assert.IsFalse(jobExecution.Status.IsUnsuccessful()); Assert.IsFalse(jobExecution.Status.IsRunning()); }
public void RunJobWithTaskletReset() { FileUtils.CopyDir(TestDataDirectoryIn, TestDataDirectoryToReset); XmlJob job = XmlJobParser.LoadJob("Job1.xml"); IJobOperator jobOperator = BatchRuntime.GetJobOperator(new MyUnityLoaderJob1Reset(), job); Assert.IsNotNull(jobOperator); long?executionId = jobOperator.StartNextInstance(job.Id); Assert.IsNotNull(executionId); JobExecution jobExecution = ((SimpleJobOperator)jobOperator).JobExplorer.GetJobExecution((long)executionId); Assert.IsFalse(jobExecution.Status.IsUnsuccessful()); Assert.IsFalse(jobExecution.Status.IsRunning()); }
/// <summary> /// Creates an <see cref="IJobOperator"/> with the specified <see cref="UnityLoader"/>. /// </summary> /// <param name="loader">The <see cref="UnityLoader"/> to use.</param> /// <returns>An instance of <see cref="IJobOperator"/>.</returns> public static IJobOperator GetJobOperator(UnityLoader loader) { IUnityContainer unityContainer = new UnityContainer(); unityContainer.AddNewExtension <PostprocessingUnityExtension>(); unityContainer.AddNewExtension <StepScopeExtension>(); unityContainer.AddNewExtension <SingletonExtension>(); loader.Load(unityContainer); IJobOperator jobOperator = unityContainer.Resolve <IJobOperator>(); if (jobOperator != null) { Logger.Debug("Loaded BatchContainerServiceProvider with className = {0}", jobOperator.GetType()); } return(jobOperator); }
public void RunJobWithTaskletMerge() { if (!Directory.Exists(TestDataDirectoryToMerge)) { Directory.CreateDirectory(TestDataDirectoryToMerge); } XmlJob job = XmlJobParser.LoadJob("Job1.xml"); IJobOperator jobOperator = BatchRuntime.GetJobOperator(new MyUnityLoaderJob1Merge(), job); Assert.IsNotNull(jobOperator); long?executionId = jobOperator.StartNextInstance(job.Id); Assert.IsNotNull(executionId); JobExecution jobExecution = ((SimpleJobOperator)jobOperator).JobExplorer.GetJobExecution((long)executionId); Assert.IsFalse(jobExecution.Status.IsUnsuccessful()); Assert.IsFalse(jobExecution.Status.IsRunning()); }
public void RunJobWithTasklet() { //Delete any prior existing output file FileInfo priorOutputFile = new FileInfo(TestPathOut); if (priorOutputFile.Exists) { priorOutputFile.Delete(); } XmlJob job = XmlJobParser.LoadJob("Job1.xml"); IJobOperator jobOperator = BatchRuntime.GetJobOperator(new MyUnityLoaderJob1(), job); Assert.IsNotNull(jobOperator); Assert.AreEqual(1, jobOperator.StartNextInstance(job.Id)); // Post controls FileInfo outputFile = new FileInfo(TestPathOut); Assert.IsTrue(outputFile.Exists, "Job output file does not exist, job was not successful"); Assert.IsTrue(outputFile.Length > 0, "Job output file is empty, job was not successful"); }