public async Task Should_append_events_and_publish() { var commitId = Guid.NewGuid(); var event1 = new MyEvent(); var event2 = new MyEvent(); var eventData1 = new EventData(); var eventData2 = new EventData(); A.CallTo(() => formatter.ToEventData(A <Envelope <IEvent> > .That.Matches(e => e.Payload == event1), commitId, true)) .Returns(eventData1); A.CallTo(() => formatter.ToEventData(A <Envelope <IEvent> > .That.Matches(e => e.Payload == event2), commitId, true)) .Returns(eventData2); A.CallTo(() => eventStore.AppendEventsAsync(commitId, streamName, 123, A <ICollection <EventData> > .That.Matches(e => e.Count == 2))) .Returns(TaskHelper.Done); domainObject.AddEvent(event1); domainObject.AddEvent(event2); await sut.SaveAsync(domainObject, domainObject.GetUncomittedEvents(), commitId); A.CallTo(() => eventStore.AppendEventsAsync(commitId, streamName, 123, A <ICollection <EventData> > .That.Matches(e => e.Count == 2))).MustHaveHappened(); }
public long Run() { var streamName = Guid.NewGuid().ToString(); for (var eventId = 0; eventId < NumEvents; eventId++) { var eventData = formatter.ToEventData(new Envelope <IEvent>(new MyEvent { EventNumber = eventId + 1 }), Guid.NewGuid()); eventStore.AppendEventsAsync(Guid.NewGuid(), streamName, eventId - 1, new [] { eventData }).Wait(); } eventConsumer.Wait(); if (eventConsumer.EventNumbers.Count != NumEvents) { throw new InvalidOperationException($"{eventConsumer.EventNumbers.Count} Events have been handled"); } for (var i = 0; i < eventConsumer.EventNumbers.Count; i++) { var value = eventConsumer.EventNumbers[i]; if (value != i + 1) { throw new InvalidOperationException($"Event[{i}] != value"); } } return(NumEvents); }
public long Run() { var streamName = Guid.NewGuid().ToString(); for (var eventId = 0; eventId < NumEvents; eventId++) { var eventData = formatter.ToEventData(new Envelope <IEvent>(new MyEvent { EventNumber = eventId + 1 }), Guid.NewGuid()); eventStore.AppendEventsAsync(Guid.NewGuid(), streamName, eventId - 1, new [] { eventData }).Wait(); } eventConsumer.WaitAndVerify(); return(NumEvents); }
public async Task SaveAsync(IAggregate domainObject, ICollection <Envelope <IEvent> > events, Guid commitId) { Guard.NotNull(domainObject, nameof(domainObject)); var streamName = nameResolver.GetStreamName(domainObject.GetType(), domainObject.Id); var versionCurrent = domainObject.Version; var versionExpected = versionCurrent - events.Count; var eventsToSave = events.Select(x => formatter.ToEventData(x, commitId)).ToList(); try { await eventStore.AppendEventsAsync(commitId, streamName, versionExpected, eventsToSave); } catch (WrongEventVersionException) { throw new DomainObjectVersionException(domainObject.Id.ToString(), domainObject.GetType(), versionCurrent, versionExpected); } }
public long Run() { Parallel.For(0, NumStreams, streamId => { var eventOffset = -1; var streamName = streamId.ToString(); for (var commitId = 0; commitId < NumCommits; commitId++) { var eventData = formatter.ToEventData(new Envelope <IEvent>(new MyEvent()), Guid.NewGuid()); eventStore.AppendEventsAsync(Guid.NewGuid(), streamName, eventOffset - 1, new[] { eventData }).Wait(); eventOffset++; } }); eventConsumer.WaitAndVerify(); return(NumStreams * NumCommits); }