Beispiel #1
0
        public async Task Should_get_state_from_all_actors()
        {
            sut.Run();

            A.CallTo(() => actor1.GetState())
            .Returns(new EventConsumerInfo {
                Name = consumerName1, Position = "123 "
            });

            A.CallTo(() => actor2.GetState())
            .Returns(new EventConsumerInfo {
                Name = consumerName2, Position = "345 "
            });

            var response = await pubSub.RequestAsync <GetStatesRequest, GetStatesResponse>(new GetStatesRequest(), TimeSpan.FromSeconds(5), true);

            response.States.ShouldAllBeEquivalentTo(new EventConsumerInfo[]
            {
                new EventConsumerInfo {
                    Name = consumerName1, Position = "123 "
                },
                new EventConsumerInfo {
                    Name = consumerName2, Position = "345 "
                }
            });
        }
Beispiel #2
0
        public async Task Should_stop_if_handling_failed()
        {
            sut.ActivateAsync(consumerName, store).Wait();
            sut.Activate(eventConsumer);

            var ex = new InvalidOperationException();

            A.CallTo(() => eventConsumer.On(envelope))
            .Throws(ex);

            var @event = new StoredEvent(Guid.NewGuid().ToString(), 123, eventData);

            await OnEventAsync(eventSubscription, @event);

            sut.Dispose();

            state.ShouldBeEquivalentTo(new EventConsumerState {
                IsStopped = true, Position = initialPosition, Error = ex.ToString()
            });

            A.CallTo(() => eventConsumer.On(envelope))
            .MustHaveHappened();

            A.CallTo(() => persistence.WriteSnapshotAsync(A <EventConsumerState> .Ignored))
            .MustHaveHappened(Repeated.Exactly.Once);

            A.CallTo(() => eventSubscription.StopAsync())
            .MustHaveHappened(Repeated.Exactly.Once);

            sut.GetState().ShouldBeEquivalentTo(new EventConsumerInfo {
                Name = consumerName, IsStopped = true, Position = initialPosition, Error = ex.ToString()
            });
        }