Skip to content

Commit ef3eb49

Browse files
committed
Replace CopyOnWriteArraySet with synchronized List for steps
Change stepExecutions collection in `JobExecutionEvent` from `CopyOnWriteArraySet` to `Collections.synchronizedList(new ArrayList<>())` to preserve the order of step executions. Sets do not maintain insertion order, which can cause issues when processing or displaying step execution history in the correct sequence. This change ensures that step executions are stored and retrieved in the order they were added, which is critical for understanding job execution flow and debugging batch processes. Re-enable previously disabled tests that verify step execution handling and auto-configuration behavior. Remove unused imports and bean definitions that are no longer needed after the Spring Batch 6.x migration.
1 parent c319ed6 commit ef3eb49

File tree

4 files changed

+1
-14
lines changed

4 files changed

+1
-14
lines changed

spring-cloud-task-batch/src/test/java/org/springframework/cloud/task/batch/configuration/TaskJobLauncherAutoConfigurationTests.java

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616

1717
package org.springframework.cloud.task.batch.configuration;
1818

19-
import org.junit.jupiter.api.Disabled;
2019
import org.junit.jupiter.api.Test;
2120

2221
import org.springframework.batch.core.configuration.JobRegistry;
@@ -31,7 +30,6 @@
3130
import org.springframework.boot.autoconfigure.AutoConfigurations;
3231
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
3332
import org.springframework.boot.batch.autoconfigure.BatchAutoConfiguration;
34-
import org.springframework.boot.batch.autoconfigure.BatchProperties;
3533
import org.springframework.boot.batch.autoconfigure.JobLauncherApplicationRunner;
3634
import org.springframework.boot.jdbc.autoconfigure.EmbeddedDataSourceConfiguration;
3735
import org.springframework.boot.test.context.assertj.AssertableApplicationContext;
@@ -99,7 +97,6 @@ private void validateJobNames(AssertableApplicationContext context, String jobNa
9997
assertThat(names).isEqualTo(jobNames);
10098
}
10199

102-
@Disabled
103100
@Test
104101
public void testAutoBuiltDataSourceWithTaskJobLauncherCLRDisabled() {
105102
this.contextRunner.run(context -> {
@@ -133,11 +130,6 @@ JobRegistry jobRegistry() {
133130
return new MapJobRegistry();
134131
}
135132

136-
@Bean
137-
BatchProperties batchProperties() {
138-
return new BatchProperties();
139-
}
140-
141133
}
142134

143135
}

spring-cloud-task-stream/src/main/java/org/springframework/cloud/task/batch/listener/support/JobExecutionEvent.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
import java.util.List;
2525
import java.util.Set;
2626
import java.util.concurrent.CopyOnWriteArrayList;
27-
import java.util.concurrent.CopyOnWriteArraySet;
2827

2928
import org.springframework.batch.core.BatchStatus;
3029
import org.springframework.batch.core.Entity;
@@ -44,7 +43,7 @@ public class JobExecutionEvent extends Entity {
4443

4544
private JobInstanceEvent jobInstance;
4645

47-
private Collection<StepExecutionEvent> stepExecutions = new CopyOnWriteArraySet<>();
46+
private Collection<StepExecutionEvent> stepExecutions = Collections.synchronizedList(new ArrayList<>());
4847

4948
private BatchStatus status = BatchStatus.STARTING;
5049

spring-cloud-task-stream/src/main/java/org/springframework/cloud/task/batch/listener/support/StepExecutionEvent.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,6 @@ public StepExecutionEvent(StepExecution stepExecution) {
107107
this.rollbackCount = stepExecution.getRollbackCount();
108108
this.writeCount = stepExecution.getWriteCount();
109109
this.writeSkipCount = stepExecution.getWriteSkipCount();
110-
111110
}
112111

113112
/**

spring-cloud-task-stream/src/test/java/org/springframework/cloud/task/batch/listener/JobExecutionEventTests.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
import java.util.Set;
2626

2727
import org.junit.jupiter.api.BeforeEach;
28-
import org.junit.jupiter.api.Disabled;
2928
import org.junit.jupiter.api.Test;
3029

3130
import org.springframework.batch.core.BatchStatus;
@@ -74,7 +73,6 @@ public class JobExecutionEventTests {
7473

7574
private JobInstance jobInstance;
7675

77-
//
7876
@BeforeEach
7977
public void setup() {
8078
this.jobInstance = new JobInstance(JOB_INSTANCE_ID, JOB_NAME);
@@ -119,7 +117,6 @@ public void testJobParameters() {
119117
new JobParameterEvent(PARAMETERS[3]));
120118
}
121119

122-
@Disabled
123120
@Test
124121
public void testStepExecutions() {
125122
JobExecution jobExecution;

0 commit comments

Comments
 (0)