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 Receives_events_after_replay() { var proj = CreateAndInitializeTestProjection(); var e = MockPersistedStreamEvent.Create(new TestEvent(), stream: _testStream); proj.Tell(e); ExpectMsg <IPersistedStreamEvent <TestEvent> >(TimeSpan.FromSeconds(15)); }
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>(); }
IActorRef CreateWorkingReader(int eventCount = 0) { var reader = Sys.ActorOf(conf => { conf.Receive <ReadStreamRequest>((r, ctx) => { for (var i = 1; i <= eventCount; i++) { var e = MockPersistedStreamEvent.Create(new SampleEvent1(), i, i, TestStream); ctx.Sender.Tell(new ReadStreamResponse(r.RequestID, e)); } ctx.Sender.Tell(new ReadStreamFinished(r.RequestID)); }); }); return(reader); }