Hi,
We have wrote a CommandeHandler that generate several command to create several aggregates.
`
@Component
public class MyFirstCommandHandler
{
private final CommandGateway commandGateway;
public MyFirstCommandHandler(CommandGateway commandGateway)
{
this.commandGateway = commandGateway;
}
@CommandHandler
public void handle(
final InitCommand initCommand)
{
// for example call external api that returns a list of objects to create
List response = asList(“a”, “b”);
response.forEach(s -> commandGateway.send(new CreateMyAggregateCommand(new MyAggregateId(), s)));
}
}
`
The aggregate
`
@Aggregate
@NoArgsConstructor
public class MyAggregate
{
@AggregateIdentifier
private MyAggregateId id;
private String something;
@CommandHandler
public MyAggregate(final CreateMyAggregateCommand command)
{
apply(new MyAggregateCreatedEvent(command.getId(), command.getSomething()));
}
@EventSourcingHandler
public void on(final MyAggregateCreatedEvent event)
{
this.id = event.getId();
this.something = event.getSomething();
System.out.println(event);
}
}
`
And the test corresping to the first command handler
`
public class MyFirstCommandHandlerTest
{
private FixtureConfiguration fixture;
@Before
public void setUp()
throws Exception
{
fixture = new AggregateTestFixture<>(MyAggregate.class);
CommandBus commandBus = fixture.getCommandBus();
DefaultCommandGateway commandGateway = new DefaultCommandGateway(commandBus);
fixture.registerAnnotatedCommandHandler(new MyFirstCommandHandler(commandGateway));
}
@Test
public void testMigrateStream()
throws Exception
{
fixture
.givenNoPriorActivity()
.when(new InitCommand())
.expectSuccessfulHandlerExecution();
}
}
`
The test fail because with the error
`
org.axonframework.test.AxonAssertionError: Illegal state change detected! Property “test.onecommandtwoevents.domain.MyAggregate.id.identifier” has different value when sourcing events.
Working aggregate value: <8802e90d-2764-4daa-97c5-d661ba38918e>
Value after applying events:
`
We don’t know why but the framework try to apply the first emited event to a third instance of the aggregate !!
But when the application run’s normally, we do not have errors.
We have created a minimal project to show the use case :
https://github.com/micolator/test-axon-one-command-two-events
Thanks for your help