public ProjectionSubscriptionRequest(ProjectionStreamQuery query, int lastKnownSequence) { Argument.RequiresNotNull(query, nameof(query)); Argument.Requires(lastKnownSequence >= 0, nameof(lastKnownSequence)); Query = query; LastKnownSequence = lastKnownSequence; }
public ProjectionSubscriptionRequest(ProjectionStreamQuery query, int lastKnownSequence) { Argument.RequiresNotNull(query, nameof(query)); Argument.Requires(lastKnownSequence >= 0, nameof(lastKnownSequence)); Query = query; LastKnownSequence = lastKnownSequence; }
public static Props CreateProps(ProjectionStreamQuery query, IActorRef reader, IActorRef writer, GlobalOptions options, Props replayWorkerProps = null) { Argument.RequiresNotNull(query, nameof(query)); Argument.RequiresNotNull(reader, nameof(reader)); Argument.RequiresNotNull(writer, nameof(writer)); Argument.RequiresNotNull(options, nameof(options)); return Props.Create<ProjectionStream>(query, reader, writer, options, replayWorkerProps); }
public TestContainer(TestKitBase testKit, GlobalOptions options = null, Type replayWorkerType = null) { var query = new ProjectionStreamQuery(); Reader = testKit.CreateTestProbe(); Writer = testKit.CreateTestProbe(); options = options ?? new GlobalOptions(); var props = Even.ProjectionStream.CreateProps(query, Reader, Writer, options); ProjectionStream = testKit.Sys.ActorOf(props); }
public void Sends_ProjectionReplayFinished_to_uptodate_subscriber() { var reader = CreateWorkingReader(); var query = new ProjectionStreamQuery(); var props = ProjectionStream.CreateProps(query, reader, ActorRefs.Nobody, new GlobalOptions()); var ps = Sys.ActorOf(props); var subscriber = CreateTestProbe(); ps.Tell(new ProjectionSubscriptionRequest(query, 0), subscriber); subscriber.ExpectMsg <ProjectionReplayFinished>(); }
public void Sends_RebuildProjection_to_subscriber_with_unknown_sequence() { var reader = CreateWorkingReader(0); var query = new ProjectionStreamQuery(); var props = ProjectionStream.CreateProps(query, reader, ActorRefs.Nobody, new GlobalOptions()); var ps = Sys.ActorOf(props); var subscriber = CreateTestProbe(); // projection stream only knows event 0, projection says it knows 99 ps.Tell(new ProjectionSubscriptionRequest(query, 99), subscriber); subscriber.ExpectMsg <RebuildProjection>(); }
public TestContainer(TestKitBase testKit, GlobalOptions options = null, Type replayWorkerType = null) { var query = new ProjectionStreamQuery(); Reader = testKit.CreateTestProbe(); Writer = testKit.CreateTestProbe(); options = options ?? new GlobalOptions(); var props = Even.ProjectionStream.CreateProps(query, Reader, Writer, options); ProjectionStream = testKit.Sys.ActorOf(props); }
public void SubscriptionRequest_with_past_sequence_starts_projection_replay_worker() { var workerProps = Props.Create <ProbeRelay>(TestActor); var reader = CreateWorkingReader(1); var query = new ProjectionStreamQuery(new DomainEventPredicate(typeof(TestEvent))); var props = ProjectionStream.CreateProps(query, reader, ActorRefs.Nobody, new GlobalOptions(), workerProps); var ps = Sys.ActorOf(props); var subscriber = CreateTestProbe(); ps.Tell(new ProjectionSubscriptionRequest(query, 0), subscriber); ExpectMsg <InitializeProjectionReplayWorker>(); }
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)); }
public ProjectionStream(ProjectionStreamQuery query, IActorRef reader, IActorRef writer, GlobalOptions options, Props replayWorkerProps) { _query = query; _reader = reader; _writer = writer; _options = options; _replayWorkerProps = replayWorkerProps ?? Props.Create<ProjectionReplayWorker>(); // subscribe to events in the stream Context.System.EventStream.Subscribe(Self, typeof(IPersistedEvent)); // request checkpoint var request = new ReadProjectionCheckpointRequest(_query.ProjectionStream); _lastRequestId = request.RequestID; _reader.Tell(request); Become(AwaitingCheckpoint); }
public async Task Sends_ProjectionUnsubscribed_to_subscribers_on_restart() { var query = new ProjectionStreamQuery(); var reader = CreateWorkingReader(); var props = ProjectionStream.CreateProps(query, reader, ActorRefs.Nobody, new GlobalOptions()); var ps = Sys.ActorOf(props); var subscriber = Sys.ActorOf(conf => { conf.Receive <ProjectionReplayFinished>((m, ctx) => { }); conf.ReceiveAny((o, ctx) => TestActor.Forward(o)); }); ps.Tell(new ProjectionSubscriptionRequest(query, 0), subscriber); await Task.Delay(100); ps.Tell(Kill.Instance); ExpectMsg <ProjectionUnsubscribed>(); }
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)); }
public async Task Sends_ProjectionUnsubscribed_to_subscribers_on_restart() { var query = new ProjectionStreamQuery(); var reader = CreateWorkingReader(); var props = ProjectionStream.CreateProps(query, reader, ActorRefs.Nobody, new GlobalOptions()); var ps = Sys.ActorOf(props); var subscriber = Sys.ActorOf(conf => { conf.Receive<ProjectionReplayFinished>((m, ctx) => { }); conf.ReceiveAny((o, ctx) => TestActor.Forward(o)); }); ps.Tell(new ProjectionSubscriptionRequest(query, 0), subscriber); await Task.Delay(100); ps.Tell(Kill.Instance); ExpectMsg<ProjectionUnsubscribed>(); }
public void Sends_ProjectionReplayFinished_to_uptodate_subscriber() { var reader = CreateWorkingReader(); var query = new ProjectionStreamQuery(); var props = ProjectionStream.CreateProps(query, reader, ActorRefs.Nobody, new GlobalOptions()); var ps = Sys.ActorOf(props); var subscriber = CreateTestProbe(); ps.Tell(new ProjectionSubscriptionRequest(query, 0), subscriber); subscriber.ExpectMsg<ProjectionReplayFinished>(); }
public void Sends_RebuildProjection_to_subscriber_with_unknown_sequence() { var reader = CreateWorkingReader(0); var query = new ProjectionStreamQuery(); var props = ProjectionStream.CreateProps(query, reader, ActorRefs.Nobody, new GlobalOptions()); var ps = Sys.ActorOf(props); var subscriber = CreateTestProbe(); // projection stream only knows event 0, projection says it knows 99 ps.Tell(new ProjectionSubscriptionRequest(query, 99), subscriber); subscriber.ExpectMsg<RebuildProjection>(); }
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)); }
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)); }
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 SubscriptionRequest_with_past_sequence_starts_projection_replay_worker() { var workerProps = Props.Create<ProbeRelay>(TestActor); var reader = CreateWorkingReader(1); var query = new ProjectionStreamQuery(new DomainEventPredicate(typeof(TestEvent))); var props = ProjectionStream.CreateProps(query, reader, ActorRefs.Nobody, new GlobalOptions(), workerProps); var ps = Sys.ActorOf(props); var subscriber = CreateTestProbe(); ps.Tell(new ProjectionSubscriptionRequest(query, 0), subscriber); ExpectMsg<InitializeProjectionReplayWorker>(); }