コード例 #1
0
        protected void WhenLoop(IEnumerable <WhenStep> steps)
        {
            foreach (var step in steps)
            {
                _timeProvider.AddToUtcTime(TimeSpan.FromMilliseconds(10));
                if (step.Action != null)
                {
                    step.Action();
                }

                foreach (var message in step)
                {
                    if (message != null)
                    {
                        _queue.Publish(message);
                    }
                }

                _queue.ProcessTimer();
                if (_otherQueues != null)
                {
                    foreach (var other in _otherQueues)
                    {
                        other.ProcessTimer();
                    }
                }

                var count = 1;
                var total = 0;
                while (count > 0)
                {
                    count  = 0;
                    count += _queue.ProcessNonTimer();
                    if (_otherQueues != null)
                    {
                        foreach (var other in _otherQueues)
                        {
                            count += other.ProcessNonTimer();
                        }
                    }
                    total += count;
                    if (total > 2000)
                    {
                        throw new Exception("Infinite loop?");
                    }
                }

                // process final timer messages
            }

            _queue.Process();
            if (_otherQueues != null)
            {
                foreach (var other in _otherQueues)
                {
                    other.Process();
                }
            }
        }
コード例 #2
0
        public new void When()
        {
            _distibutionPointCorrelationId = Guid.NewGuid();
            _fakeTimeProvider = new FakeTimeProvider();
            _edp = new TransactionFileEventReader(_bus, _distibutionPointCorrelationId, null, new TFPos(100, 50),
                                                  _fakeTimeProvider,
                                                  deliverEndOfTFPosition: false);
            _edp.Resume();
            _firstEventId  = Guid.NewGuid();
            _secondEventId = Guid.NewGuid();
            var correlationId = _consumer.HandledMessages.OfType <ClientMessage.ReadAllEventsForward>().Last()
                                .CorrelationId;

            _edp.Handle(
                new ClientMessage.ReadAllEventsForwardCompleted(
                    correlationId, ReadAllResult.Success, null,
                    new[] {
                EventStore.Core.Data.ResolvedEvent.ForUnresolvedEvent(
                    new EventRecord(
                        1, 50, Guid.NewGuid(), _firstEventId, 50, 0, "a", ExpectedVersion.Any,
                        _fakeTimeProvider.UtcNow,
                        PrepareFlags.SingleWrite | PrepareFlags.TransactionBegin | PrepareFlags.TransactionEnd,
                        "event_type1", new byte[] { 1 }, new byte[] { 2 }), 100),
                EventStore.Core.Data.ResolvedEvent.ForUnresolvedEvent(
                    new EventRecord(
                        2, 150, Guid.NewGuid(), _secondEventId, 150, 0, "b", ExpectedVersion.Any,
                        _fakeTimeProvider.UtcNow,
                        PrepareFlags.SingleWrite | PrepareFlags.TransactionBegin | PrepareFlags.TransactionEnd,
                        "event_type1", new byte[] { 1 }, new byte[] { 2 }), 200),
            }, null, false, 100,
                    new TFPos(200, 150), new TFPos(500, -1), new TFPos(100, 50), 500));
            correlationId = _consumer.HandledMessages.OfType <ClientMessage.ReadAllEventsForward>().Last().CorrelationId;
            _edp.Handle(
                new ClientMessage.ReadAllEventsForwardCompleted(
                    correlationId, ReadAllResult.Success, null,
                    new EventStore.Core.Data.ResolvedEvent[0], null, false, 100, new TFPos(), new TFPos(), new TFPos(),
                    500));
            _fakeTimeProvider.AddToUtcTime(TimeSpan.FromMilliseconds(500));
            correlationId = ((ClientMessage.ReadAllEventsForward)(_consumer.HandledMessages
                                                                  .OfType <AwakeServiceMessage.SubscribeAwake>().Last().ReplyWithMessage)).CorrelationId;
            _edp.Handle(
                new ClientMessage.ReadAllEventsForwardCompleted(
                    correlationId, ReadAllResult.Success, null,
                    new EventStore.Core.Data.ResolvedEvent[0], null, false, 100, new TFPos(), new TFPos(), new TFPos(),
                    500));
        }
コード例 #3
0
        public new void When()
        {
            _distibutionPointCorrelationId = Guid.NewGuid();
            _fakeTimeProvider = new FakeTimeProvider();
            _edp = new StreamEventReader(_bus, _distibutionPointCorrelationId, null, "stream", 10, _fakeTimeProvider,
                                         false,
                                         produceStreamDeletes: false);
            _edp.Resume();
            _firstEventId  = Guid.NewGuid();
            _secondEventId = Guid.NewGuid();
            var correlationId = _consumer.HandledMessages.OfType <ClientMessage.ReadStreamEventsForward>().Last()
                                .CorrelationId;

            _edp.Handle(
                new ClientMessage.ReadStreamEventsForwardCompleted(
                    correlationId, "stream", 100, 100, ReadStreamResult.Success,
                    new[] {
                ResolvedEvent.ForUnresolvedEvent(
                    new EventRecord(
                        10, 50, Guid.NewGuid(), _firstEventId, 50, 0, "stream", ExpectedVersion.Any,
                        DateTime.UtcNow,
                        PrepareFlags.SingleWrite | PrepareFlags.TransactionBegin | PrepareFlags.TransactionEnd,
                        "event_type1", new byte[] { 1 }, new byte[] { 2 })),
                ResolvedEvent.ForUnresolvedEvent(
                    new EventRecord(
                        11, 100, Guid.NewGuid(), _secondEventId, 100, 0, "stream", ExpectedVersion.Any,
                        DateTime.UtcNow,
                        PrepareFlags.SingleWrite | PrepareFlags.TransactionBegin | PrepareFlags.TransactionEnd,
                        "event_type2", new byte[] { 3 }, new byte[] { 4 }))
            }, null, false, "", 12, 11, true, 200));
            correlationId = _consumer.HandledMessages.OfType <ClientMessage.ReadStreamEventsForward>().Last()
                            .CorrelationId;
            _edp.Handle(
                new ClientMessage.ReadStreamEventsForwardCompleted(
                    correlationId, "stream", 100, 100, ReadStreamResult.Success,
                    new ResolvedEvent[] { }, null, false, "", 12, 11, true, 400));
            _fakeTimeProvider.AddToUtcTime(TimeSpan.FromMilliseconds(500));
            correlationId = ((ClientMessage.ReadStreamEventsForward)(_consumer.HandledMessages
                                                                     .OfType <AwakeServiceMessage.SubscribeAwake>().Last().ReplyWithMessage)).CorrelationId;
            _edp.Handle(
                new ClientMessage.ReadStreamEventsForwardCompleted(
                    correlationId, "stream", 100, 100, ReadStreamResult.Success,
                    new ResolvedEvent[] { }, null, false, "", 12, 11, true, 400));
        }
コード例 #4
0
        public new void When()
        {
            _ab12Tag = new Dictionary <string, long> {
                { "a", 1 }, { "b", 2 }
            };
            _abStreams = new[] { "a", "b" };

            _distibutionPointCorrelationId = Guid.NewGuid();
            _fakeTimeProvider = new FakeTimeProvider();
            _edp = new MultiStreamEventReader(
                _ioDispatcher, _bus, _distibutionPointCorrelationId, null, 0, _abStreams, _ab12Tag, false,
                _fakeTimeProvider);
            _edp.Resume();
            _firstEventId  = Guid.NewGuid();
            _secondEventId = Guid.NewGuid();
            var correlationId = _consumer.HandledMessages.OfType <ClientMessage.ReadStreamEventsForward>()
                                .Last(x => x.EventStreamId == "a").CorrelationId;

            _edp.Handle(
                new ClientMessage.ReadStreamEventsForwardCompleted(
                    correlationId, "a", 100, 100, ReadStreamResult.Success,
                    new[] {
                ResolvedEvent.ForUnresolvedEvent(
                    new EventRecord(
                        1, 50, Guid.NewGuid(), _firstEventId, 50, 0, "a", ExpectedVersion.Any,
                        _fakeTimeProvider.UtcNow,
                        PrepareFlags.SingleWrite | PrepareFlags.TransactionBegin | PrepareFlags.TransactionEnd,
                        "event_type1", new byte[] { 1 }, new byte[] { 2 })),
            }, null, false, "", 2, 1, true, 200));
            correlationId = _consumer.HandledMessages.OfType <ClientMessage.ReadStreamEventsForward>()
                            .Last(x => x.EventStreamId == "b").CorrelationId;
            _edp.Handle(
                new ClientMessage.ReadStreamEventsForwardCompleted(
                    correlationId, "b", 100, 100, ReadStreamResult.Success,
                    new[] {
                ResolvedEvent.ForUnresolvedEvent(
                    new EventRecord(
                        2, 100, Guid.NewGuid(), _secondEventId, 100, 0, "b", ExpectedVersion.Any,
                        _fakeTimeProvider.UtcNow,
                        PrepareFlags.SingleWrite | PrepareFlags.TransactionBegin | PrepareFlags.TransactionEnd,
                        "event_type1", new byte[] { 1 }, new byte[] { 2 })),
            }, null, false, "", 3, 2, true, 200));
            correlationId = _consumer.HandledMessages.OfType <ClientMessage.ReadStreamEventsForward>()
                            .Last(x => x.EventStreamId == "a").CorrelationId;
            _edp.Handle(
                new ClientMessage.ReadStreamEventsForwardCompleted(
                    correlationId, "a", 100, 100, ReadStreamResult.Success, new ResolvedEvent[] { }, null, false, "", 2,
                    1, true, 400));
            correlationId = _consumer.HandledMessages.OfType <ClientMessage.ReadStreamEventsForward>()
                            .Last(x => x.EventStreamId == "b").CorrelationId;
            _edp.Handle(
                new ClientMessage.ReadStreamEventsForwardCompleted(
                    correlationId, "b", 100, 100, ReadStreamResult.Success, new ResolvedEvent[] { }, null, false, "", 3,
                    2, true, 400));
            _fakeTimeProvider.AddToUtcTime(TimeSpan.FromMilliseconds(500));
            correlationId = ((ClientMessage.ReadStreamEventsForward)(_consumer.HandledMessages
                                                                     .OfType <AwakeServiceMessage.SubscribeAwake>().Last().ReplyWithMessage)).CorrelationId;
            _edp.Handle(
                new ClientMessage.ReadStreamEventsForwardCompleted(
                    correlationId, "a", 100, 100, ReadStreamResult.Success, new ResolvedEvent[] { }, null, false, "", 2,
                    1, true, 600));
        }