0

I'm currently putting together integration tests for a Spring Boot / Axon application.

In one of these tests, it (a node) creates another node via SpringApplicationBuilder (under a different profile), connecting to the same Axon Server instance as its creator.

The problem I'm having is that event handling starts to behave weirdly, I believe that any 'common' event handlers on the original application with the second created node get ignored/lost. Everything seems to behave normally when the instances are started outside of the test environment.

My thought is that in the test, the two nodes end up sharing an Instance Name on Axon Server (as they share a processId and hostname), which messes with handler registration/tracking. Does this make sense?

Is there a way that I can manually set this value for nodes connecting to Axon Server so that this doesn't occur during testing?

Morgan
  • 303
  • 2
  • 15

1 Answers1

2

I am not sure which components are started by the outer test application, and which are started by the inner one. Beware that there are multiple aspects that could get in your way here.

  1. AxonServer may be confused and believe the two components are actually the same. Indeed, the hostname and processId for both will be the same, which causes AxonServer to believe it is just dealing with multiple connections from the same application. To circumvent that, you can define a different clientId, using the axon.axonserver.clientId property. Just set that to a random value, and that should take care of that part of the problem.

  2. Another issue is that your components may have tracking processors with the same name. In that case, AxonServer will see both instances of the processor as multiple instances of the same processor, and balance the load between the two (if enough segments are present). If you only have one processing segment available, then only one handler will be active. The other component will not receive any events.

    To circumvent this, prefix the names of your processors with something unique, in your test cases. You can use the EventProcessingConfigurer's assignProcessingGroup(Function<String, String> assignmentRule) method to change the rule of assigning groups to processors. By default, the name of the processor is identical to the name of the group. In your case, you could (based on the test profile you set), add a unique test-related prefix to the processor name. That will 'trick' Axon into believing they are different processors, and need to run concurrently.

I'd recommend trying option 1 first. If that doesn't suffice for the test, you could try the second one as well.

Community
  • 1
  • 1
Allard
  • 2,640
  • 13
  • 13
  • Thank you, your first suggestion worked. I'm not aware if the second is as issue at present but I will update this if it is. – Morgan Feb 08 '19 at 08:48