Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Limit thread synchronization in AbstractRequestExpectationManager [SPR-16319] #20866

Closed
spring-issuemaster opened this issue Dec 21, 2017 · 1 comment

Comments

Projects
None yet
2 participants
@spring-issuemaster
Copy link
Collaborator

commented Dec 21, 2017

Mathieu POUSSE opened SPR-16319 and commented

I am using the MockRestServiceServer to simulate calls to some external system.
My application uses parallel requests and I'd like to simulate this case in the test.

Therefore, I'd like to add a delay before the response is returned to the RestTemplate.

This can easily done this way:

this.server.expect(...).andExpect(method(HttpMethod.GET))
        .andRespond(
                request -> {
                    waitABit();
                    return withSuccess(...).createResponse(request);
                });

Unfortunately, the way AbstractRequestExpectationManager is currently written lock the MockServer until the response for the current request has been returned (because of this synchronized block

)

I am wondering if we can exclude the call to validateRequestInternal(request) from the synchronized block.

The current behavior of expectation validation will remain as is, but the response generation will not block the other threads.

cc #1626


Affects: 5.0.2

Issue Links:

  • #19027 Support timeout settings in MockRestServiceServer

Referenced from: pull request #1626, and commits 0c28928

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

commented Jan 17, 2018

Rossen Stoyanchev commented

As I mentioned on the attached PR it was a bit more complicated. The base class had to be restructured so that only response creation is done outside the synchronized block.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.