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); }
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); }
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); }
public void last_encountered_empty_page() { var page = new EventPage(0, 100, new List<IEvent>()) { NextKnownSequence = 150, LastKnownSequence = 1000 }; page.LastEncountered().ShouldBe(149); }
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); }
public Task StoreProgress(Type viewType, EventPage page) { Accumulator.Prune(page.To); if (shouldRestartFetcher()) { _fetcher.Start(this, Lifecycle); } return(Task.CompletedTask); }
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(); }
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); }
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); }
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); }
public void Store(EventPage page) { if (First == null) { First = page; Last = page; } else if (Last != null) { Last.Next = page; Last = page; } }
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); }
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; } }
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)); } }
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)); } }
public StoreProgress(Type viewType, EventPage page) { _viewType = viewType; _page = page; }
public void QueuePage(EventPage page) { UpdateBlock.Post(new CachePageUpdate(page)); }
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); }
public void PageExecuted(EventPage page, IProjectionTrack track) { _writeline($"{page} executed for {track.ViewType.FullName}"); }
public CachePageUpdate(EventPage page) { _page = page; }
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) { }
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(); }
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(); }
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); }
public void PageExecuted(EventPage page, IProjectionTrack track) { }
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}"); }