Beispiel #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);
        }
Beispiel #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);
        }
Beispiel #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);
        }
Beispiel #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);
        }
Beispiel #5
0
        public async Task <EventPage> FetchNextPage(long lastEncountered)
        {
            EventPage page = null;

            await _errorHandler.TryAction(async() =>
            {
                page = await fetchNextPage(lastEncountered).ConfigureAwait(false);
            }, _track).ConfigureAwait(false);

            return(page);
        }
Beispiel #6
0
        public Task StoreProgress(Type viewType, EventPage page)
        {
            Accumulator.Prune(page.To);

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

            return(Task.CompletedTask);
        }
Beispiel #7
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();

        }
Beispiel #8
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);
        }
Beispiel #9
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);


        }
Beispiel #10
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);
        }
Beispiel #11
0
 public void Store(EventPage page)
 {
     if (First == null)
     {
         First = page;
         Last  = page;
     }
     else if (Last != null)
     {
         Last.Next = page;
         Last      = page;
     }
 }
Beispiel #12
0
 public void Store(EventPage page)
 {
     if (First == null)
     {
         First = page;
         Last = page;
     }
     else if (Last != null)
     {
         Last.Next = page;
         Last = page;
     }
 }
Beispiel #13
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);
        }
Beispiel #14
0
        public void Store(EventPage page)
        {
            if (page.Count == 0)
            {
                return;
            }

            if (First == null)
            {
                First = page;
                Last  = page;
            }
            else if (Last != null)
            {
                Last.Next = page;
                Last      = page;
            }
        }
Beispiel #15
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));
            }
        }
Beispiel #16
0
        private async Task executePage(EventPage page, CancellationToken cancellation)
        {
            // TODO -- have to pass in the tenant here
            using (var session = _store.OpenSession())
            {
                await _projection.ApplyAsync(session, page, cancellation).ConfigureAwait(false);

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

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

                _logger.PageExecuted(page, this);

                // This is a change to accomodate the big gap problem
                LastEncountered = page.LastEncountered();

                evaluateWaiters();

                UpdateBlock?.Post(new StoreProgress(_projection.ProjectedType(), page));
            }
        }
Beispiel #17
0
 public StoreProgress(Type viewType, EventPage page)
 {
     _viewType = viewType;
     _page     = page;
 }
Beispiel #18
0
 public void QueuePage(EventPage page)
 {
     UpdateBlock.Post(new CachePageUpdate(page));
 }
Beispiel #19
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);
        }
Beispiel #20
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);


        }
Beispiel #21
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));
            }
        }
Beispiel #22
0
 public void PageExecuted(EventPage page, IProjectionTrack track)
 {
     _writeline($"{page} executed for {track.ViewType.FullName}");
 }
Beispiel #23
0
 public CachePageUpdate(EventPage page)
 {
     _page = page;
 }
Beispiel #24
0
        public Task StoreProgress(Type viewType, EventPage page)
        {
            Accumulator.Prune(page.To);

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

            return Task.CompletedTask;
        }
 public void ProjectionBackedUp(IProjectionTrack track, int cachedEventCount, EventPage page)
 {
     
 }
Beispiel #26
0
 public StoreProgress(Type viewType, EventPage page)
 {
     _viewType = viewType;
     _page = page;
 }
Beispiel #27
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();
        }
Beispiel #28
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();

        }
Beispiel #29
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);
        }
Beispiel #30
0
 public void PageExecuted(EventPage page, IProjectionTrack track)
 {
     _writeline($"{page} executed for {track.ViewType.FullName}");
 }
 public void PageExecuted(EventPage page, IProjectionTrack track)
 {
     
 }
Beispiel #32
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}");
 }
Beispiel #33
0
 public CachePageUpdate(EventPage page)
 {
     _page = page;
 }
Beispiel #34
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);
        }
Beispiel #35
0
 public void QueuePage(EventPage page)
 {
     UpdateBlock.Post(new CachePageUpdate(page));
 }
Beispiel #36
0
 public void PageExecuted(EventPage page, IProjectionTrack track)
 {
 }
Beispiel #37
0
 public void ProjectionBackedUp(IProjectionTrack track, int cachedEventCount, EventPage page)
 {
 }
Beispiel #38
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}");
 }