Beispiel #1
0
        public void CanReadFromCheckpoint(long checkpoint, int expectedCount, int firstRead)
        {
            _changeStream.Append(Enumerable.Range(0, 10).Select(BitConverter.GetBytes).ToArray());
            var read = _changeStream.ReadAfter(checkpoint, 2).ToArray();

            read.Length.ShouldBe(expectedCount);

            for (int i = 0; i < expectedCount; i++, firstRead++)
            {
                read[i].Key.ShouldBe(firstRead);
                BitConverter.ToInt32(read[i].Value, 0).ShouldBe(firstRead);
            }
        }
Beispiel #2
0
        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)));
        }