Skip to content

Conversation

@HongYeseul
Copy link

@HongYeseul HongYeseul commented Jan 11, 2026

Problem

Tests using StepScopeTestUtils with @SpringBatchTest failed with ClassCastException due to ID collisions. MetaDataInstanceFactory always created instances with the same default IDs (123L), causing multiple StepExecution instances to be treated as identical in StepSynchronizationManager.

Solution

Added AtomicLong counters to generate unique IDs for each StepExecution and JobExecution. This prevents context collisions while maintaining backward compatibility—the first invocation still uses the original default IDs.

Changes

  • Added jobExecutionIdCounter and stepExecutionIdCounter static fields
  • Updated createStepExecution(JobParameters) to use incrementAndGet() for unique IDs
  • Added test case to verify unique ID generation

Closes #5181

…tanceFactory to prevent collisions

Signed-off-by: HongYeseul <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

MetaDataInstanceFactory default values cause StepContext collision in StepScopeTestUtils when @SpringBatchTest is active

1 participant