ProcessingGroup not triggered when running cucumber tests

Hi all,

Right now I am experimenting with Axon in a PoC situation for the company I work in, right now I have got a working API with a couple of endpoints.

Now, I wanted to use cucumber to run scenario tests on the API I have just build, but I am encountering something I can not explain.

The example application is a blog API, where there is a database being used to persist the projections when the event was saved. To do this I have used the @ProcessingGroup annotation on a BlogPostProjector. When running, and calling this from the endpoint itself everything works as expected. But when I run it as a scenario in cucumber this processing group is never triggered, and then of course the triggered event does not end up being stored into the database.

the code can be found at:

The actual implementation of the feature file is like this:


<br>package nl.martijnklene.api.infrastructure.glue;<br><br>import;<br>import;<br>import;<br>import nl.martijnklene.api.application.command.CreateBlogPost;<br>import nl.martijnklene.api.application.entity.BlogPost;<br>import nl.martijnklene.api.application.repository.BlogPostRepository;<br>import nl.martijnklene.api.infrastructure.SpringIntegrationTest;<br>import nl.martijnklene.api.infrastructure.model.swagger.BlogPayload;<br>import org.axonframework.commandhandling.gateway.CommandGateway;<br>import org.junit.Assert;<br>import org.springframework.beans.factory.annotation.Autowired;<br><br>import java.util.Date;<br>import java.util.List;<br>import java.util.UUID;<br><br>public class CreateBlogPostSteps extends SpringIntegrationTest {<br> @Autowired<br> private CommandGateway commandGateway;<br> @Autowired<br> private BlogPostRepository blogPostRepository;<br><br> private final UUID generatedUuid = UUID.randomUUID();<br> private final Date createdDate = new Date();<br><br> @When("I submit my request with the following content:$")<br> public void submitRequest(List<BlogPayload> blogPayloads) {<br> for (BlogPayload blogPayload: blogPayloads) {<br> CreateBlogPost createBlogPost = new CreateBlogPost(<br> generatedUuid,<br> blogPayload.getTitle(),<br> blogPayload.getContent(),<br> blogPayload.getTags(),<br> blogPayload.getAuthor(),<br> createdDate<br> );<br> commandGateway.send(createBlogPost);<br> }<br> }<br><br> @Then("a new blog post should have been created")<br> public void blogPostCreated() {<br> BlogPost blogPost = blogPostRepository.findOneById(generatedUuid);<br> Assert.assertEquals(generatedUuid, blogPost.getId());<br> }<br><br> @And("the creation date should be of today")<br> public void creationDateMustBeToday() {<br> BlogPost blogPost = blogPostRepository.findOneById(generatedUuid);<br> Assert.assertEquals(createdDate, blogPost.getCreatedAt());<br> }<br>}<br>


Hi Martijn,

it took me a while to figure out, but the problem was actually quite obvious ;-). You’re using an Async Command Bus. In your test scenario, you’re sending the command and immediately doing a query. The query arrives before the command has finished processing.

A quick fix would be to: commandGateway.send(createBlogPost).join();
Alternatively, you can combine CompletableFuture instances and join once on all of them, allowing the commands to be executed in parallel.




Knew it should be something really easy.

Thanks Allard, scenario testing is working now.