Skip to content

add batch methods to StubLifecycleListener.#3351

Merged
RafeArnold merged 6 commits into
masterfrom
batch-stub-lifecycle-listener-2
Mar 12, 2026
Merged

add batch methods to StubLifecycleListener.#3351
RafeArnold merged 6 commits into
masterfrom
batch-stub-lifecycle-listener-2

Conversation

@RafeArnold

Copy link
Copy Markdown
Contributor

add batch methods to StubLifecycleListener so that multiple stubs can be processed at once if imported in a batch.

if an import request was set to delete all stubs not imported, and its
duplicate policy was set to IGNORE, the mapping saver would incorrectly
delete any peristed stubs that were ignored during the import.
@RafeArnold RafeArnold requested a review from a team as a code owner March 4, 2026 14:10
@RafeArnold RafeArnold force-pushed the batch-stub-lifecycle-listener-2 branch from cf7e6aa to 8f3cfac Compare March 4, 2026 14:14
to declutter StubLifecycleListener
better practice than using the passed in list.

@Override
public void setNewStub(StubMapping newStub) {
this.newStub = newStub;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Making these mutable seems a bit grubby. Is there no practical immutable alternative?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as far as i can see this is the only reasonable way to replicate the single stub methods, beforeStubCreated and beforeStubEdited, that can return a new stub value to be passed to the next listener/saved. initially i tried to use the return value of beforeStubsAltered in the same way but because its a list of stubs it creates huge potential for misaligned behaviour. the implementor of the listener could completely remove a bunch of stubs from the returned list so they wouldnt be processed. this is not an ability that the listeners have had so far so didnt feel appropriate to add here. i kind of agree that on first sight, the mutability looks a bit nasty, but i actually think it creates quite a clean api for the listener implementors that replicates the api of the single stub methods. to be clear, this mutability only lasts for the duration of the call to this method, so doesnt create the potential for mutable references to hang around and edit stubs at will.

@RafeArnold RafeArnold merged commit 09e560d into master Mar 12, 2026
5 checks passed
@RafeArnold RafeArnold deleted the batch-stub-lifecycle-listener-2 branch March 12, 2026 16:59
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.

3 participants