Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Improve MessageChannelPartitionHandler::receiveReplies #4776

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

quaff
Copy link
Contributor

@quaff quaff commented Mar 4, 2025

  1. Message payload not always be Set, if you return payload directly, you will see tests failed:
[main] ERROR org.springframework.batch.core.step.AbstractStep - Encountered an error executing step step1-manager in job job1
java.lang.ClassCastException: class java.util.ArrayList cannot be cast to class java.util.Set (java.util.ArrayList and java.util.Set are in module java.base of loader 'bootstrap')
	at org.springframework.batch.integration.partition.MessageChannelPartitionHandler.receiveReplies(MessageChannelPartitionHandler.java:298)
	at org.springframework.batch.integration.partition.MessageChannelPartitionHandler.doHandle(MessageChannelPartitionHandler.java:244)
	at org.springframework.batch.core.partition.support.AbstractPartitionHandler.handle(AbstractPartitionHandler.java:60)
	at org.springframework.batch.core.partition.support.PartitionStep.doExecute(PartitionStep.java:102)
	at org.springframework.batch.core.step.AbstractStep.execute(AbstractStep.java:230)
	at org.springframework.batch.core.job.SimpleStepHandler.handleStep(SimpleStepHandler.java:153)
	at org.springframework.batch.core.job.flow.JobFlowExecutor.executeStep(JobFlowExecutor.java:68)
	at org.springframework.batch.core.job.flow.support.state.StepState.handle(StepState.java:68)
	at org.springframework.batch.core.job.flow.support.SimpleFlow.resume(SimpleFlow.java:165)
	at org.springframework.batch.core.job.flow.support.SimpleFlow.start(SimpleFlow.java:140)
	at org.springframework.batch.core.job.flow.FlowJob.doExecute(FlowJob.java:132)
	at org.springframework.batch.core.job.AbstractJob.execute(AbstractJob.java:307)
	at org.springframework.batch.core.launch.support.TaskExecutorJobLauncher$1.run(TaskExecutorJobLauncher.java:155)
	at org.springframework.core.task.SyncTaskExecutor.execute(SyncTaskExecutor.java:50)
	at org.springframework.batch.core.launch.support.TaskExecutorJobLauncher.run(TaskExecutorJobLauncher.java:146)
	at org.springframework.batch.integration.partition.VanillaIntegrationTests.testLaunchJob(VanillaIntegrationTests.java:58)
  1. No need to create a new HashSet if payload is Set since no modifications applied to it.

1. Message payload not always be `Set`, if you return payload directly, you will see tests failed:
```
[main] ERROR org.springframework.batch.core.step.AbstractStep - Encountered an error executing step step1-manager in job job1
java.lang.ClassCastException: class java.util.ArrayList cannot be cast to class java.util.Set (java.util.ArrayList and java.util.Set are in module java.base of loader 'bootstrap')
	at org.springframework.batch.integration.partition.MessageChannelPartitionHandler.receiveReplies(MessageChannelPartitionHandler.java:298)
	at org.springframework.batch.integration.partition.MessageChannelPartitionHandler.doHandle(MessageChannelPartitionHandler.java:244)
	at org.springframework.batch.core.partition.support.AbstractPartitionHandler.handle(AbstractPartitionHandler.java:60)
	at org.springframework.batch.core.partition.support.PartitionStep.doExecute(PartitionStep.java:102)
	at org.springframework.batch.core.step.AbstractStep.execute(AbstractStep.java:230)
	at org.springframework.batch.core.job.SimpleStepHandler.handleStep(SimpleStepHandler.java:153)
	at org.springframework.batch.core.job.flow.JobFlowExecutor.executeStep(JobFlowExecutor.java:68)
	at org.springframework.batch.core.job.flow.support.state.StepState.handle(StepState.java:68)
	at org.springframework.batch.core.job.flow.support.SimpleFlow.resume(SimpleFlow.java:165)
	at org.springframework.batch.core.job.flow.support.SimpleFlow.start(SimpleFlow.java:140)
	at org.springframework.batch.core.job.flow.FlowJob.doExecute(FlowJob.java:132)
	at org.springframework.batch.core.job.AbstractJob.execute(AbstractJob.java:307)
	at org.springframework.batch.core.launch.support.TaskExecutorJobLauncher$1.run(TaskExecutorJobLauncher.java:155)
	at org.springframework.core.task.SyncTaskExecutor.execute(SyncTaskExecutor.java:50)
	at org.springframework.batch.core.launch.support.TaskExecutorJobLauncher.run(TaskExecutorJobLauncher.java:146)
	at org.springframework.batch.integration.partition.VanillaIntegrationTests.testLaunchJob(VanillaIntegrationTests.java:58)
```

2. No need to create a new `HashSet` if payload is `Set` since no modifications applied to it.

Signed-off-by: Yanming Zhou <zhouyanming@gmail.com>
@quaff
Copy link
Contributor Author

quaff commented Mar 4, 2025

I think failed tests are not caused by this PR, they fail with other PR too, but passed in local.

Caused by:

java.io.IOException: No such file or directory
	at java.base/java.io.UnixFileSystem.createFileExclusively(Native Method)
	at java.base/java.io.File.createNewFile(File.java:1043)
	at org.springframework.batch.item.file.MultiResourceItemWriter.write(MultiResourceItemWriter.java:80)

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant