public void Sends_read_events_to_subscriber()
        {
            var reader = Sys.ActorOf(conf =>
            {
                conf.Receive<ReadIndexedProjectionStreamRequest>((r, ctx) =>
                {
                    for (var i = 1; i <= 3; i++)
                    {
                        var e = MockPersistedStreamEvent.Create(new TestEvent(), i, i);
                        ctx.Sender.Tell(new ReadIndexedProjectionStreamResponse(r.RequestID, e));
                    }

                    ctx.Sender.Tell(new ReadIndexedProjectionStreamFinished(r.RequestID, 3));
                });
            });

            var request = new ProjectionSubscriptionRequest(new ProjectionStreamQuery(), 0);

            var worker = Sys.ActorOf<ProjectionReplayWorker>();
            worker.Tell(new InitializeProjectionReplayWorker(reader, TestActor, request, 3, new GlobalOptions()));

            ExpectMsg<ProjectionReplayEvent>(m => m.Event.StreamSequence == 1);
            ExpectMsg<ProjectionReplayEvent>(m => m.Event.StreamSequence == 2);
            ExpectMsg<ProjectionReplayEvent>(m => m.Event.StreamSequence == 3);
            ExpectMsg<ProjectionReplayFinished>();
        }
        public void Requests_events_to_reader()
        {
            var request = new ProjectionSubscriptionRequest(new ProjectionStreamQuery(), 0);
            var worker = Sys.ActorOf<ProjectionReplayWorker>();
            worker.Tell(new InitializeProjectionReplayWorker(TestActor, ActorRefs.Nobody, request, 1, new GlobalOptions()));

            ExpectMsg<ReadIndexedProjectionStreamRequest>();
        }
        public void Worker_terminates_on_ReadFinished()
        {
            var reader = Sys.ActorOf(conf =>
            {
                conf.Receive<ReadIndexedProjectionStreamRequest>((r, ctx) =>
                {
                    ctx.Sender.Tell(new ReadIndexedProjectionStreamFinished(r.RequestID, 0));
                });
            });

            var request = new ProjectionSubscriptionRequest(new ProjectionStreamQuery(), 0);

            var worker = Sys.ActorOf<ProjectionReplayWorker>();
            worker.Tell(new InitializeProjectionReplayWorker(reader, ActorRefs.Nobody, request, 0, new GlobalOptions()));

            Watch(worker);
            ExpectTerminated(worker);
        }
Esempio n. 4
0
        public InitializeProjectionReplayWorker(IActorRef reader, IActorRef subscriber, ProjectionSubscriptionRequest subscriptionRequest, int lastSequenceToRead, GlobalOptions options)
        {
            Argument.RequiresNotNull(reader, nameof(reader));
            Argument.RequiresNotNull(subscriber, nameof(subscriber));
            Argument.RequiresNotNull(subscriptionRequest, nameof(subscriptionRequest));
            Argument.RequiresNotNull(options, nameof(options));

            this.Reader = reader;
            this.Subscriber = subscriber;
            this.SubscriptionRequest = subscriptionRequest;
            this.LastSequenceToRead = lastSequenceToRead;
            this.Options = options;
        }
Esempio n. 5
0
        private void StartProjectionReplayWorker(ProjectionSubscriptionRequest ps)
        {
            var props = _replayWorkerProps.WithSupervisorStrategy(new OneForOneStrategy(ex => Directive.Stop));

            var worker = Context.ActorOf(props);
            worker.Tell(new InitializeProjectionReplayWorker(_reader, Sender, ps, _currentSequence, _options));
        }
        public void Worker_requests_until_all_events_are_read()
        {
            var canFinish = false;

            var reader = Sys.ActorOf(conf =>
            {
                conf.Receive<ReadIndexedProjectionStreamRequest>((r, ctx) =>
                {
                    var start = r.InitialSequence;
                    int end;

                    if (canFinish)
                        end = start + r.Count;
                    else
                        end = start + 2;

                    for (var i = start; i <= end; i++)
                    {
                        var e = MockPersistedStreamEvent.Create(new TestEvent(), i, i);
                        ctx.Sender.Tell(new ReadIndexedProjectionStreamResponse(r.RequestID, e));
                    }

                    ctx.Sender.Tell(new ReadIndexedProjectionStreamFinished(r.RequestID, end));
                });
            });

            var request = new ProjectionSubscriptionRequest(new ProjectionStreamQuery(), 0);
            var options = new GlobalOptions { ProjectionReplayRetryInterval = TimeSpan.FromMilliseconds(600) };
            var worker = Sys.ActorOf<ProjectionReplayWorker>();
            worker.Tell(new InitializeProjectionReplayWorker(reader, TestActor, request, 5, new GlobalOptions()));

#pragma warning disable 4014
            Task.Delay(500).ContinueWith(_ => canFinish = true);
#pragma warning restore 4014

            ExpectMsg<ProjectionReplayEvent>(m => m.Event.StreamSequence == 1);
            ExpectMsg<ProjectionReplayEvent>(m => m.Event.StreamSequence == 2);
            ExpectMsg<ProjectionReplayEvent>(m => m.Event.StreamSequence == 3);
            ExpectMsg<ProjectionReplayEvent>(m => m.Event.StreamSequence == 4);
            ExpectMsg<ProjectionReplayEvent>(m => m.Event.StreamSequence == 5);
            ExpectMsg<ProjectionReplayFinished>();
        }