Hi guys,
I’m currently evaluating the event store and I have been trying to write some tests around the idempotency guarantee described in https://github.com/eventstore/eventstore/wiki/Optimistic-Concurrency-&-Idempotence.
According to the documentation saving events with the same stream name and event ID should only create one event. When the ExpectedVersion.Any, saving the event multiple times only creates one event which is great.
However when I save the same event but with incrementing expected version, it creates multiple event. Is this an expected behaviour?
Here’s a snippet of my test which is testing at a low level to ensure it is not my implementation that’s skewing the result.
var eventsToSave = new List { CreateEventData(aggregate) };
using (var connection = EventStoreConnection.Create(ConnectionSettings.Create()))
{
connection.Connect(new IPEndPoint(IPAddress.Loopback, 1113));
connection.AppendToStream(aggregate.GroupId, ExpectedVersion.NoStream, eventsToSave);
// This shouldn’t create a new entry but this line does.
connection.AppendToStream(aggregate.GroupId, 1, eventsToSave);
connection.AppendToStream(aggregate.GroupId, 1, eventsToSave);
connection.AppendToStream(aggregate.GroupId, ExpectedVersion.Any, eventsToSave);
}
var events = EventStoreFactory.Create().GetEventsByGroupId(aggregate.GroupId);
Assert.AreEqual(1, events.Count());
``
The test fails from getting 2 events rather than 1. The first save creates a new stream and an event. The second save creates a duplicate and the third save does not create a new event.
This is a potential problem for us because AFAIK there is no way for me to know if my previous save created an event or not to ensure I don’t increment the version number that I should expect.
Please shed some light.
Thanks,
Ron