Skip to content

Intermittently breaking test case - SimpleStepFactoryBeanTests.testSimpleConcurrentJob #4949

@isanghaessi

Description

@isanghaessi

I found a test case that breaks intermittently during working on #4755.

@Test
void testSimpleConcurrentJob() throws Exception {
SimpleStepFactoryBean<String, String> factory = getStepFactory("foo", "bar");
factory.setTaskExecutor(new SimpleAsyncTaskExecutor());
AbstractStep step = (AbstractStep) factory.getObject();
step.setName("step1");
JobExecution jobExecution = repository.createJobExecution(job.getName(), new JobParameters());
StepExecution stepExecution = jobExecution.createStepExecution(step.getName());
repository.add(stepExecution);
step.execute(stepExecution);
assertEquals(BatchStatus.COMPLETED, stepExecution.getStatus());
assertEquals(2, written.size());
assertTrue(written.contains("foo"));
}

This test case wants to test concurrent job.
But, used Collections are not thread safe.

private final List<Exception> listened = new ArrayList<>();
private JobRepository repository;
private final List<String> written = new ArrayList<>();
private final ItemWriter<String> writer = data -> written.addAll(data.getItems());
private ItemReader<String> reader = new ListItemReader<>(Arrays.asList("a", "b", "c"));

These collections should be thread safe.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions