public void Initialize()
 {
     _jobInstance = new JobInstance(1, "testJob");
     _jobExecution = new JobExecution(_jobInstance, new JobParameters());
     _stepExecution1 = new StepExecution("testStep1", _jobExecution, 1);
     _stepExecution2 = new StepExecution("testStep2", _jobExecution, 2);
 }
 /// <summary>
 /// Method for re-constituting the step executions from
 /// existing instances.
 /// </summary>
 /// <param name="stepExecution"></param>
 public void AddStepExecution(StepExecution stepExecution)
 {
     if (!_stepExecutions.Contains(stepExecution))
     {
         _stepExecutions.TryAdd((stepExecution));
     }
 }
Beispiel #3
0
        /// <summary>
        /// Registers a step execution with the current job execution.
        /// </summary>
        /// <param name="stepName"></param>
        /// <returns>the name of the step the new execution is associated with</returns>
        public StepExecution CreateStepExecution(string stepName)
        {
            StepExecution stepExecution = new StepExecution(stepName, this);

            _stepExecutions.TryAdd(stepExecution);
            return(stepExecution);
        }
        /// <summary>
        /// Performs the actual check and returns the code "EMPTY" or "NOT_EMPTY" accordingly
        /// </summary>
        /// <param name="stepExecution"></param>
        /// <returns>"EMPTY" or "NOT_EMPTY"</returns>
        public ExitStatus AfterStep(StepExecution stepExecution)
        {
            string exitCode = Empty;

            try
            {
                FileInfo file = FileToCheck.GetFileInfo();

                if (file.Exists && (file.Attributes & FileAttributes.Directory) != FileAttributes.Directory &&
                    file.Length > 0)
                {
                    if (Logger.IsDebugEnabled)
                    {
                        Logger.Debug("File [{0}] is not empty ! length =[{1}]", file.FullName, file.Length);
                    }
                    exitCode = NotEmpty;
                }
                else
                {
                    if (Logger.IsDebugEnabled)
                    {
                        Logger.Debug("File [{0}] is empty .", file.FullName);
                    }
                }
            }
            catch (IOException)
            {
                Logger.Error("Error accessing file " + FileToCheck.GetFilename());
            }
           
            return new ExitStatus(exitCode);
        }
        public void TestUpdateStepExecution2()
        {
            var stepExecution = new StepExecution("testStep", _jobExecution);
            _stepExecutionDao.SaveStepExecution(stepExecution);
            stepExecution.Version = 1;

            _stepExecutionDao.UpdateStepExecution(stepExecution);
        }
 /// <summary>
 /// @see IStepExecutionListener#BeforeStep
 /// Launched before the step. Initializes the writers associated streams, if any.
 /// </summary>
 /// <param name="stepExecution"></param>
 public void BeforeStep(StepExecution stepExecution)
 {
     StepContextManager.Context = stepExecution.ExecutionContext;
     foreach (var writer in Writers)
     {
         writer.InitStream();
     }
 }
        public void TestSaveStepExecution()
        {
            var stepExecution = new StepExecution("testStep", _jobExecution);

            _stepExecutionDao.SaveStepExecution(stepExecution);

            Assert.AreEqual(1L, stepExecution.Id);
            Assert.AreEqual(0, stepExecution.Version);
        }
        /// <summary>
        /// Registers a step execution with the current job execution.
        /// </summary>
        /// <param name="stepName"></param>
        /// <returns>the name of the step the new execution is associated with</returns>
        public StepExecution CreateStepExecution(string stepName)
        {
            StepExecution stepExecution = new StepExecution(stepName, this);

            if (!_stepExecutions.Contains(stepExecution))
            {
                _stepExecutions.TryAdd(stepExecution);
            }
            return(stepExecution);
        }
        public void TestSaveStepExecution()
        {
            ResetSequence("BATCH_STEP_EXECUTION_SEQ");
            Insert(@"TestData\DbDao\StepExecutionTestData1.xml");
            var stepExecution = new StepExecution("TestStep", _jobExecution);

            _stepExecutionDao.SaveStepExecution(stepExecution);

            Assert.AreEqual(1, stepExecution.Id);
            Assert.AreEqual(0, stepExecution.Version);
        }
        public void TestSaveExecutionContextStep1()
        {
            var jobExecution = new JobExecution(1);
            var execution = new StepExecution("testStep", jobExecution, 2);
            var originalContext = new ExecutionContext();
            execution.ExecutionContext = originalContext;

            _executionContextDao.SaveExecutionContext(execution);
            var context = _executionContextDao.GetExecutionContext(execution);

            Assert.AreEqual(originalContext, context);
        }
        public void TestUpdateStepExecution1()
        {
            var stepExecution = new StepExecution("testStep", _jobExecution);
            _stepExecutionDao.SaveStepExecution(stepExecution);
            stepExecution.BatchStatus = BatchStatus.Completed;

            _stepExecutionDao.UpdateStepExecution(stepExecution);
            var persisted = _stepExecutionDao.GetStepExecution(_jobExecution, 1);

            Assert.AreEqual(1, stepExecution.Version);
            Assert.AreEqual(BatchStatus.Completed, persisted.BatchStatus);
        }
        /// <summary>
        /// Equals override.
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public override bool Equals(Object obj)
        {
            Object jobExecutionId = GetJobExecutionId();

            if (jobExecutionId == null || !(obj is StepExecution) || Id == null)
            {
                return(base.Equals(obj));
            }
            StepExecution other = (StepExecution)obj;

            return(_stepName.Equals(other.StepName) && (jobExecutionId.Equals(other.GetJobExecutionId()) &&
                                                        Id.Equals(other.Id)));
        }
        public void TestSaveExecutionContextStep1()
        {
            Insert(@"TestData\DbDao\ExecutionContextTestData.xml");
            var jobExecution = new JobExecution(1);
            var execution = new StepExecution("TestStep", jobExecution, 1);
            var originalContext = new ExecutionContext();
            execution.ExecutionContext = originalContext;

            _executionContextDao.SaveExecutionContext(execution);
            var context = _executionContextDao.GetExecutionContext(execution);

            Assert.AreEqual(originalContext, context);
        }
Beispiel #14
0
 /// <summary>
 /// Add some step executions.  For internal use only.
 /// </summary>
 /// <param name="stepExecutions">step executions to add to the current list</param>
 public void AddStepExecutions(IList <StepExecution> stepExecutions)
 {
     if (stepExecutions != null)
     {
         foreach (StepExecution item in stepExecutions)
         {
             StepExecution removedItem = item;
             _stepExecutions.TryTake(out removedItem);
         }
         foreach (StepExecution item in stepExecutions)
         {
             _stepExecutions.TryAdd(item);
         }
     }
 }
        public void TestSaveStepExecutions()
        {
            var stepExecution1 = new StepExecution("testStep", _jobExecution);
            var stepExecution2 = new StepExecution("testStep", _jobExecution);
            ICollection<StepExecution> executions = new List<StepExecution>();
            executions.Add(stepExecution1);
            executions.Add(stepExecution2);

            _stepExecutionDao.SaveStepExecutions(executions);

            Assert.AreEqual(1L, stepExecution1.Id);
            Assert.AreEqual(0, stepExecution1.Version);
            Assert.AreEqual(2L, stepExecution2.Id);
            Assert.AreEqual(0, stepExecution2.Version);
        }
        public void TestSaveStepExecutions()
        {
            ResetSequence("BATCH_STEP_EXECUTION_SEQ");
            Insert(@"TestData\DbDao\StepExecutionTestData1.xml");
            var stepExecution1 = new StepExecution("TestStep", _jobExecution);
            var stepExecution2 = new StepExecution("TestStep", _jobExecution);
            ICollection<StepExecution> executions = new List<StepExecution>();
            executions.Add(stepExecution1);
            executions.Add(stepExecution2);

            _stepExecutionDao.SaveStepExecutions(executions);

            Assert.AreEqual(1, stepExecution1.Id);
            Assert.AreEqual(0, stepExecution1.Version);
            Assert.AreEqual(2, stepExecution2.Id);
            Assert.AreEqual(0, stepExecution2.Version);
        }
 /// <summary>
 /// Logic launched after the step. Will launch the postprocessor.
 /// @see IStepExecutionListener#AfterStep
 /// </summary>
 /// <param name="stepExecution"></param>
 /// <returns></returns>
 public virtual ExitStatus AfterStep(StepExecution stepExecution)
 {
     ExitStatus returnStatus = stepExecution.ExitStatus;
     if (!"FAILED".Equals(returnStatus.ExitCode))
     {
         try
         {
             returnStatus = Postprocess();
         }
         catch (Exception e)
         {
             // Need to catch exception to log and set status to FAILED, while
             // Spring batch would only log and keep the status COMPLETED
             Logger.Error(e, "Exception during postprocessor");
             returnStatus = ExitStatus.Failed;
         }
     }
     return returnStatus;
 }
Beispiel #18
0
 /// <summary>
 /// Registers a step execution with the current job execution.
 /// </summary>
 /// <param name="stepName"></param>
 /// <returns>the name of the step the new execution is associated with</returns>
 public StepExecution CreateStepExecution(string stepName)
 {
     StepExecution stepExecution = new StepExecution(stepName, this);
     _stepExecutions.TryAdd(stepExecution);
     return stepExecution;
 }
        public void TestSaveExecutionContextStep2()
        {
            var jobExecution = new JobExecution(1);
            var execution = new StepExecution("testStep", jobExecution, 2);
            var originalContext = new ExecutionContext();
            execution.ExecutionContext = originalContext;
            originalContext.PutString("test1", "test1");
            originalContext.PutLong("test2", 2L);

            _executionContextDao.SaveExecutionContext(execution);
            var context = _executionContextDao.GetExecutionContext(execution);

            Assert.AreEqual(originalContext, context);
        }
Beispiel #20
0
 /// <summary>
 /// Method for re-constituting the step executions from
 /// existing instances.
 /// </summary>
 /// <param name="stepExecution"></param>
 public void AddStepExecution(StepExecution stepExecution)
 {
     _stepExecutions.TryAdd(stepExecution);
 }
Beispiel #21
0
 /// <summary>
 /// Custom constructor using a step execution.
 /// </summary>
 /// <param name="execution"></param>
 public StepContribution(StepExecution execution)
 {
     _parentSkipCount = execution.SkipCount;
 }
        public void TestAddStepExecutions1()
        {
            var stepExecution = new StepExecution("testStep", _jobExecution);
            _stepExecutionDao.SaveStepExecution(stepExecution);

            _stepExecutionDao.AddStepExecutions(_jobExecution);

            Assert.AreEqual(1, _jobExecution.StepExecutions.Count);
            Assert.IsTrue(_jobExecution.StepExecutions.Contains(stepExecution));
        }
        public void TestSaveExecutionContexts()
        {
            Insert(@"TestData\DbDao\ExecutionContextTestData.xml");
            var jobExecution = new JobExecution(1);
            var execution1 = new StepExecution("TestStep", jobExecution, 1);
            var execution2 = new StepExecution("TestStep", jobExecution, 2);
            execution1.ExecutionContext = new ExecutionContext();
            execution2.ExecutionContext = new ExecutionContext();
            execution2.ExecutionContext.PutString("test1", "test1");
            execution2.ExecutionContext.PutLong("test2", 2L);

            IList<StepExecution> executions = new List<StepExecution>();
            executions.Add(execution1);
            executions.Add(execution2);
            _executionContextDao.SaveExecutionContexts(executions);
            var context1 = _executionContextDao.GetExecutionContext(execution1);
            var context2 = _executionContextDao.GetExecutionContext(execution2);

            Assert.AreEqual(execution1.ExecutionContext, context1);
            Assert.AreEqual(execution2.ExecutionContext, context2);
        }
Beispiel #24
0
 /// <summary>
 /// Method for re-constituting the step executions from
 /// existing instances.
 /// </summary>
 /// <param name="stepExecution"></param>
 public void AddStepExecution(StepExecution stepExecution)
 {
     _stepExecutions.TryAdd(stepExecution);
 }
 /// <summary>
 /// @see IStepExecutionListener#AfterStep
 ///  Launched after the step. Not used, thus does nothing.
 /// </summary>
 /// <param name="stepExecution"></param>
 /// <returns></returns>
 public ExitStatus AfterStep(StepExecution stepExecution)
 {
     return ExitStatus.Completed;
 }
        /// <summary>
        /// Logic launched before the step. Will register the contexts and launch the preprocessor.
        /// @see IStepExecutionListener#BeforeStep
        /// </summary>
        /// <param name="stepExecution"></param>
        public virtual void BeforeStep(StepExecution stepExecution)
        {
            RegisterContexts(stepExecution);
            Preprocess();

        }
        public void TestAddStepExecutions1()
        {
            Insert(@"TestData\DbDao\StepExecutionTestData2.xml");
            var stepExecution = new StepExecution("TestStep", _jobExecution, 1);

            _stepExecutionDao.AddStepExecutions(_jobExecution);

            Assert.AreEqual(1, _jobExecution.StepExecutions.Count);
            Assert.IsTrue(_jobExecution.StepExecutions.Contains(stepExecution));
        }
 public void BeforeStep(StepExecution stepExecution)
 {
     _logger.Info("Starting uppercase test with seperate listener");
 }
 /// <summary>
 /// Do nothing before step
 /// </summary>
 /// <param name="stepExecution"></param>
 public void BeforeStep(StepExecution stepExecution)
 {
     // Do nothing
 }
            public ExitStatus AfterStep(StepExecution stepExecution)
            {
                JobExecution job = stepExecution.JobExecution;
                var jobName = job.JobInstance.JobName;

                var filePathName = Path.Combine(TestDataDirectoryLogs, "1_" + jobName + "_" + job.StartTime.Value.Ticks+ ".log");
                FileInfo fInfo = new FileInfo(filePathName);

                using (StreamWriter logSW = new StreamWriter(fInfo.FullName, true))
                {
                    logSW.WriteLine("Job Name: " + jobName + ", Id: " + job.Id + " ended with BatchError.");
                    for (int i = job.StepExecutions.Count - 1; i > 0; i--)
                    {
                        var stepName = job.StepExecutions.ElementAt(i).StepName;
                        var exitCode = job.StepExecutions.ElementAt(i).ExitStatus.ExitCode;
                        var batchStatus = job.StepExecutions.ElementAt(i).BatchStatus;
                        var summary = job.StepExecutions.ElementAt(i).GetSummary();
                        ICollection<Exception> exceptions = job.StepExecutions.ElementAt(i).GetFailureExceptions();

                        logSW.WriteLine(summary);
                        logSW.WriteLine("Step: " + stepName + ", Batch Status: " + batchStatus + ", Exit Status: " + exitCode);
                        for (int j = 0; j < exceptions.Count; j++)
                        {
                            logSW.WriteLine("Exception @ Step[" + stepName + "]: " + exceptions.ElementAt(j).InnerException);
                        }
                    }
                }

                return ExitStatus.Completed;
            }
 public ExitStatus AfterStep(StepExecution stepExecution)
 {
     _logger.Info("Ending uppercase test with seperate listener");
     return ExitStatus.Completed;
 }
        public void TestUpdateStepExecution1()
        {
            Insert(@"TestData\DbDao\StepExecutionTestData2.xml");
            var stepExecution = new StepExecution("TestStep", _jobExecution, 1)
            {
                BatchStatus = BatchStatus.Completed,
                Version = 0
            };

            _stepExecutionDao.UpdateStepExecution(stepExecution);
            var persisted = _stepExecutionDao.GetStepExecution(_jobExecution, 1);

            Assert.AreEqual(1, stepExecution.Version);
            Assert.AreEqual(BatchStatus.Completed, persisted.BatchStatus);
        }
Beispiel #33
0
 /// <summary>
 /// Custom constructor using a step execution.
 /// </summary>
 /// <param name="execution"></param>
 public StepContribution(StepExecution execution)
 {
     _parentSkipCount = execution.SkipCount;
 }
 /// <summary>
 /// registers both job and step contexts.
 /// </summary>
 /// <param name="stepExecution"></param>
 private void RegisterContexts(StepExecution stepExecution)
 {
     JobExecution jobExecution = stepExecution.JobExecution;
     JobContextManager.Context = jobExecution.ExecutionContext;
     StepContextManager.Context = stepExecution.ExecutionContext;
 }
        public void TestUpdateStepExecution2()
        {
            Insert(@"TestData\DbDao\StepExecutionTestData2.xml");
            var stepExecution = new StepExecution("TestStep", _jobExecution) { Version = 1 };

            _stepExecutionDao.UpdateStepExecution(stepExecution);
        }
 /// <summary>
 /// see IStepExecutionListener#AfterStep
 /// </summary>
 /// <param name="stepExecution"></param>
 /// <returns></returns>
 public ExitStatus AfterStep(StepExecution stepExecution)
 {
     return new ExitStatus("OK");
 }