public new void When()
        {
            _distibutionPointCorrelationId = Guid.NewGuid();
            _fakeTimeProvider = new FakeTimeProvider();
            _edp = new TransactionFileEventReader(
                _ioDispatcher, _bus, _distibutionPointCorrelationId, null, new TFPos(100, 50), _fakeTimeProvider,
                deliverEndOfTFPosition: false);
            _edp.Resume();
            _firstEventId = Guid.NewGuid();
            _secondEventId = Guid.NewGuid();
            _edp.Handle(
                new ClientMessage.ReadAllEventsForwardCompleted(
                    _distibutionPointCorrelationId, ReadAllResult.Success, null,
                    new[]
                    {
                        new ResolvedEvent(
                            new EventRecord(
                                1, 50, Guid.NewGuid(), _firstEventId, 50, 0, "a", ExpectedVersion.Any,
                                _fakeTimeProvider.Now,
                                PrepareFlags.SingleWrite | PrepareFlags.TransactionBegin | PrepareFlags.TransactionEnd,
                                "event_type1", new byte[] {1}, new byte[] {2}), null, 100),
                        new ResolvedEvent(
                            new EventRecord(
                                2, 150, Guid.NewGuid(), _secondEventId, 150, 0, "a", ExpectedVersion.Any,
                                _fakeTimeProvider.Now,
                                PrepareFlags.SingleWrite | PrepareFlags.TransactionBegin | PrepareFlags.TransactionEnd,
                                SystemEventTypes.StreamDeleted, new byte[] {1}, new byte[] {2}), null, 200),
                    }, null, false, 100,
                    new TFPos(200, 150), new TFPos(500, -1), new TFPos(100, 50), 500));

        }
 public new void When()
 {
     //_publishWithCorrelationId = Guid.NewGuid();
     _distibutionPointCorrelationId = Guid.NewGuid();
     _fakeTimeProvider = new FakeTimeProvider();
     _edp = new StreamEventReader(
         _ioDispatcher, _bus, _distibutionPointCorrelationId, null, "stream", 10, _fakeTimeProvider,
         resolveLinkTos: false, stopOnEof: true, produceStreamDeletes: false);
     _edp.Resume();
     _firstEventId = Guid.NewGuid();
     _secondEventId = Guid.NewGuid();
     _edp.Handle(
         new ClientMessage.ReadStreamEventsForwardCompleted(
             _distibutionPointCorrelationId, "stream", 100, 100, ReadStreamResult.Success, 
             new[]
                 {
                     new ResolvedEvent(
                 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}), null),
                     new ResolvedEvent(
                 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)
                 }, null, false, "", 12, 11, true, 200));
     _edp.Handle(
         new ClientMessage.ReadStreamEventsForwardCompleted(
             _distibutionPointCorrelationId, "stream", 100, 100, ReadStreamResult.Success, new ResolvedEvent[] { }, null, false, "", 12, 11, true, 400));
 }
        public new void When()
        {
            _ab12Tag = new Dictionary<string, int> {{"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();
            _edp.Handle(
                new ClientMessage.ReadStreamEventsForwardCompleted(
                    _distibutionPointCorrelationId, "a", 100, 100, ReadStreamResult.Success, 
                    new[]
                        {
                            new ResolvedEvent(
                        new EventRecord(
                            1, 50, Guid.NewGuid(), _firstEventId, 50, 0, "a", ExpectedVersion.Any, _fakeTimeProvider.Now,
                            PrepareFlags.SingleWrite | PrepareFlags.TransactionBegin | PrepareFlags.TransactionEnd,
                            "event_type1", new byte[] {1}, new byte[] {2}), null),
                        }, null, false, "", 2, 1, true, 200));
            _edp.Handle(
                new ClientMessage.ReadStreamEventsForwardCompleted(
                    _distibutionPointCorrelationId, "b", 100, 100, ReadStreamResult.Success, 
                    new[]
                        {
                            new ResolvedEvent(
                        new EventRecord(
                            2, 100, Guid.NewGuid(), _secondEventId, 100, 0, "b", ExpectedVersion.Any, _fakeTimeProvider.Now,
                            PrepareFlags.SingleWrite | PrepareFlags.TransactionBegin | PrepareFlags.TransactionEnd,
                            "event_type1", new byte[] {1}, new byte[] {2}), null),
                        }, null, false, "", 3, 2, true, 200));
            _edp.Handle(
                new ClientMessage.ReadStreamEventsForwardCompleted(
                    _distibutionPointCorrelationId, "a", 100, 100, ReadStreamResult.Success, new ResolvedEvent[] { }, null, false, "", 2, 1, true, 400));
            _edp.Handle(
                new ClientMessage.ReadStreamEventsForwardCompleted(
                    _distibutionPointCorrelationId, "b", 100, 100, ReadStreamResult.Success, new ResolvedEvent[] { }, null, false, "", 3, 2, true, 400));
            _fakeTimeProvider.AddTime(TimeSpan.FromMilliseconds(500));
            _edp.Handle(
                new ClientMessage.ReadStreamEventsForwardCompleted(
                    _distibutionPointCorrelationId, "a", 100, 100, ReadStreamResult.Success, new ResolvedEvent[] { }, null, false, "", 2, 1, true, 600));
        }
        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();
            _edp.Handle(
                new ClientMessage.ReadAllEventsForwardCompleted(
                    _distibutionPointCorrelationId, ReadAllResult.Success, null,
                    new[]
                    {
                        EventStore.Core.Data.ResolvedEvent.ForUnresolvedEvent(
                            new EventRecord(
                                1, 50, Guid.NewGuid(), _firstEventId, 50, 0, "a", ExpectedVersion.Any,
                                _fakeTimeProvider.Now,
                                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.Now,
                                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));

            _edp.Handle(
                new ClientMessage.ReadAllEventsForwardCompleted(
                    _distibutionPointCorrelationId, ReadAllResult.Success, null,
                    new EventStore.Core.Data.ResolvedEvent[0], null, false, 100, new TFPos(), new TFPos(), new TFPos(), 500));
            _fakeTimeProvider.AddTime(TimeSpan.FromMilliseconds(500));
            _edp.Handle(
                new ClientMessage.ReadAllEventsForwardCompleted(
                    _distibutionPointCorrelationId, ReadAllResult.Success, null,
                    new EventStore.Core.Data.ResolvedEvent[0], null, false, 100, new TFPos(), new TFPos(), new TFPos(), 500));
        }
 public void When()
 {
     _publishWithCorrelationId = Guid.NewGuid();
     _distibutionPointCorrelationId = Guid.NewGuid();
     _fakeTimeProvider = new FakeTimeProvider();
     _edp = new StreamEventReader(_bus, _distibutionPointCorrelationId, "stream", 10, _fakeTimeProvider, false);
     _edp.Resume();
     _firstEventId = Guid.NewGuid();
     _secondEventId = Guid.NewGuid();
     _edp.Handle(
         new ClientMessage.ReadStreamEventsForwardCompleted(
             _distibutionPointCorrelationId, "stream", 100, 100, ReadStreamResult.Success, 
             new[]
                 {
                     new ResolvedEvent(
                 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}), null),
                     new ResolvedEvent(
                 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)
                 }, "", 12, 11, true, 200));
     _edp.Handle(
         new ClientMessage.ReadStreamEventsForwardCompleted(
             _distibutionPointCorrelationId, "stream", 100, 100, ReadStreamResult.Success, 
             new ResolvedEvent[] { }, "", 12, 11, true, 400));
     _fakeTimeProvider.AddTime(TimeSpan.FromMilliseconds(500));
     _edp.Handle(
         new ClientMessage.ReadStreamEventsForwardCompleted(
             _distibutionPointCorrelationId, "stream", 100, 100, ReadStreamResult.Success, 
             new ResolvedEvent[] { }, "", 12, 11, true, 400));
 }
 protected override void Given()
 {
     _checkpointAfterMs = 1000;
     _checkpointProcessedEventsThreshold = 1;
     _timeProvider = new FakeTimeProvider();
 }
示例#7
0
        public void Setup()
        {
            var address    = IPAddress.Loopback;
            var members    = new List <MemberInfo>();
            var seeds      = new List <IPEndPoint>();
            var seedSource = new ReallyNotSafeFakeGossipSeedSource(seeds);

            _nodes = new Dictionary <IPEndPoint, IPublisher>();
            for (int i = 0; i < 3; i++)
            {
                var inputBus  = new InMemoryBus($"ELECTIONS-INPUT-BUS-NODE-{i}", watchSlowMsg: false);
                var outputBus = new InMemoryBus($"ELECTIONS-OUTPUT-BUS-NODE-{i}", watchSlowMsg: false);
                var endPoint  = new IPEndPoint(address, 1000 + i);
                seeds.Add(endPoint);
                var instanceId = Guid.Parse($"101EFD13-F9CD-49BE-9C6D-E6AF9AF5540{i}");
                members.Add(MemberInfo.ForVNode(instanceId, DateTime.UtcNow, VNodeState.Unknown, true,
                                                endPoint, null, endPoint, null, endPoint, endPoint, -1, 0, 0, -1, -1, Guid.Empty, 0, false)
                            );
                var nodeInfo = new VNodeInfo(instanceId, 0, endPoint, endPoint, endPoint, endPoint, endPoint,
                                             endPoint, false);
                _fakeTimeProvider = new FakeTimeProvider();
                _scheduler        = new FakeScheduler(new FakeTimer(), _fakeTimeProvider);
                var timerService = new TimerService(_scheduler);

                var         writerCheckpoint   = new InMemoryCheckpoint();
                var         readerCheckpoint   = new InMemoryCheckpoint();
                var         epochManager       = new FakeEpochManager();
                Func <long> lastCommitPosition = () => - 1;
                var         electionsService   = new Core.Services.ElectionsService(outputBus,
                                                                                    nodeInfo,
                                                                                    3,
                                                                                    writerCheckpoint,
                                                                                    readerCheckpoint,
                                                                                    epochManager,
                                                                                    () => - 1, 0, new FakeTimeProvider());
                electionsService.SubscribeMessages(inputBus);

                outputBus.Subscribe <HttpMessage.SendOverHttp>(this);
                var nodeId = i;
                outputBus.Subscribe(new AdHocHandler <Message>(
                                        m => {
                    switch (m)
                    {
                    case TimerMessage.Schedule sm:
                        TestContext.WriteLine(
                            $"Node {nodeId} : Delay {sm.TriggerAfter} : {sm.ReplyMessage.GetType()}");
                        timerService.Handle(sm);
                        break;

                    case HttpMessage.SendOverHttp hm:
                        TestContext.WriteLine($"Node {nodeId} : EP {hm.EndPoint} : {hm.Message.GetType()}");
                        break;

                    default:
                        TestContext.WriteLine($"Node {nodeId} : EP {m.GetType()}");
                        inputBus.Publish(m);
                        break;
                    }
                }
                                        ));
                _nodes.Add(endPoint, inputBus);

                var gossip = new NodeGossipService(outputBus, seedSource, nodeInfo, writerCheckpoint, readerCheckpoint,
                                                   epochManager, lastCommitPosition, 0, TimeSpan.FromMilliseconds(500), TimeSpan.FromDays(1),
                                                   _fakeTimeProvider);
                inputBus.Subscribe <SystemMessage.SystemInit>(gossip);
                inputBus.Subscribe <GossipMessage.RetrieveGossipSeedSources>(gossip);
                inputBus.Subscribe <GossipMessage.GotGossipSeedSources>(gossip);
                inputBus.Subscribe <GossipMessage.Gossip>(gossip);
                inputBus.Subscribe <GossipMessage.GossipReceived>(gossip);
                inputBus.Subscribe <SystemMessage.StateChangeMessage>(gossip);
                inputBus.Subscribe <GossipMessage.GossipSendFailed>(gossip);
                inputBus.Subscribe <GossipMessage.UpdateNodePriority>(gossip);
                inputBus.Subscribe <SystemMessage.VNodeConnectionEstablished>(gossip);
                inputBus.Subscribe <SystemMessage.VNodeConnectionLost>(gossip);
            }

            _members = members;
        }
示例#8
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));
        }
 public static void Init(TestContext context)
 {
     _timeProvider = new FakeTimeProvider();
     TimeProviderAccessor.SetTimeProvider(_timeProvider);
 }