Refine search
@Test public void testResourceNotExists() throws Exception { JobExecution jobExecution = launcher.run(job2, new JobParameters()); Assert.isTrue(jobExecution.getExitStatus().getExitCode().equals("FAILED"), "The job exit status is not FAILED."); Assert.isTrue(jobExecution.getAllFailureExceptions().get(0).getMessage().contains("Failed to initialize the reader"), "The job failed for the wrong reason."); }
@Override public void execute(JobExecution execution) throws UnexpectedJobExecutionException { assertEquals(1, execution.getJobParameters().getParameters().size()); execution.setStatus(BatchStatus.FAILED); execution.setEndTime(new Date()); jobRepository.update(execution); throw new RuntimeException("FOO"); } @Override
private void baseJobParametersVerify(JobParameters parameters, int paramCount) { assertEquals(date, parameters.getDate("SCHEDULE_DATE")); assertEquals(1L, parameters.getLong("LONG").longValue()); assertEquals("string value", parameters.getString("STRING")); assertEquals(paramCount, parameters.getParameters().size()); }
protected Properties getJobRestartProperties(Properties params, org.springframework.batch.core.JobExecution previousJobExecution) { Properties jobRestartProperties = new Properties(); if (previousJobExecution != null) { JobParameters previousJobParameters = previousJobExecution.getJobParameters(); if (previousJobParameters != null && !previousJobParameters.isEmpty()) { jobRestartProperties.putAll(previousJobParameters.toProperties()); } } if (params != null) { Enumeration<?> propertyNames = params.propertyNames(); while(propertyNames.hasMoreElements()) { String curName = (String) propertyNames.nextElement(); jobRestartProperties.setProperty(curName, params.getProperty(curName)); } } return jobRestartProperties; }
/** * Set up a {@link SimpleCompletionPolicy} with a commit interval taken from * the {@link JobParameters}. If there is a Long parameter with the given * key name, the intValue of this parameter is used. If not an exception * will be thrown. * * @see org.springframework.batch.core.listener.StepExecutionListenerSupport#beforeStep(org.springframework.batch.core.StepExecution) */ @Override public void beforeStep(StepExecution stepExecution) { JobParameters jobParameters = stepExecution.getJobParameters(); Assert.state(jobParameters.getParameters().containsKey(keyName), "JobParameters do not contain Long parameter with key=[" + keyName + "]"); delegate = new SimpleCompletionPolicy(jobParameters.getLong(keyName).intValue()); }
/** * Increment the run.id parameter (starting with 1). */ @Override public JobParameters getNext(@Nullable JobParameters parameters) { JobParameters params = (parameters == null) ? new JobParameters() : parameters; long id = params.getLong(key, new Long(0)) + 1; return new JobParametersBuilder(params).addLong(key, id).toJobParameters(); }
@Test public void test() throws Exception { JobExecution execution = jobLauncher.run(job, new JobParameters()); assertEquals(BatchStatus.COMPLETED, execution.getStatus()); assertEquals(3, execution.getStepExecutions().size()); }
@Test public void test() throws Exception { // Run 1 JobExecution jobExecution1 = jobLauncher.run(job, new JobParameters()); assertEquals(BatchStatus.STOPPED, jobExecution1.getStatus()); // Run 2 JobExecution jobExecution2 = jobLauncher.run(job, new JobParameters()); assertEquals(BatchStatus.STOPPED, jobExecution2.getStatus()); }
Assert.isTrue(parameters == null || parameters.length == 0 || !jobParameters.isEmpty(), "Invalid JobParameters " + Arrays.asList(parameters) + ". If parameters are provided they should be in the form name=value (no whitespace)."); jobExecution.setStatus(BatchStatus.STOPPING); jobRepository.update(jobExecution); jobExecution.setStatus(BatchStatus.ABANDONED); jobRepository.update(jobExecution); + jobIdentifier); jobParameters = jobExecution.getJobParameters(); jobName = jobExecution.getJobInstance().getJobName();
/** * Copy constructor. Initializes the builder with the supplied parameters. * @param jobParameters {@link JobParameters} instance used to initialize the builder. * @param jobExplorer {@link JobExplorer} used for looking up previous job parameter information */ public JobParametersBuilder(JobParameters jobParameters, JobExplorer jobExplorer) { this.jobExplorer = jobExplorer; this.parameterMap = new LinkedHashMap<>(jobParameters.getParameters()); }
@Transactional @Test public void testGetLastJobExecution() { JobExecution lastExecution = new JobExecution(jobInstance, jobParameters); lastExecution.setStatus(BatchStatus.STARTED); int JUMP_INTO_FUTURE = 1000; // makes sure start time is 'greatest' lastExecution.setCreateTime(new Date(System.currentTimeMillis() + JUMP_INTO_FUTURE)); jobExecutionDao.saveJobExecution(lastExecution); assertEquals(lastExecution, jobExecutionDao.getLastJobExecution(jobInstance)); assertNotNull(lastExecution.getJobParameters()); assertEquals("jobKey", lastExecution.getJobParameters().getString("job.key")); }
@BeforeTransaction public void onSetUpBeforeTransaction() throws Exception { StepExecution stepExecution = new StepExecution("stepName", new JobExecution(new JobInstance(jobId, "testJob"), new JobParameters())); writer.beforeStep(stepExecution); writer.write(Arrays.asList("FOO", "BAR", "SPAM", "BUCKET")); reader.beforeStep(stepExecution); }
@Test public void testGetStepExecutionSummariesSunnyDay() throws Exception { jobParameters = new JobParameters(); JobExecution jobExecution = new JobExecution(new JobInstance(123L, job.getName()), 111L, jobParameters, null); jobExecution.createStepExecution("step1"); jobExecution.createStepExecution("step2"); jobExecution.getStepExecutions().iterator().next().setId(21L); when(jobExplorer.getJobExecution(111L)).thenReturn(jobExecution); Map<Long, String> value = jobOperator.getStepExecutionSummaries(111L); assertEquals(2, value.size()); }
@Override public void beforeJob(JobExecution jobExecution) { Date date = jobExecution.getJobParameters().getDate("date"); MDC.put(JOB_EXECUTION_ID, jobExecution.getId().toString()); MDC.put(JOB_INSTANCE_ID, jobExecution.getJobId().toString()); MDC.put(DATE_PARAMETER, new SimpleDateFormat("yyyy-MM-dd").format(date)); }
@Override public void run() { try { JobExecution jobExecution = new JobExecution(new JobInstance((long) -1, "mapJob"), new JobParameters()); latch.await(); tested.saveJobExecution(jobExecution); ids.add(jobExecution.getId()); } catch(Exception e) { exception.set(e); } } };
@Test public void testValidRun() throws Exception { JobExecution jobExecution = jobLauncher.run(job1, new JobParameters()); //Ensure job completed successfully. Assert.isTrue(jobExecution.getExitStatus().equals(ExitStatus.COMPLETED), "Step Execution did not complete normally: " + jobExecution.getExitStatus()); //Check output. Assert.isTrue(actual.exists(), "Actual does not exist."); compareFiles(expected.getFile(), actual.getFile()); }
/** * @return a map containing the items from the {@link JobParameters} */ public Map<String, Object> getJobParameters() { Map<String, Object> result = new HashMap<>(); for (Entry<String, JobParameter> entry : jobExecution.getJobParameters().getParameters() .entrySet()) { result.put(entry.getKey(), entry.getValue().getValue()); } return Collections.unmodifiableMap(result); }
@Test public void testJobParameters() { JobParameters params = new JobParametersBuilder() .addString("key1", "value1") .toJobParameters(); when(execution.getJobParameters()).thenReturn(params); assertEquals("value1", execution.getJobParameters().getString("key1")); }
@SuppressWarnings({"unchecked", "rawtypes"}) private GenericMessage<ChunkRequest> getSimpleMessage(String string, Long jobId) { StepContribution stepContribution = new JobExecution(new JobInstance(0L, "job"), new JobParameters()) .createStepExecution("step").createStepContribution(); ChunkRequest chunk = new ChunkRequest(0, StringUtils.commaDelimitedListToSet(string), jobId, stepContribution); GenericMessage<ChunkRequest> message = new GenericMessage<>(chunk); return message; }
@Test public void testDateReturnsNullWhenKeyDoesntExit(){ assertNull(new JobParameters().getDate("keythatdoesntexist")); } }