Ejemplo n.º 1
0
        public void TestProjectionAppliesOneEventForSameSequence()
        {
            var eventStream = Substitute.For <IEventStream>();

            eventStream
            .Load(1, 50)
            .Returns(new List <IDomainEvent>
            {
                new FooEvent(1),
                new FooEvent(1),
                new FooEvent(1),
                new FooEvent(1),
                new FooEvent(1),
            });

            var projectionState = Substitute.For <IProjectionStateRepository>();

            projectionState.GetOffset(Arg.Any <string>()).Returns(0);

            var projection1 = new FooProjection(projectionState);

            var projectionAgent = new ProjectionAgent(eventStream, new IProjection[] { projection1 });

            var disposable = projectionAgent.Run(config =>
            {
                config.BatchSize = 50;
                config.PeekIntervalMilliseconds = 1;
            });

            Thread.Sleep(100);

            disposable.Dispose();

            Assert.AreEqual(1, projection1.Called);
        }
        public void TestProjectionAgentQueriesEventStreamByCorrespondingProjectionOffset()
        {
            var eventStream = Substitute.For <IEventStream>();

            var subscriptions1 = new List <string> {
                typeof(FooEvent).Name
            };

            var subscriptions2 = new List <string> {
                typeof(BooEvent).Name, typeof(FooEvent).Name
            };

            eventStream
            .Load(1, 3, Arg.Is <List <string> >(x => subscriptions1.SequenceEqual(x)))
            .Returns(new List <IDomainEvent>
            {
                new FooEvent(1),
                new FooEvent(2),
                new FooEvent(3)
            });

            eventStream
            .Load(21, 3, Arg.Is <List <string> >(x => subscriptions2.SequenceEqual(x)))
            .Returns(new List <IDomainEvent>
            {
                new BooEvent(21),
                new BooEvent(22),
                new BooEvent(23)
            });

            var projectionState1 = Substitute.For <IProjectionStateRepository>();

            projectionState1.GetOffset().Returns(0);

            var projectionState2 = Substitute.For <IProjectionStateRepository>();

            projectionState2.GetOffset().Returns(20);

            var projection1 = new FooProjection(projectionState1);
            var projection2 = new BooProjection(projectionState2);

            var projectionAgent = new ProjectionAgent(eventStream, new IProjection[] { projection1, projection2 });

            projectionAgent.Run(config =>
            {
                config.BatchSize       = 3;
                config.PollingInterval = 1;
            });

            Thread.Sleep(100);

            projectionAgent.Dispose();

            eventStream.Received().Load(1, 3, Arg.Is <List <string> >(x => subscriptions1.SequenceEqual(x)));
            eventStream.Received().Load(21, 3, Arg.Is <List <string> >(x => subscriptions2.SequenceEqual(x)));
            eventStream.Received().Load(4, 3, Arg.Is <List <string> >(x => subscriptions1.SequenceEqual(x)));
            eventStream.Received().Load(24, 3, Arg.Is <List <string> >(x => subscriptions2.SequenceEqual(x)));
        }
        public void TestProjectionAgentQueriesEventStreamPerProjection()
        {
            var eventStream = Substitute.For <IEventStream>();

            var subscriptions = new List <string> {
                typeof(FooEvent).Name
            };

            eventStream
            .Load(1, 50, Arg.Is <List <string> >(x => subscriptions.SequenceEqual(x)))
            .Returns(new List <IDomainEvent>()
            {
                new FooEvent(1),
                new FooEvent(2),
                new FooEvent(3),
                new FooEvent(4),
                new FooEvent(5),
            });

            eventStream
            .Load(15, 50, Arg.Is <List <string> >(x => subscriptions.SequenceEqual(x)))
            .Returns(new List <IDomainEvent>()
            {
                new FooEvent(15),
                new FooEvent(16),
                new FooEvent(17),
            });

            var projectionState1 = Substitute.For <IProjectionStateRepository>();

            projectionState1.GetOffset().Returns(0);

            var projectionState2 = Substitute.For <IProjectionStateRepository>();

            projectionState2.GetOffset().Returns(14);

            var projection1 = new FooProjection(projectionState1);
            var projection2 = new FooProjection(projectionState2);

            var projectionAgent = new ProjectionAgent(eventStream, new IProjection[] { projection1, projection2 });

            projectionAgent.Run(config =>
            {
                config.BatchSize       = 50;
                config.PollingInterval = 1;
            });

            Thread.Sleep(100);

            projectionAgent.Dispose();

            eventStream.Received(1).Load(1, 50, Arg.Is <List <string> >(x => subscriptions.SequenceEqual(x)));
            eventStream.Received(1).Load(15, 50, Arg.Is <List <string> >(x => subscriptions.SequenceEqual(x)));
        }
        public void TestProjectionTracksEventSequence()
        {
            var eventStream = Substitute.For <IEventStream>();

            var subscriptions = new List <string> {
                typeof(FooEvent).Name
            };

            eventStream
            .Load(1, 50, Arg.Is <List <string> >(x => subscriptions.SequenceEqual(x)))
            .Returns(new List <IDomainEvent>
            {
                new FooEvent(1),
                new FooEvent(2),
                new FooEvent(3),
                new FooEvent(4),
                new FooEvent(5),
            });

            var projectionState = Substitute.For <IProjectionStateRepository>();

            projectionState.GetOffset().Returns(0);

            var projection1 = new FooProjection(projectionState);
            var projection2 = new FooProjection(projectionState);

            var projectionAgent = new ProjectionAgent(eventStream, new IProjection[] { projection1, projection2 });

            projectionAgent.Run(config =>
            {
                config.BatchSize       = 50;
                config.PollingInterval = 1;
            });

            Thread.Sleep(100);

            projectionAgent.Dispose();

            Assert.AreEqual(5, projection1.Called);
            Assert.AreEqual(5, projection2.Called);
        }
Ejemplo n.º 5
0
        public void TestProjectionAgentQueriesEventStreamByCorrespondingSubscriptions()
        {
            var eventStream = Substitute.For <IEventStream>();

            var subscriptions1 = new List <string> {
                typeof(FooEvent).Name
            };

            var subscriptions2 = new List <string> {
                typeof(BooEvent).Name, typeof(FooEvent).Name
            };

            var projectionState1 = Substitute.For <IProjectionStateRepository>();

            projectionState1.GetOffset(Arg.Any <string>()).Returns(0);

            var projectionState2 = Substitute.For <IProjectionStateRepository>();

            projectionState2.GetOffset(Arg.Any <string>()).Returns(20);

            var projection1 = new FooProjection(projectionState1);
            var projection2 = new BooProjection(projectionState2);

            var projectionAgent = new ProjectionAgent(eventStream, new IProjection[] { projection1, projection2 });

            var disposable = projectionAgent.Run(config =>
            {
                config.BatchSize = 50;
                config.PeekIntervalMilliseconds = 1;
            });

            Thread.Sleep(100);

            disposable.Dispose();

            eventStream.Received().Load(1, 50);
            eventStream.Received().Load(21, 50);
        }