예제 #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}");
 }