Beispiel #1
0
        public EventBatchProducerTests()
        {
            dateTimeProvider  = Substitute.For <IDateTimeProvider>();
            nameProvider      = Substitute.For <IEventNameProvider>();
            eventIdProvider   = Substitute.For <IEventIdProvider>();
            expectedName      = "event-name";
            expectedTimestamp = DateTimeOffset.Now;
            metadata          = new StreamMetadata(
                "id",
                "pk",
                "streamId",
                1,
                StreamState.Active,
                expectedTimestamp.AddDays(-1));
            options = new StreamWriteOptions
            {
                CausationId   = "A",
                CorrelationId = "B",
            };
            @event          = new Fixture().Create <TestEvent>();
            expectedEventId = new Fixture().Create <string>();

            dateTimeProvider
            .GetDateTime()
            .Returns(expectedTimestamp);
            nameProvider
            .GetName(default)
Beispiel #2
0
        public ValueTask <CommandResult> WriteEventAsync(
            TCommand command,
            IReadOnlyCollection <object> events,
            CancellationToken cancellationToken)
        {
            var id            = command.GetEventStreamId();
            var version       = (StreamVersion?)command.RequiredVersion ?? StreamVersion.Any;
            var streamOptions = new StreamWriteOptions
            {
                CausationId   = command.CommandId,
                CorrelationId = command.CorrelationId,
            };

            return(WriteToEventStoreAsync(
                       id.Value,
                       version,
                       streamOptions,
                       events,
                       GetRetries(command),
                       cancellationToken));
        }
Beispiel #3
0
        private async ValueTask <CommandResult> WriteToEventStoreAsync(
            StreamId id,
            StreamVersion version,
            StreamWriteOptions options,
            IReadOnlyCollection <object> events,
            int reties,
            CancellationToken cancellationToken)
        {
            try
            {
                var response = await eventStore
                               .WriteToStreamAsync(
                    id,
                    events,
                    version,
                    options,
                    cancellationToken)
                               .ConfigureAwait(false);

                return(new CommandResult(id, response.Version, ResultType.Changed));
            }
            catch (StreamWriteConflictException)
            {
                if (reties > 0)
                {
                    return(await WriteToEventStoreAsync(
                               id,
                               version,
                               options,
                               events,
                               reties - 1,
                               cancellationToken)
                           .ConfigureAwait(false));
                }

                throw;
            }
        }
Beispiel #4
0
        public void When_disabled()
        {
            var entity = new TestEntity(EntityRowKey, "*");

            var insert  = Include.Insert(entity);
            var replace = Include.Replace(entity);

            EventData[] events =
            {
                CreateEvent(insert),
                CreateEvent(replace)
            };

            var options = new StreamWriteOptions {
                TrackChanges = false
            };

            Assert.ThrowsAsync <StorageException>(() => Stream.WriteAsync(stream, options, events),
                                                  "Should fail since there conflicting operations");

            var stored = RetrieveTestEntity(entity.RowKey);

            Assert.That(stored, Is.Null, "Should not insert entity due to ETG failure");
        }