Example #1
0
        public async Task should_not_pause_the_fetcher_if_under_the_threshold()
        {
            var thePage = new EventPage(0, 100, new IEvent[0]) { Count = 100 };

            await theProjectionTrack.CachePage(thePage).ConfigureAwait(false);

            await theFetcher.DidNotReceive().Pause().ConfigureAwait(false);
        }
Example #2
0
        public async Task stores_the_first_page()
        {
            var thePage = new EventPage(0, 100, new IEvent[0]) { Count = 100 };

            await theProjectionTrack.CachePage(thePage).ConfigureAwait(false);

            theProjectionTrack.Accumulator.AllPages().Single()
                .ShouldBe(thePage);
        }
Example #3
0
        public void last_encountered_with_no_known_sequence()
        {
            var page = new EventPage(0, 100, new List<IEvent>())
            {
                NextKnownSequence = 0,
                LastKnownSequence = 1000
            };

            page.LastEncountered().ShouldBe(1000);
        }
Example #4
0
        public void last_encountered_empty_page()
        {
            var page = new EventPage(0, 100, new List<IEvent>())
            {
                NextKnownSequence = 150,
                LastKnownSequence = 1000
            };

            page.LastEncountered().ShouldBe(149);
        }
Example #5
0
        public void should_pause_if_empty_with_no_known_next()
        {
            var page = new EventPage(0, 100, new List<IEvent>())
            {
                NextKnownSequence = 0,
                LastKnownSequence = 1000
            };

            page.ShouldPause().ShouldBeTrue();

        }
Example #6
0
        public async Task store_progress_removes_obsolete_page()
        {
            var thePage = new EventPage(0, 100, new IEvent[0]) { Count = 100 };
            var thePage2 = new EventPage(101, 200, new IEvent[0]) { Count = 100 };
            await theProjectionTrack.CachePage(thePage).ConfigureAwait(false);
            await theProjectionTrack.CachePage(thePage2).ConfigureAwait(false);


            await theProjectionTrack.StoreProgress(typeof(ActiveProject), thePage).ConfigureAwait(false);

            theProjectionTrack.Accumulator.AllPages().Single()
                .ShouldBe(thePage2);
        }
Example #7
0
 public void Store(EventPage page)
 {
     if (First == null)
     {
         First = page;
         Last = page;
     }
     else if (Last != null)
     {
         Last.Next = page;
         Last = page;
     }
 }
Example #8
0
        public void last_encountered_with_non_zero_page()
        {
            var page = new EventPage(0, 100, new List<IEvent> {new Event<ProjectStarted>(new ProjectStarted())})
            {
                NextKnownSequence = 0,
                LastKnownSequence = 1000
            };

            page.Sequences.Add(97);
            page.Sequences.Add(98);
            page.Sequences.Add(99);

            page.LastEncountered().ShouldBe(1000);
        }
Example #9
0
        public async Task should_restart_the_fetcher_if_it_was_paused_and_below_the_threshold()
        {
            theFetcher.State.Returns(FetcherState.Paused);

            var thePage = new EventPage(0, 100, new IEvent[0]) { Count = 100 };
            await theProjectionTrack.CachePage(thePage).ConfigureAwait(false);


            await theProjectionTrack.StoreProgress(typeof(ActiveProject), thePage).ConfigureAwait(false);

            theFetcher.Received().Start(theProjectionTrack, theProjectionTrack.Lifecycle);
        }
Example #10
0
 public StoreProgress(Type viewType, EventPage page)
 {
     _viewType = viewType;
     _page = page;
 }
Example #11
0
        private async Task executePage(EventPage page, CancellationToken cancellation)
        {
            using (var session = _store.OpenSession())
            {
                await _projection.ApplyAsync(session, page.Streams, cancellation).ConfigureAwait(false);

                session.QueueOperation(new EventProgressWrite(_events, _projection.Produces.FullName, page.To));

                await session.SaveChangesAsync(cancellation).ConfigureAwait(false);

                _logger.PageExecuted(page, this);

                LastEncountered = page.To;

                evaluateWaiters();

                UpdateBlock?.Post(new StoreProgress(_projection.Produces, page));
            }
        }
Example #12
0
        public async Task ExecutePage(EventPage page, CancellationToken cancellation)
        {
            // Duplicated, ignore. Shouldn't happen, but Fetcher is screwed up, so...
            if (page.To <= LastEncountered) return;

            await _errorHandler.TryAction(async () =>
            {
                await executePage(page, cancellation).ConfigureAwait(false);
            }, this).ConfigureAwait(false);


        }
Example #13
0
        public async Task CachePage(EventPage page)
        {
            Accumulator.Store(page);

            
            if (Accumulator.CachedEventCount > _projection.AsyncOptions.MaximumStagedEventCount)
            {
                _logger.ProjectionBackedUp(this, Accumulator.CachedEventCount, page);
                await _fetcher.Pause().ConfigureAwait(false);
            }


            _executionTrack?.Post(page);
        }
Example #14
0
        public async Task should_queue_the_page_on_each_projection_on_the_first_one()
        {
            var thePage = new EventPage(0, 100, new IEvent[0]) { Count = 100 };

            await theProjectionTrack.CachePage(thePage).ConfigureAwait(false);
        }
Example #15
0
        public void should_pause_if_there_are_any_events()
        {
            var page = new EventPage(0, 100, new List<IEvent> { new Event<ProjectStarted>(new ProjectStarted()) })
            {
                NextKnownSequence = 0,
                LastKnownSequence = 1000
            };

            page.Sequences.Add(97);
            page.Sequences.Add(98);
            page.Sequences.Add(99);

            page.ShouldPause().ShouldBeTrue();

        }
Example #16
0
 public CachePageUpdate(EventPage page)
 {
     _page = page;
 }
Example #17
0
        public void should_not_pause_if_there_is_a_next_known_sequence()
        {
            var page = new EventPage(0, 100, new List<IEvent>())
            {
                NextKnownSequence = 300,
                LastKnownSequence = 1000
            };

            page.ShouldPause().ShouldBeFalse();
        }
Example #18
0
 public void PageExecuted(EventPage page, IProjectionTrack track)
 {
     _writeline($"{page} executed for {track.ViewType.FullName}");
 }
Example #19
0
 public void PageExecuted(EventPage page, IProjectionTrack track)
 {
     
 }
Example #20
0
        public Task StoreProgress(Type viewType, EventPage page)
        {
            Accumulator.Prune(page.To);

            if (shouldRestartFetcher())
            {
                _fetcher.Start(this, Lifecycle);
            }

            return Task.CompletedTask;
        }
Example #21
0
 public void QueuePage(EventPage page)
 {
     UpdateBlock.Post(new CachePageUpdate(page));
 }
Example #22
0
 public void ProjectionBackedUp(IProjectionTrack track, int cachedEventCount, EventPage page)
 {
     
 }
Example #23
0
 public void ProjectionBackedUp(IProjectionTrack track, int cachedEventCount, EventPage page)
 {
     _writeline($"Projection {track.ViewType.FullName} is backed up with {cachedEventCount} events in memory, last page fetched was {page}");
 }