示例#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);
        }
示例#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);
        }
示例#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);
        }
示例#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);
        }
示例#5
0
文件: Fetcher.cs 项目: ifle/marten
        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);
        }
示例#6
0
        public Task StoreProgress(Type viewType, EventPage page)
        {
            Accumulator.Prune(page.To);

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

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

        }
示例#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);
        }
示例#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);


        }
示例#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);
        }
示例#11
0
 public void Store(EventPage page)
 {
     if (First == null)
     {
         First = page;
         Last  = page;
     }
     else if (Last != null)
     {
         Last.Next = page;
         Last      = page;
     }
 }
示例#12
0
 public void Store(EventPage page)
 {
     if (First == null)
     {
         First = page;
         Last = page;
     }
     else if (Last != null)
     {
         Last.Next = page;
         Last = page;
     }
 }
示例#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);
        }
示例#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;
            }
        }
示例#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));
            }
        }
示例#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));
            }
        }
示例#17
0
 public StoreProgress(Type viewType, EventPage page)
 {
     _viewType = viewType;
     _page     = page;
 }
示例#18
0
 public void QueuePage(EventPage page)
 {
     UpdateBlock.Post(new CachePageUpdate(page));
 }
示例#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);
        }
示例#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);


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

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

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

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