private ReadAllPage Read(AllStreamPosition from) { var maxPosition = MaxPosition; _writeLine($"From {from}, Max {maxPosition}"); if (from > MaxPosition) { var page = new ReadAllPage(from, from, true, new Envelope[0]); _writeLine(page.ToString()); return(page); } var messages = Enumerable.Range(0, 10) .Where(x => x <= maxPosition - from.ToInt64()) .Select(x => new Envelope(from.Shift(x), x)) .ToArray(); bool isEnd = !messages.Any() || messages.Last().Checkpoint.ToInt64() == maxPosition; var result = new ReadAllPage( from, messages.Any() ? messages.Last().Checkpoint.Shift() : from, isEnd, messages); _writeLine(result.ToString()); return(result); }
public PollingNotifierTests() { _currentPosition = AllStreamPosition.None; _notifier = new PollingNotifier( _ => _currentPosition.ToInt64() != 9999 ? Task.FromResult(_currentPosition) : throw new InvalidOperationException("Error happened"), (ex, p) => { _error.SetResult(ex); // this actually fails 2nd+ time (intentional) return(Task.CompletedTask); }, interval: Interval); }
public async Task Checkpoint_is_stored_on_commit() { var expected = new AllStreamPosition(10); using (var cpStore = Util.BuildCheckpointStore()) using (var sut = new CheckpointProjection(new DelegateProjection(), cpStore)) { await sut.Project(new Envelope(expected, null)); await sut.Commit(); cpStore.Read().ShouldBe(expected.ToInt64()); } }
public Task <ReadAllPage> ReadForward( AllStreamPosition from = default(AllStreamPosition), int batchSize = 10, CancellationToken cancellationToken = default(CancellationToken)) { var pairs = _allStream.ReadAfter(from.ToInt64() - 1, batchSize); var messages = pairs.Select(p => new Envelope( TranslateKey(p.Key), Serializer.DeserializeJson <DocumentSaved>(p.Value))) .ToArray(); if (messages.Length == 0) { return(Task.FromResult(new ReadAllPage(from, from, true, new Envelope[0]))); } var next = messages.Last().Checkpoint.Shift(); var isEnd = _allStream.GetLastCheckpoint().Key < next; return(Task.FromResult(new ReadAllPage(from, next, isEnd, messages))); }