Exemplo n.º 1
0
        public void WorksWithInstancePerAggregateRootView()
        {
            _context.AddViewManager(_instancePerAggregateRootViewManager);

            _context.Save("id1", new ThisIsJustAnEvent());
            _context.Save("id1", new ThisIsJustAnEvent());
            _context.Save("id1", new ThisIsJustAnEvent());

            _context.Save("id2", new ThisIsJustAnEvent());
            _context.Save("id2", new ThisIsJustAnEvent());
            _context.Save("id2", new ThisIsJustAnEvent());

            _context.WaitForViewsToCatchUp();

            var view = _factory.Load <InstancePerAggregateRootView>(InstancePerAggregateRootLocator.GetViewIdFromAggregateRootId("id1"));

            Assert.That(view.EventCounter, Is.EqualTo(3));
        }
Exemplo n.º 2
0
        public void CanPurgeTheView()
        {
            // arrange
            PurgeTestView.StaticBadBoy = "first value";
            _context.Save("id", new Event());
            PurgeTestView.StaticBadBoy = "new value";

            // act
            _viewManager.Purge();
            _context.WaitForViewsToCatchUp();

            // assert
            var view = _viewManager.Load(GlobalInstanceLocator.GetViewInstanceId());

            Assert.That(view.CaughtStaticBadBoy, Is.EqualTo("new value"));
        }
Exemplo n.º 3
0
        public void CanRecoverAfterTransientErrors(int eventCount, double failIntervalSeconds, double failDurationSeconds)
        {
            // arrange
            var eventIds  = Enumerable.Range(0, eventCount).ToList();
            var failCount = 0;

            using (var failTimer = new Timer(TimeSpan.FromSeconds(failIntervalSeconds).TotalMilliseconds))
            {
                failTimer.Elapsed += delegate
                {
                    View.Fail = true;
                    failCount++;

                    ThreadPool.QueueUserWorkItem(_ =>
                    {
                        Thread.Sleep(TimeSpan.FromSeconds(failDurationSeconds));
                        View.Fail = false;
                    });
                };
                failTimer.Start();


                var events = eventIds
                             .Select(id => new Event {
                    EventId = id
                })
                             .ToList();

                events.ForEach(e => _context.Save("someid", e));

                // act
                _context.AddViewManager(_viewManager);
                _context.WaitForViewsToCatchUp(300);
            }

            Console.WriteLine(@"====================================================
Processed {0} events
Failed every {1} seconds (total fail count: {2})
====================================================", eventCount, failIntervalSeconds, failCount);

            // assert
            var viewInstance = _viewManager.Load(GlobalInstanceLocator.GetViewInstanceId());

            Assert.That(viewInstance.EventIds, Is.EqualTo(eventIds));
        }
Exemplo n.º 4
0
        public void ViewsCanSubscribeToBaseClasses()
        {
            // arrange
            var viewId = InstancePerAggregateRootLocator.GetViewIdFromAggregateRootId("id");

            _context.Save("id", new Event());
            _context.Save("id", new Event());
            _context.Save("id", new AnotherEvent());
            _context.Save("id", new AnotherEvent());

            _context.WaitForViewsToCatchUp();

            // act
            var normalView = _viewManager1.Load(viewId);
            var viewWithAggregateRootSubscription      = _viewManager2.Load(viewId);
            var viewWithGeneralDomainEventSubscription = _viewManager3.Load(viewId);

            // assert
            Assert.That(normalView.ProcessedEvents, Is.EqualTo(4));
            Assert.That(viewWithAggregateRootSubscription.ProcessedEvents, Is.EqualTo(4), "Expected that the view could get all events from this particular aggregate root");
            Assert.That(viewWithGeneralDomainEventSubscription.ProcessedEvents, Is.EqualTo(4), "Expected that the view could get ALL events");
        }