示例#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);
        }
示例#2
0
        /// <summary> Initialize the wrapper and set <see cref="IsReady"/> to true. </summary>
        /// <remarks>
        /// Upon failure, logs the exception and tries again after a short delay, forever.
        /// </remarks>
        private async Task Initialize()
        {
            while (!_cancel.IsCancellationRequested)
            {
                try
                {
                    await Wrapper.InitializeAsync(_cancel).ConfigureAwait(false);

                    _isReady = true;
                    return;
                }
                catch (OperationCanceledException) { throw; }
                catch (Exception e)
                {
                    _log.Error("Could not initialize EventStreamService", e);
                    _initFailure = e;
                    Wrapper.Reset();
                }

                await Task.Delay(TimeSpan.FromSeconds(5), _cancel).ConfigureAwait(false);
            }
        }
示例#3
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);
        }