public class CommandHandlingBenchmark {
private static final UUID aggregateIdentifier = UUID.randomUUID();
public static void main(String[] args) {
CommandBus cb = new SimpleCommandBus();
InMemoryEventStore eventStore = new InMemoryEventStore();
eventStore.appendInitialEvent("test", new SimpleDomainEventStream(new GenericDomainEventMessage<SomeEvent>(
aggregateIdentifier, 0, new SomeEvent())));
final MyAggregate myAggregate = new MyAggregate(aggregateIdentifier);
Repository<MyAggregate> repository = new Repository<MyAggregate>() {
@Override
public MyAggregate load(Object aggregateIdentifier, Long expectedVersion) {
throw new UnsupportedOperationException("Not implemented yet");
}
@Override
public MyAggregate load(Object aggregateIdentifier) {
return myAggregate;
}
@Override
public void add(MyAggregate aggregate) {
throw new UnsupportedOperationException("Not implemented yet");
}
};
cb.subscribe(String.class.getName(), new MyCommandHandler(repository));
// new AnnotationCommandHandlerAdapter(new MyCommandHandler(repository), cb).subscribe();
long COMMAND_COUNT = 5 * 1000 * 1000;
cb.dispatch(GenericCommandMessage.asCommandMessage("ready,"));
long t1 = System.currentTimeMillis();
for (int t = 0; t < COMMAND_COUNT; t++) {
cb.dispatch(GenericCommandMessage.asCommandMessage("go!"));
}
long t2 = System.currentTimeMillis();
System.out.println(String.format("Just did %d commands per second", ((COMMAND_COUNT * 1000) / (t2 - t1))));
}