Skip to content

Commit

Permalink
file: fix a race condition where an exchange is missed due to a call …
Browse files Browse the repository at this point in the history
…to mockEndpoint.reset() #3584
  • Loading branch information
aldettinger committed Mar 7, 2022
1 parent 4278b83 commit 40029d1
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -91,17 +91,22 @@ public void startRoute(String routeId) throws Exception {

@Path("/getFromMock/{mockId}")
@GET
public String getFromMock(@PathParam("mockId") String mockId) throws Exception {
public String getFromMock(@PathParam("mockId") String mockId) {
MockEndpoint mockEndpoint = context.getEndpoint("mock:" + mockId, MockEndpoint.class);

String result = mockEndpoint.getExchanges().stream().map(e -> e.getIn().getBody(String.class))
.collect(Collectors.joining(SEPARATOR));

mockEndpoint.reset();

return result;
}

@Path("/resetMock/{mockId}")
@GET
public void resetMock(@PathParam("mockId") String mockId) {
MockEndpoint mockEndpoint = context.getEndpoint("mock:" + mockId, MockEndpoint.class);
mockEndpoint.reset();
}

@Path("/create/{folder}")
@POST
@Consumes(MediaType.APPLICATION_OCTET_STREAM)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,12 @@ public void idempotent() throws IOException {
.extract().asString(),
equalTo(FILE_CONTENT_01));

// clear the mock to assert that FILE_CONTENT_01 will not be received again even if presented a second time to the route
RestAssured
.get("/file/resetMock/idempotent")
.then()
.statusCode(204);

// move file back
Path donePath = Paths.get(fileName01.replaceFirst("target/idempotent", "target/idempotent/done"));
Path targetPath = Paths.get(fileName01);
Expand Down

0 comments on commit 40029d1

Please sign in to comment.