Exemplo n.º 1
0
        public void Projection_write_speed_without_unit_of_work()
        {
            var eventsRead = 0;

            var projector1 = Projector.Create <IEvent>(e =>
            {
                using (var db = new ReadModelDbContext())
                {
                    db.Set <ProductInventory>().Add(new ProductInventory
                    {
                        ProductName      = Guid.NewGuid().ToString(),
                        QuantityInStock  = Any.Int(1, 5),
                        QuantityReserved = 0
                    });

                    db.SaveChanges();

                    eventsRead++;
                }
            }).Named(MethodBase.GetCurrentMethod().Name + ":projector1");

            using (var catchup = new ReadModelCatchup(projector1)
            {
                StartAtEventId = startAtEventId
            })
            {
                catchup.Run();
            }

            Console.WriteLine(new { eventsRead });

            // TODO: (Write_speed_without_unit_of_work) write test
            Assert.Fail("Test not written yet.");
        }
        public void Projection_write_speed_with_unit_of_work()
        {
            var eventsRead = 0;

            var projector1 = Projector.Create <IEvent>(e =>
            {
                using (var update = this.Update())
                {
                    var db = update.Resource <ReadModelDbContext>();

                    db.Set <ProductInventory>().Add(new ProductInventory
                    {
                        ProductName      = Guid.NewGuid().ToString(),
                        QuantityInStock  = Any.Int(1, 5),
                        QuantityReserved = 0
                    });

                    db.SaveChanges();

                    eventsRead++;
                }
            }).Named(MethodBase.GetCurrentMethod().Name + ":projector1");

            using (var catchup = new ReadModelCatchup(
                       eventStoreDbContext: () => EventStoreDbContext(),
                       readModelDbContext: () => ReadModelDbContext(),
                       startAtEventId: startAtEventId, projectors: projector1))
            {
                catchup.Run();
            }

            Console.WriteLine(new { eventsRead });
        }
        public void Read_speed_for_IEvent()
        {
            var eventsRead = 0;

            var projector1 = Projector.Create<IEvent>(e => { eventsRead++; }).Named(MethodBase.GetCurrentMethod().Name + ":projector1");

            using (var catchup = new ReadModelCatchup(projector1) { StartAtEventId = startAtEventId })
            {
                catchup.Run();
            }

            Console.WriteLine(new { eventsRead });
        }
        public void Read_speed_for_two_specific_events()
        {
            var eventsRead = 0;

            var projector1 = Projector.Create<Order.ItemAdded>(e => { eventsRead++; }).Named(MethodBase.GetCurrentMethod().Name + ":projector1");
            var projector2 = Projector.Create<CustomerAccount.RequestedNoSpam>(e => { eventsRead++; }).Named(MethodBase.GetCurrentMethod().Name + ":projector2");

            using (var catchup = new ReadModelCatchup(projector1, projector2) { StartAtEventId = startAtEventId })
            {
                catchup.Run();
            }

            Console.WriteLine(new { eventsRead });
        }
        public void Read_speed_for_IEvent()
        {
            var eventsRead = 0;

            var projector1 = Projector.Create <IEvent>(e => { eventsRead++; }).Named(MethodBase.GetCurrentMethod().Name + ":projector1");

            using (var catchup = new ReadModelCatchup(
                       eventStoreDbContext: () => EventStoreDbContext(),
                       readModelDbContext: () => ReadModelDbContext(),
                       startAtEventId: startAtEventId, projectors: projector1))
            {
                catchup.Run();
            }

            Console.WriteLine(new { eventsRead });
        }
Exemplo n.º 6
0
        public void Read_speed_for_IEvent()
        {
            var eventsRead = 0;

            var projector1 = Projector.Create <IEvent>(e => { eventsRead++; }).Named(MethodBase.GetCurrentMethod().Name + ":projector1");

            using (var catchup = new ReadModelCatchup(projector1)
            {
                StartAtEventId = startAtEventId
            })
            {
                catchup.Run();
            }

            Console.WriteLine(new { eventsRead });
        }
        public void Read_speed_for_IEvent()
        {
            var eventsRead = 0;

            var projector1 = Projector.Create<IEvent>(e => { eventsRead++; }).Named(MethodBase.GetCurrentMethod().Name + ":projector1");

            using (var catchup = new ReadModelCatchup(
                eventStoreDbContext: () => EventStoreDbContext(),
                readModelDbContext: () => ReadModelDbContext(),
                startAtEventId: startAtEventId, projectors: projector1))
            {
                catchup.Run();
            }

            Console.WriteLine(new { eventsRead });
        }
Exemplo n.º 8
0
        public void Read_speed_for_two_specific_events()
        {
            var eventsRead = 0;

            var projector1 = Projector.Create <Order.ItemAdded>(e => { eventsRead++; }).Named(MethodBase.GetCurrentMethod().Name + ":projector1");
            var projector2 = Projector.Create <CustomerAccount.RequestedNoSpam>(e => { eventsRead++; }).Named(MethodBase.GetCurrentMethod().Name + ":projector2");

            using (var catchup = new ReadModelCatchup(projector1, projector2)
            {
                StartAtEventId = startAtEventId
            })
            {
                catchup.Run();
            }

            Console.WriteLine(new { eventsRead });
        }
        public void Read_speed_for_two_specific_events()
        {
            var eventsRead = 0;

            var projector1 = Projector.Create <Order.ItemAdded>(e => { eventsRead++; }).Named(MethodBase.GetCurrentMethod().Name + ":projector1");
            var projector2 = Projector.Create <CustomerAccount.RequestedNoSpam>(e => { eventsRead++; }).Named(MethodBase.GetCurrentMethod().Name + ":projector2");

            using (var catchup = new ReadModelCatchup(
                       eventStoreDbContext: () => EventStoreDbContext(),
                       readModelDbContext: () => ReadModelDbContext(),
                       startAtEventId: startAtEventId,
                       projectors: new object[] { projector1, projector2 }))
            {
                catchup.Run();
            }

            Console.WriteLine(new { eventsRead });
        }
Exemplo n.º 10
0
        public void ReadModelCatchup_StartAtEventId_can_be_used_to_avoid_requery_of_previous_events()
        {
            var lastEventId = Events.Write(50, _ => Events.Any());

            var eventsProjected = 0;

            var projector = Projector.Create <Event>(e => { eventsProjected++; }).Named(MethodBase.GetCurrentMethod().Name);

            using (var catchup = new ReadModelCatchup(projector)
            {
                StartAtEventId = lastEventId - 20
            })
            {
                catchup.Run();
            }

            eventsProjected.Should().Be(21);
        }
Exemplo n.º 11
0
        public async Task ReadModelCatchup_StartAtEventId_can_be_used_to_avoid_requery_of_previous_events()
        {
            var lastEventId = Events.Write(50, _ => Events.Any());

            var eventsProjected = 0;

            var projector = Projector.Create <Event>(e => { eventsProjected++; })
                            .Named(MethodBase.GetCurrentMethod().Name);

            using (var catchup = new ReadModelCatchup(
                       eventStoreDbContext: () => EventStoreDbContext(),
                       readModelDbContext: () => ReadModelDbContext(),
                       startAtEventId: lastEventId - 20,
                       projectors: projector))
            {
                await catchup.Run();
            }

            eventsProjected.Should().Be(21);
        }
Exemplo n.º 12
0
        private void RunCatchup()
        {
            // TODO: (RunCatchup) provide trace output here and throughout
            var projectors = handlers.OrEmpty()
                             .Where(h => h.GetType().IsProjectorType())
                             .ToArray();

            if (!projectors.Any())
            {
                return;
            }

            if (configuration.IsUsingSqlEventStore())
            {
                var catchup = new ReadModelCatchup(projectors)
                {
                    CreateEventStoreDbContext = CreateEventStoreDbContext,
                    CreateReadModelDbContext  = CreateReadModelDbContext,
                    StartAtEventId            = startCatchupAtEventId
                };

                using (catchup)
                    using (catchup.EventBus.Errors.Subscribe(scenario.AddEventHandlingError))
                        using (catchup.Progress.Subscribe(s => Console.WriteLine(s)))
                        {
                            catchup.Run();
                        }
            }
            else
            {
                EventBus.PublishAsync(InitialEvents.ToArray()).Wait();
            }

            if (scenario.EventHandlingErrors.Any())
            {
                throw new ScenarioSetupException(
                          "The following event handling errors occurred during projection catchup: " +
                          string.Join("\n", scenario.EventHandlingErrors.Select(e => e.Exception.ToString())));
            }
        }
Exemplo n.º 13
0
        private void RunCatchup()
        {
            var projectors = handlers.OrEmpty()
                             .Where(h => h.GetType().IsProjectorType())
                             .ToArray();

            if (!projectors.Any())
            {
                return;
            }

            if (configuration.IsUsingSqlEventStore())
            {
                var catchup = new ReadModelCatchup(
                    eventStoreDbContext: () => configuration.EventStoreDbContext(),
                    readModelDbContext: () => configuration.ReadModelDbContext(),
                    startAtEventId: startCatchupAtEventId,
                    projectors: projectors);

                using (catchup)
                    using (catchup.EventBus.Errors.Subscribe(scenario.AddEventHandlingError))
                        using (catchup.Progress.Subscribe(s => Console.WriteLine(s)))
                        {
                            catchup.Run().Wait(TimeSpan.FromSeconds(30));
                        }
            }
            else
            {
                EventBus.PublishAsync(InitialEvents.ToArray()).Wait();
            }

            if (scenario.EventHandlingErrors.Any())
            {
                throw new ScenarioSetupException(
                          "The following event handling errors occurred during projection catchup: " +
                          string.Join("\n", scenario.EventHandlingErrors.Select(e => e.Exception.ToString())));
            }
        }
        public void Projection_write_speed_with_unit_of_work()
        {
            var eventsRead = 0;

            var projector1 = Projector.Create<IEvent>(e =>
            {
                using (var update = this.Update())
                {
                    var db = update.Resource<ReadModelDbContext>();

                    db.Set<ProductInventory>().Add(new ProductInventory
                    {
                        ProductName = Guid.NewGuid().ToString(),
                        QuantityInStock = Any.Int(1, 5),
                        QuantityReserved = 0
                    });

                    db.SaveChanges();

                    eventsRead++;
                }
            }).Named(MethodBase.GetCurrentMethod().Name + ":projector1");

            using (var catchup = new ReadModelCatchup(
                eventStoreDbContext: () => EventStoreDbContext(),
                readModelDbContext: () => ReadModelDbContext(),
                startAtEventId: startAtEventId, projectors: projector1))
            {
                catchup.Run();
            }

            Console.WriteLine(new { eventsRead });
        }
        public void Read_speed_for_two_specific_events()
        {
            var eventsRead = 0;

            var projector1 = Projector.Create<Order.ItemAdded>(e => { eventsRead++; }).Named(MethodBase.GetCurrentMethod().Name + ":projector1");
            var projector2 = Projector.Create<CustomerAccount.RequestedNoSpam>(e => { eventsRead++; }).Named(MethodBase.GetCurrentMethod().Name + ":projector2");

            using (var catchup = new ReadModelCatchup(
                eventStoreDbContext: () => EventStoreDbContext(),
                readModelDbContext: () => ReadModelDbContext(),
                startAtEventId: startAtEventId,
                projectors: new object[] { projector1, projector2 }))
            {
                catchup.Run();
            }

            Console.WriteLine(new { eventsRead });
        }
        public void Projection_write_speed_without_unit_of_work()
        {
            var eventsRead = 0;

            var projector1 = Projector.Create<IEvent>(e =>
            {
                using (var db = new ReadModelDbContext())
                {
                    db.Set<ProductInventory>().Add(new ProductInventory
                    {
                        ProductName = Guid.NewGuid().ToString(),
                        QuantityInStock = Any.Int(1, 5),
                        QuantityReserved = 0
                    });

                    db.SaveChanges();

                    eventsRead++;
                }
            }).Named(MethodBase.GetCurrentMethod().Name + ":projector1");

            using (var catchup = new ReadModelCatchup(projector1) { StartAtEventId = startAtEventId })
            {
                catchup.Run();
            }

            Console.WriteLine(new { eventsRead });

            // TODO: (Write_speed_without_unit_of_work) write test
            Assert.Fail("Test not written yet.");
        }