本文整理了Java中org.springframework.batch.item.ExecutionContext.isEmpty()
方法的一些代码示例,展示了ExecutionContext.isEmpty()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ExecutionContext.isEmpty()
方法的具体详情如下:
包路径:org.springframework.batch.item.ExecutionContext
类名称:ExecutionContext
方法名:isEmpty
[英]Indicates whether or not the context is empty.
[中]指示上下文是否为空。
代码示例来源:origin: spring-projects/spring-batch
@Test
public void testIsEmpty() {
assertTrue(context.isEmpty());
context.putString("1", "test");
assertFalse(context.isEmpty());
}
代码示例来源:origin: spring-projects/spring-batch
if (jobExecutionContext != null && !jobExecutionContext.isEmpty()) {
job.setJobExecutionListeners(new JobExecutionListener[] { new JobExecutionListenerSupport() {
@Override
代码示例来源:origin: spring-projects/spring-batch
@Test
public void testCopyConstructorNullInput() throws Exception {
ExecutionContext context = new ExecutionContext((ExecutionContext) null);
assertTrue(context.isEmpty());
}
代码示例来源:origin: spring-projects/spring-batch
/**
* Execution context should be restored on restart.
*/
@Test
public void testRestartAndExecutionContextRestored() throws Exception {
job.setRestartable(true);
step1.setAllowStartIfComplete(true);
final RuntimeException exception = new RuntimeException("Foo!");
step2.setProcessException(exception);
job.execute(jobExecution);
assertEquals(1, jobExecution.getAllFailureExceptions().size());
Throwable e = jobExecution.getAllFailureExceptions().get(0);
assertSame(exception, e);
assertTrue(step1.passedInJobContext.isEmpty());
assertFalse(step2.passedInJobContext.isEmpty());
assertFalse(jobExecution.getExecutionContext().isEmpty());
jobExecution = jobRepository.createJobExecution(job.getName(), jobParameters);
job.execute(jobExecution);
assertEquals(1, jobExecution.getAllFailureExceptions().size());
e = jobExecution.getAllFailureExceptions().get(0);
assertSame(exception, e);
assertFalse(step1.passedInJobContext.isEmpty());
assertFalse(step2.passedInJobContext.isEmpty());
}
代码示例来源:origin: spring-projects/spring-batch
@Test
public void testRestart() throws Exception {
step1.setAllowStartIfComplete(true);
final RuntimeException exception = new RuntimeException("Foo!");
step2.setProcessException(exception);
job.execute(jobExecution);
Throwable e = jobExecution.getAllFailureExceptions().get(0);
assertSame(exception, e);
jobExecution = jobRepository.createJobExecution(job.getName(), jobParameters);
job.execute(jobExecution);
e = jobExecution.getAllFailureExceptions().get(0);
assertSame(exception, e);
assertTrue(step1.passedInStepContext.isEmpty());
assertFalse(step2.passedInStepContext.isEmpty());
}
代码示例来源:origin: spring-projects/spring-batch
@Test
public void testRunNormally() throws Exception {
step1.setStartLimit(5);
step2.setStartLimit(5);
job.execute(jobExecution);
assertEquals(2, list.size());
checkRepository(BatchStatus.COMPLETED);
assertNotNull(jobExecution.getEndTime());
assertNotNull(jobExecution.getStartTime());
assertTrue(step1.passedInJobContext.isEmpty());
assertFalse(step2.passedInJobContext.isEmpty());
}
代码示例来源:origin: spring-projects/spring-batch
@Test
public void testPersistentCopy() throws Exception {
MapExecutionContextDao tested = new MapExecutionContextDao();
JobExecution jobExecution = new JobExecution((long)1);
StepExecution stepExecution = new StepExecution("stepName", jobExecution, 123L);
assertTrue(stepExecution.getExecutionContext().isEmpty());
tested.updateExecutionContext(stepExecution);
stepExecution.getExecutionContext().put("key","value");
ExecutionContext retrieved = tested.getExecutionContext(stepExecution);
assertTrue(retrieved.isEmpty());
tested.updateExecutionContext(jobExecution);
jobExecution.getExecutionContext().put("key", "value");
retrieved = tested.getExecutionContext(jobExecution);
assertTrue(retrieved.isEmpty());
}
代码示例来源:origin: spring-projects/spring-batch
/**
* CONDITION: keys = {key}. key is already in job but not in step.
*
* EXPECTED: key is not erased.
*/
@Test
public void promoteEntriesKeyNotFoundInStep() throws Exception {
ExecutionContextPromotionListener listener = new ExecutionContextPromotionListener();
JobExecution jobExecution = new JobExecution(1L);
StepExecution stepExecution = jobExecution.createStepExecution("step1");
stepExecution.setExitStatus(ExitStatus.COMPLETED);
Assert.state(jobExecution.getExecutionContext().isEmpty(), "Job ExecutionContext is not empty");
Assert.state(stepExecution.getExecutionContext().isEmpty(), "Step ExecutionContext is not empty");
jobExecution.getExecutionContext().putString(key, value);
listener.setKeys(new String[] { key });
listener.afterPropertiesSet();
listener.afterStep(stepExecution);
assertEquals(value, jobExecution.getExecutionContext().getString(key));
}
代码示例来源:origin: spring-projects/spring-batch
@Test
public void testRestartWithNullParameter() throws Exception {
JobParameters jobParameters = new JobParametersBuilder().addString("foo", null).toJobParameters();
jobExecution = jobRepository.createJobExecution(job.getName(), jobParameters);
jobInstance = jobExecution.getJobInstance();
step1.setAllowStartIfComplete(true);
final RuntimeException exception = new RuntimeException("Foo!");
step2.setProcessException(exception);
job.execute(jobExecution);
Throwable e = jobExecution.getAllFailureExceptions().get(0);
assertSame(exception, e);
jobExecution = jobRepository.createJobExecution(job.getName(), jobParameters);
job.execute(jobExecution);
e = jobExecution.getAllFailureExceptions().get(0);
assertSame(exception, e);
assertTrue(step1.passedInStepContext.isEmpty());
assertFalse(step2.passedInStepContext.isEmpty());
}
代码示例来源:origin: spring-projects/spring-batch
/**
* CONDITION: keys = {key, key2}. Only {key} exists in the ExecutionContext.
*
* EXPECTED: key is promoted. key2 is not.
*/
@Test
public void promoteEntriesKeyNotFound() throws Exception {
ExecutionContextPromotionListener listener = new ExecutionContextPromotionListener();
JobExecution jobExecution = new JobExecution(1L);
StepExecution stepExecution = jobExecution.createStepExecution("step1");
stepExecution.setExitStatus(ExitStatus.COMPLETED);
Assert.state(jobExecution.getExecutionContext().isEmpty(), "Job ExecutionContext is not empty");
Assert.state(stepExecution.getExecutionContext().isEmpty(), "Step ExecutionContext is not empty");
stepExecution.getExecutionContext().putString(key, value);
listener.setKeys(new String[] { key, key2 });
listener.afterPropertiesSet();
listener.afterStep(stepExecution);
assertEquals(value, jobExecution.getExecutionContext().getString(key));
assertFalse(jobExecution.getExecutionContext().containsKey(key2));
}
代码示例来源:origin: spring-projects/spring-batch
/**
* CONDITION: strict = true. keys = {key, key2}. Only {key} exists in the
* ExecutionContext.
*
* EXPECTED: IllegalArgumentException
*/
@Test(expected = IllegalArgumentException.class)
public void promoteEntriesKeyNotFoundStrict() throws Exception {
ExecutionContextPromotionListener listener = new ExecutionContextPromotionListener();
listener.setStrict(true);
JobExecution jobExecution = new JobExecution(1L);
StepExecution stepExecution = jobExecution.createStepExecution("step1");
stepExecution.setExitStatus(ExitStatus.COMPLETED);
Assert.state(jobExecution.getExecutionContext().isEmpty(), "Job ExecutionContext is not empty");
Assert.state(stepExecution.getExecutionContext().isEmpty(), "Step ExecutionContext is not empty");
stepExecution.getExecutionContext().putString(key, value);
listener.setKeys(new String[] { key, key2 });
listener.afterPropertiesSet();
listener.afterStep(stepExecution);
assertEquals(value, jobExecution.getExecutionContext().getString(key));
assertFalse(jobExecution.getExecutionContext().containsKey(key2));
}
代码示例来源:origin: spring-projects/spring-batch
/**
* CONDITION: ExecutionContext contains {key, key2}. keys = {key}. statuses
* is not set (defaults to {COMPLETED}).
*
* EXPECTED: key is promoted. key2 is not.
*/
@Test
public void promoteEntryNullStatuses() throws Exception {
ExecutionContextPromotionListener listener = new ExecutionContextPromotionListener();
JobExecution jobExecution = new JobExecution(1L);
StepExecution stepExecution = jobExecution.createStepExecution("step1");
stepExecution.setExitStatus(ExitStatus.COMPLETED);
Assert.state(jobExecution.getExecutionContext().isEmpty(), "Job ExecutionContext is not empty");
Assert.state(stepExecution.getExecutionContext().isEmpty(), "Step ExecutionContext is not empty");
stepExecution.getExecutionContext().putString(key, value);
stepExecution.getExecutionContext().putString(key2, value2);
listener.setKeys(new String[] { key });
listener.afterPropertiesSet();
listener.afterStep(stepExecution);
assertEquals(value, jobExecution.getExecutionContext().getString(key));
assertFalse(jobExecution.getExecutionContext().containsKey(key2));
}
代码示例来源:origin: spring-projects/spring-batch
/**
* Execution context must not be left empty even if job failed before
* committing first chunk - otherwise ItemStreams won't recognize it is
* restart scenario on next run.
*/
@Test
public void testRestartAfterFailureInFirstChunk() throws Exception {
MockRestartableItemReader reader = new MockRestartableItemReader() {
@Override
public String read() throws RuntimeException {
// fail on the very first item
throw new RuntimeException("CRASH!");
}
};
step.setTasklet(new TestingChunkOrientedTasklet<>(reader, itemWriter));
step.registerStream(reader);
StepExecution stepExecution = new StepExecution(step.getName(), new JobExecution(jobInstance, jobParameters));
step.execute(stepExecution);
assertEquals(BatchStatus.FAILED, stepExecution.getStatus());
Throwable expected = stepExecution.getFailureExceptions().get(0);
assertEquals("CRASH!", expected.getMessage());
assertFalse(stepExecution.getExecutionContext().isEmpty());
assertTrue(stepExecution.getExecutionContext().getString("spam").equals("bucket"));
}
代码示例来源:origin: spring-projects/spring-batch
/**
* CONDITION: ExecutionContext contains {key, key2}. keys = {key, key2}.
* statuses = {status}. ExitStatus = status2
*
* EXPECTED: no promotions.
*/
@Test
public void promoteEntryStatusNotFound() throws Exception {
ExecutionContextPromotionListener listener = new ExecutionContextPromotionListener();
JobExecution jobExecution = new JobExecution(1L);
StepExecution stepExecution = jobExecution.createStepExecution("step1");
stepExecution.setExitStatus(new ExitStatus(status2));
Assert.state(jobExecution.getExecutionContext().isEmpty(), "Job ExecutionContext is not empty");
Assert.state(stepExecution.getExecutionContext().isEmpty(), "Step ExecutionContext is not empty");
stepExecution.getExecutionContext().putString(key, value);
stepExecution.getExecutionContext().putString(key2, value2);
listener.setKeys(new String[] { key });
listener.setStatuses(new String[] { status });
listener.afterPropertiesSet();
listener.afterStep(stepExecution);
assertFalse(jobExecution.getExecutionContext().containsKey(key));
assertFalse(jobExecution.getExecutionContext().containsKey(key2));
}
代码示例来源:origin: spring-projects/spring-batch
/**
* CONDITION: keys = {key, key2}. statuses = {statusWildcard}. ExitStatus =
* status
*
* EXPECTED: key is promoted. key2 is not.
*/
@Test
public void promoteEntryStatusWildcardFound() throws Exception {
ExecutionContextPromotionListener listener = new ExecutionContextPromotionListener();
JobExecution jobExecution = new JobExecution(1L);
StepExecution stepExecution = jobExecution.createStepExecution("step1");
stepExecution.setExitStatus(new ExitStatus(status));
Assert.state(jobExecution.getExecutionContext().isEmpty(), "Job ExecutionContext is not empty");
Assert.state(stepExecution.getExecutionContext().isEmpty(), "Step ExecutionContext is not empty");
stepExecution.getExecutionContext().putString(key, value);
stepExecution.getExecutionContext().putString(key2, value2);
listener.setKeys(new String[] { key });
listener.setStatuses(new String[] { statusWildcard });
listener.afterPropertiesSet();
listener.afterStep(stepExecution);
assertEquals(value, jobExecution.getExecutionContext().getString(key));
assertFalse(jobExecution.getExecutionContext().containsKey(key2));
}
代码示例来源:origin: spring-projects/spring-batch
/**
* CONDITION: ExecutionContext contains {key, key2}. keys = {key, key2}.
* statuses = {status}. ExitStatus = status
*
* EXPECTED: key is promoted. key2 is not.
*/
@Test
public void promoteEntryStatusFound() throws Exception {
ExecutionContextPromotionListener listener = new ExecutionContextPromotionListener();
listener.setStrict(true);
JobExecution jobExecution = new JobExecution(1L);
StepExecution stepExecution = jobExecution.createStepExecution("step1");
stepExecution.setExitStatus(new ExitStatus(status));
Assert.state(jobExecution.getExecutionContext().isEmpty(), "Job ExecutionContext is not empty");
Assert.state(stepExecution.getExecutionContext().isEmpty(), "Step ExecutionContext is not empty");
stepExecution.getExecutionContext().putString(key, value);
stepExecution.getExecutionContext().putString(key2, value2);
listener.setKeys(new String[] { key });
listener.setStatuses(new String[] { status });
listener.afterPropertiesSet();
listener.afterStep(stepExecution);
assertEquals(value, jobExecution.getExecutionContext().getString(key));
assertFalse(jobExecution.getExecutionContext().containsKey(key2));
}
代码示例来源:origin: uk.ac.ebi.intact.dataexchange/intact-db-importer
if (!executionContext.isEmpty()){
for (Map.Entry<String, Object> entry : executionContext.entrySet()){
if (entry.getKey().startsWith(PERSIST_MAP_COUNT+"_")){
内容来源于网络,如有侵权,请联系作者删除!