public void Requests_matched_events_be_written_to_index() { var query = new ProjectionStreamQuery(new DomainEventPredicate(typeof(TestEvent))); var writer = CreateTestProbe(); var props = ProjectionStream.CreateProps(query, CreateWorkingReader(), writer, new GlobalOptions()); var ps = Sys.ActorOf(props); ps.Tell(MockPersistedEvent.Create(new object(), 1)); ps.Tell(MockPersistedEvent.Create(new TestEvent(), 2)); ps.Tell(MockPersistedEvent.Create(new object(), 3)); ps.Tell(MockPersistedEvent.Create(new TestEvent(), 4)); ps.Tell(MockPersistedEvent.Create(new object(), 5)); writer.ExpectMsg <ProjectionIndexPersistenceRequest>(m => m.ProjectionStream.Equals(query.ProjectionStream) && m.ProjectionStreamSequence == 1 && m.GlobalSequence == 2); writer.ExpectMsg <ProjectionIndexPersistenceRequest>(m => m.ProjectionStream.Equals(query.ProjectionStream) && m.ProjectionStreamSequence == 2 && m.GlobalSequence == 4); writer.ExpectNoMsg(TimeSpan.FromMilliseconds(500)); }
IActorRef CreateWorkingReader(int eventCount = 0) { return(Sys.ActorOf(conf => { conf.Receive <ReadProjectionCheckpointRequest>((r, ctx) => { ctx.Sender.Tell(new ReadProjectionCheckpointResponse(r.RequestID, eventCount)); }); conf.Receive <ReadRequest>((r, ctx) => { for (var i = 0; i < eventCount; i++) { var domainEvent = new TestEvent(); var e = MockPersistedEvent.Create(new TestEvent(), i + 1); ctx.Sender.Tell(new ReadResponse(r.RequestID, e)); } ctx.Sender.Tell(new ReadFinished(r.RequestID)); }); })); }
public void Publishes_events_from_eventstream_to_subscribers() { var reader = CreateWorkingReader(); var query = new ProjectionStreamQuery(new DomainEventPredicate(typeof(TestEvent))); var props = ProjectionStream.CreateProps(query, reader, ActorRefs.Nobody, new GlobalOptions()); var ps = Sys.ActorOf(props); var subscriber = Sys.ActorOf(conf => { conf.Receive <ProjectionReplayFinished>((r, ctx) => { }); conf.ReceiveAny((o, ctx) => TestActor.Forward(o)); }); // subscribe ps.Tell(new ProjectionSubscriptionRequest(query, 0), subscriber); //publish to event stream var e = MockPersistedEvent.Create(new TestEvent()); Sys.EventStream.Publish(e); // expects the domain event to be the same ExpectMsg <IPersistedStreamEvent>(m => m.DomainEvent == e.DomainEvent, TimeSpan.FromSeconds(15)); }
public void Subscribers_that_received_RebuildProjection_need_to_resubscribe_to_receive_messages() { var reader = CreateWorkingReader(); var query = new ProjectionStreamQuery(new DomainEventPredicate(typeof(TestEvent))); var props = ProjectionStream.CreateProps(query, reader, ActorRefs.Nobody, new GlobalOptions()); var ps = Sys.ActorOf(props); var subscriber = Sys.ActorOf(conf => { conf.Receive <RebuildProjection>((r, ctx) => { }); conf.ReceiveAny((o, ctx) => TestActor.Forward(o)); }); // subscribe with invalid sequence ps.Tell(new ProjectionSubscriptionRequest(query, 10), subscriber); //publish to event stream var e = MockPersistedEvent.Create(new TestEvent()); Sys.EventStream.Publish(e); // expects the domain event to be the same ExpectNoMsg(TimeSpan.FromSeconds(1)); }