public async Task RememberConsumedStreamVersionAsync_WhenLatestManuallyCommitedVersionEqualsToStreamCurrent_SkipCommitOnReceiveAsync( [Frozen] StreamVersion version, [Frozen] CommitStreamVersionFMock commitStreamVersionMock, [Frozen] Mock <IEventStreamReader> readerMock, [Frozen] JournaledEvent[] events, EventStreamConsumer consumer) { var streamVersion = version.Increment(events.Length); readerMock .Setup(self => self.StreamVersion) .Returns(streamVersion); await consumer.ReceiveEventsAsync(); var handledEvents = 0; foreach (var e in consumer.EnumerateEvents()) { handledEvents++; await consumer.CommitProcessedStreamVersionAsync(); } await consumer.ReceiveEventsAsync(); Assert.Equal(handledEvents, commitStreamVersionMock.CallsCount); Assert.Equal(streamVersion, commitStreamVersionMock.CommitedVersion); }
public async Task RememberConsumedStreamVersionAsync_WhenSkipCurrentFlagIsTrue_CommitsOnlyProcessedEvents( [Frozen] StreamVersion version, [Frozen] CommitStreamVersionFMock commitStreamVersionMock, [Frozen] Mock <IEventStreamReader> readerMock, [Frozen] JournaledEvent[] events, EventStreamConsumer consumer) { var streamVersion = version.Increment(events.Length); readerMock .Setup(self => self.StreamVersion) .Returns(streamVersion); await consumer.ReceiveEventsAsync(); var handledEvents = 0; foreach (var e in consumer.EnumerateEvents()) { handledEvents++; await consumer.CommitProcessedStreamVersionAsync(skipCurrent : true); } Assert.Equal(handledEvents - 1, commitStreamVersionMock.CallsCount); Assert.Equal(streamVersion.Decrement(), commitStreamVersionMock.CommitedVersion); }
public async Task Execute_ReturnsHeaderWithIncrementedVersion( [Frozen] StreamVersion currentVersion, JournaledEvent[] events, AppendOperation operation) { var targetVersion = currentVersion.Increment(events.Count()); operation.Prepare(events); var result = await operation.ExecuteAsync(); Assert.Equal(targetVersion, result.Version); }
public async Task ReceiveEventsAsync_WhenReceivingWasStarted_CommitsReaderVersion( [Frozen] StreamVersion streamVersion, [Frozen] CommitStreamVersionFMock commitStreamVersionMock, [Frozen] IEventStreamReader reader, EventStreamConsumer consumer) { await consumer.ReceiveEventsAsync(); // starts receiving await consumer.ReceiveEventsAsync(); // continues receiving and commits previous events Assert.Equal(1, commitStreamVersionMock.CallsCount); Assert.Equal(streamVersion.Increment(reader.Events.Count), commitStreamVersionMock.CommitedVersion); }
public Task AddAsync(string streamName, StreamVersion streamVersion, int eventCount) { Require.NotEmpty(streamName, "streamName"); Require.Positive(eventCount, "eventCount"); var operation = m_table.PrepareBatchOperation(); var toVersion = streamVersion.Increment(eventCount); operation.InsertOrReplace( partitionKey: GetPartitionKey(streamName), rowKey: GetRowKey(streamName, streamVersion), propertyName: "ToVersion", propertyValue: (int)toVersion); return(operation.ExecuteAsync()); }
public async Task CloseAsync_WhenReaderHasUnprocessedEventsAndCurrentEventHasBeenCommited_SkipCommit( [Frozen] StreamVersion version, [Frozen] CommitStreamVersionFMock commitStreamVersionMock, EventStreamConsumer consumer) { await consumer.ReceiveEventsAsync(); foreach (var e in consumer.EnumerateEvents()) { await consumer.CommitProcessedStreamVersionAsync(); break; } await consumer.CloseAsync(); Assert.Equal(1, commitStreamVersionMock.CallsCount); Assert.Equal(version.Increment(), commitStreamVersionMock.CommitedVersion); }
public async Task RememberConsumedStreamVersionAsync_WhenEventWasConsumedAndAutoCommitDisabled_CommitsConsumedVersion( [Frozen] StreamVersion version, [Frozen] CommitStreamVersionFMock commitStreamVersionMock, EventStreamConsumer consumer) { await consumer.ReceiveEventsAsync(); var handledEvents = 0; foreach (var e in consumer.EnumerateEvents()) { handledEvents++; await consumer.CommitProcessedStreamVersionAsync(); break; } Assert.Equal(1, commitStreamVersionMock.CallsCount); Assert.Equal(version.Increment(handledEvents), commitStreamVersionMock.CommitedVersion); }
public async Task <FetchEventsResult> FetchStreamEvents(string stream, EventStreamHeader header, StreamVersion fromVersion, int sliceSize) { // fromVersion already in slice var isFetchingCompleted = false; var nextSliceVersion = fromVersion.Increment(sliceSize - 1); if (nextSliceVersion >= header.Version) { nextSliceVersion = header.Version; isFetchingCompleted = true; } const string queryTemplate = "((PartitionKey eq '{0}') and (RowKey eq 'HEAD')) or " + "((PartitionKey eq '{0}') and (RowKey ge '{1}' and RowKey le '{2}'))"; var query = m_table.PrepareEntityFilterRangeQuery( queryTemplate.FormatString( stream, fromVersion.ToString(), nextSliceVersion.ToString())); var queryResult = await query.ExecuteAsync(); var events = new SortedList <StreamVersion, JournaledEvent>(sliceSize); foreach (var properties in queryResult) { var rowKey = (string)properties[KnownProperties.RowKey]; if (!rowKey.EqualsCi("HEAD")) { events.Add(StreamVersion.Parse((string)properties[KnownProperties.RowKey]), JournaledEvent.Create(properties)); } } return(new FetchEventsResult(isFetchingCompleted, events)); }
public async Task CloseAsync_WhenReaderHasUnprocessedEventsAndOnMessagesWasConsumed_CommitsConsumedVersion( [Frozen] StreamVersion version, [Frozen] CommitStreamVersionFMock commitStreamVersionMock, EventStreamConsumer consumer) { await consumer.ReceiveEventsAsync(); var handledEventCount = 0; foreach (var e in consumer.EnumerateEvents()) { if (handledEventCount >= 1) { break; } handledEventCount++; } await consumer.CloseAsync(); Assert.Equal(1, commitStreamVersionMock.CallsCount); Assert.Equal(version.Increment(), commitStreamVersionMock.CommitedVersion); }
private async Task<SortedList<StreamVersion, JournaledEvent>> FetchEvents( string stream, StreamVersion fromVersion, StreamVersion toVersion, int sliceSize) { var nextSliceVersion = fromVersion.Increment(sliceSize); if (nextSliceVersion >= toVersion) { nextSliceVersion = toVersion; } var query = m_table.PrepareEntityFilterRangeQuery( "(PartitionKey eq '{0}') and (RowKey ge '{1}' and RowKey le '{2}')".FormatString( stream, fromVersion.ToString(), nextSliceVersion.ToString()), JournaledEventPropertyNames.All); var queryResult = await query.ExecuteAsync(); var result = new SortedList<StreamVersion, JournaledEvent>(sliceSize); foreach (var properties in queryResult) { result.Add(StreamVersion.Parse((string)properties[KnownProperties.RowKey]), JournaledEvent.Create(properties)); } return result; }