示例#1
0
        public async Task with_restart()
        {
            var memory = new MemoryStorageDriver();
            var cache  = new Testing.InMemoryCache();
            var ew     = new EventStreamWrapper <TstEvent, CheckSequence>(
                memory,
                new [] { new CheckSequence.Projection() },
                cache
                );
            await ew.AppendEventsAsync(new[] { new TstEvent(1) });

            await ew.AppendEventsAsync(new[] { new TstEvent(2) });

            await ew.AppendEventsAsync(new[] { new TstEvent(3) });

            await ew.TrySaveAsync();

            await ew.AppendEventsAsync(new[] { new TstEvent(4) });

            await ew.AppendEventsAsync(new[] { new TstEvent(5) });

            Assert.Equal(5u, ew.Current.LastEvt);

            // try to read:
            var ew2 = new EventStreamWrapper <TstEvent, CheckSequence>(
                memory, new[] { new CheckSequence.Projection() },
                cache);

            await ew2.InitializeAsync();

            Assert.Equal(5u, ew2.Current.LastEvt);
        }
        /// <remarks>
        ///     This constructor is private so that it is obvious (via <c>StartNew</c>)
        ///     that background tasks are being creatd.
        /// </remarks>
        private EventStreamService(
            StorageConfiguration storage,
            IEnumerable <IProjection <TEvent> > projections,
            IProjectionCacheProvider projectionCache,
            ILogAdapter log,
            CancellationToken cancel) : base(TimeSpan.FromSeconds(30), cancel)
        {
            _log       = log;
            _cancel    = cancel;
            Wrapper    = new EventStreamWrapper <TEvent, TState>(storage, projections, projectionCache, log);
            Quarantine = Wrapper.Quarantine;

            Ready = Task.Run(Initialize, cancel);
        }
示例#3
0
        public async Task test(int projectionSeq, int streamSeq, int expectedRequestedDiscardSeq, int expectedResets)
        {
            if (streamSeq < 0 || projectionSeq < 0 || expectedRequestedDiscardSeq < 0 || expectedResets < 0)
            {
                throw new Exception("positive int required");
            }

            var projection = Mock.Of <IReifiedProjection>(proj => proj.Sequence == (uint)projectionSeq);
            var stream     = new MockStream((uint)streamSeq);
            await EventStreamWrapper <object, object> .Catchup(projection, stream);

            Assert.Equal((uint)expectedRequestedDiscardSeq, stream.RequestedDiscardSeq);
            Assert.Equal(expectedResets, stream.NbResets);
        }
示例#4
0
        public async Task without_restart()
        {
            var memory = new MemoryStorageDriver();
            var ew     = new EventStreamWrapper <TstEvent, CheckSequence>(
                memory,
                new [] { new CheckSequence.Projection() }, null
                );
            await ew.AppendEventsAsync(new[] { new TstEvent(1) });

            await ew.AppendEventsAsync(new[] { new TstEvent(2) });

            await ew.AppendEventsAsync(new[] { new TstEvent(3) });

            Assert.Equal(3u, ew.Current.LastEvt);

            // try to read:
            var ew2 = new EventStreamWrapper <TstEvent, CheckSequence>(
                memory, new[] { new CheckSequence.Projection() }, null);

            await ew2.InitializeAsync();

            Assert.Equal(3u, ew2.Current.LastEvt);
        }
示例#5
0
        /// <remarks>
        ///     This constructor is private so that it is obvious (via <c>StartNew</c>)
        ///     that background tasks are being creatd.
        /// </remarks>
        private EventStreamService(
            StorageConfiguration storage,
            IEnumerable <IProjection <TEvent> > projections,
            IProjectionCacheProvider projectionCache,
            IEnumerable <Tuple <EventStream <TEvent> .Listener, uint> > events,
            ILogAdapter log,
            CancellationToken cancel)
        {
            _log       = log;
            _cancel    = cancel;
            Wrapper    = new EventStreamWrapper <TEvent, TState>(storage, projections, projectionCache, log);
            Quarantine = Wrapper.Quarantine;

            if (events != null)
            {
                foreach (var pair in events)
                {
                    Wrapper.OnEachCommitted(pair.Item1, pair.Item2);
                }
            }

            Ready = Task.Run(Initialize, cancel);
            Task.Run(Loop, cancel);
        }