public async Task Run() { while (!Volatile.Read(ref _isStoped)) { var currVersion = Volatile.Read(ref _aggregateVersion); var events = _testData.CreateEvents <TestAggregateRoot>( NumEventsPerBucket, AggregateId, currVersion + NumEventsPerBucket + 1); try { var transactionId = _fixture.Create <string>(); await _store.Append(AggregateId, transactionId, currVersion, events); await _store.Commit(AggregateId, transactionId); Interlocked.Add(ref _aggregateVersion, NumEventsPerBucket); Interlocked.Increment(ref _succeededApends); } catch (ConcurrencyException) { Interlocked.Increment(ref _concurrencyErrorsDetected); } } }
public async Task Append_Should_CreateAggregateEntryAndEvents_When_CalledForTheFirstTimeForAggregate() { int numEvents = 5; string aggregateId = _fixture.Create <string>(); int fromVersion = 1; string transactionId = _fixture.Create <string>(); var events = _testData.CreateEvents <TestAggregateRoot>(numEvents, aggregateId, fromVersion).ToArray(); await _store.Append(aggregateId, transactionId, 0, events); var aggregate = await GetAggregate(aggregateId); var eRes = await GetEvents(aggregateId); EventEntity[] eventRes = eRes.ToArray(); Assert.AreEqual(5, aggregate.aggregate_event_seq); Assert.IsNotNull(eventRes); Assert.IsNotEmpty(eventRes); Assert.AreEqual(numEvents, eventRes.Count()); for (int i = 0; i < eventRes.Length; ++i) { var originalEvent = events[i]; var returnedEvent = eventRes[i]; Assert.AreEqual(aggregateId, returnedEvent.aggregate_id); Assert.AreEqual(i + 1, returnedEvent.event_seq); Assert.AreEqual(originalEvent.DateUtc, returnedEvent.timestamp); var returnedPayload = JObject.Parse(returnedEvent.msg_data); Assert.IsTrue(JObject.EqualityComparer.Equals(originalEvent.Payload, returnedPayload)); } }