public void GivenAnyTime_WhenProcessTerminates_ShouldLogStartRemovingProcess() { manager.Tell(new StartProcessCommand(processId)); EventFilter.Info("Removing process.") .ExpectOne(() => Sys.Stop(process)); }
public void ShoudLogPlayMovie() { IActorRef actor = ActorOf(Props.Create(() => new UserActor(ActorOf(BlackHoleActor.Props)))); EventFilter.Info("Started playing Boolean Lies").And.Info("Replying to sender") .Expect(2, () => actor.Tell(new PlayMovieMessage("Boolean Lies"))); }
public void UserIdentityActor_should_log_user_indexing_operation() { EventFilter.Info("indexing users").ExpectOne(() => { _identity.Tell(new UserIdentityActor.IndexUsers()); }); }
public void CanLoadStateFromSnapshotStore() { const string ACTOR_NAME = "test-actorX"; const string EXPECTED_STATE = "Ken Hartley Reed"; var snapshots = InMemoryPersistence.Get(Sys).SnapshotSource; snapshots.Add(new SnapshotEntry() { Id = ACTOR_NAME + "_0", PersistenceId = ACTOR_NAME, SequenceNr = 0, Snapshot = new TestActorState() { State = EXPECTED_STATE }, Timestamp = 1 }); // verify the SnapshotOffer was triggered when we create our actor EventFilter.Info(message: "SnapshotOffer received.").ExpectOne(() => { var snapshotActor = Sys.ActorOf(Props.Create(() => new PersistBySnapshotTestActor()), ACTOR_NAME); snapshotActor.Tell(new GetStateCommand()); }); ExpectMsg <string>(msg => msg == EXPECTED_STATE); }
public void GivenProcessExist_WhenProcessTerminates_ShouldLogRemovingProcess() { manager.Tell(new StartProcessCommand(processId)); EventFilter.Info($"Removing process with Id: {processId}.") .ExpectOne(() => Sys.Stop(process)); }
public void Must_suspend_dead_letters_logging_when_reaching_akka_log_dead_letters_and_then_re_enable() { EventFilter .Info(start: ExpectedDeadLettersLogMessage(1)) .Expect(1, () => _deadActor.Tell(1)); EventFilter .Info(start: ExpectedDroppedLogMessage(2)) .Expect(1, () => _droppingActor.Tell(2)); EventFilter .Info(start: ExpectedUnhandledLogMessage(3)) .Expect(1, () => _unhandledActor.Tell(3)); EventFilter .Info(start: ExpectedDeadLettersLogMessage(4) + ", no more dead letters will be logged in next") .Expect(1, () => _deadActor.Tell(4)); _deadActor.Tell(5); _droppingActor.Tell(6); // let suspend-duration elapse Thread.Sleep(2050); // re-enabled EventFilter .Info(start: ExpectedDeadLettersLogMessage(7) + ", of which 2 were not logged") .Expect(1, () => _deadActor.Tell(7)); // reset count EventFilter .Info(start: ExpectedDeadLettersLogMessage(1)) .Expect(1, () => _deadActor.Tell(8)); }
public void LoggingActor_should_log_info_message_on_valid_operation_2() { // doing same thing, but checking for messages that contain this instead EventFilter.Info(contains: "completed").ExpectOne(() => { _logger.Tell(new ValidData()); }); }
public void Persistence_should_auto_start_journal_and_snapshotstore_when_specified() { EventFilter.Info(message: "Auto-starting journal plugin `akka.persistence.journal.test`") .And.Info(message: "Auto-starting snapshot store `akka.persistence.snapshot-store.test`").Expect(2, () => { var persistence = Persistence.Instance.Apply(Sys); }); }
public void ShouldLogEvent() { var actor = ActorOf(Props.Create(() => new UserActor(ActorOf(BlackHoleActor.Props)))); EventFilter.Info("Started playing Batman") .And .Info("Replying to sender") .Expect(2, () => actor.Tell(new PlayMovieMessage("Batman"))); }
public void LoggingActor_should_log_info_message_on_valid_operation() { // listen for specific INFO log message that valid data op should trigger // by default, this looks for an exact match on the data passed in EventFilter.Info("Completed operation with valid data").ExpectOne(() => { _logger.Tell(new ValidData()); }); }
protected void MuteMarkingAsReachable(ActorSystem system = null) { var sys = system ?? Sys; if (!sys.Log.IsDebugEnabled) { EventFilter.Info(new Regex(".*Marking.* as REACHABLE.*")).Mute(); } }
public void GivenProcessExists_WhenDomainEvent_ShouldLogDelegatingToProcess() { var evnt = Substitute.For <DomainEvent>(processId); manager.Tell(new StartProcessCommand(processId)); EventFilter.Info($"Delegating event to process with Id: {processId}.") .ExpectOne(() => manager.Tell(evnt)); }
/// <summary> /// The expected log info pattern to intercept after a <see cref="Cluster.Down(Address)"/>. /// </summary> /// <param name="expected"></param> protected void Down(string expected) { Within(TimeSpan.FromSeconds(10), () => { EventFilter .Info(contains: expected) .ExpectOne(() => _cluster.Down(_selfAddress)); }); }
public void ShouldLogStopMessage() { // Arrange var actor = ActorOf(Props.Create(() => new CloudBackupActor(SourceFolderPathsFilePath))); // Act-Assert EventFilter.Info(LogMessageParts.ReceivedStop).ExpectOne(() => { actor.Tell(new StopMessage()); }); }
public void TestPublishNotSupporteddMessage() { var subject = SetUpTestActorRef(); var testProbe = CreateTestProbeAndSubscribeToFoo(subject); EventFilter.Info("PublishMessage of Type OopsMessage failed. Type not valid").ExpectOne(() => { subject.UnderlyingActor.PublishMessage(new OopsMessage("Oops")); testProbe.ExpectNoMsg(TimeSpan.FromSeconds(0.3)); }); }
public void WhenReceivedStringMessage_ShouldLogNoChangesDetected() { // Arrange var actor = ActorOf(Props.Create(() => new BackupStatisticsActor())); // Act-Assert string path = "some zip path"; string noChangesDetected = string.Format("No changes detected in {0}...", path); string received = string.Format("Received: {0}", noChangesDetected); EventFilter .Info(received) .Expect(expectedCount: 1, action: () => actor.Tell(noChangesDetected)); }
public void ShouldLogIncrementFolderCountMessage() { // Arrange var actor = ActorOf(Props.Create(() => new CloudBackupActor(SourceFolderPathsFilePath))); string path = ZipSourceFolderPath; // Act-Assert EventFilter .Info(message: null, start: null, contains: LogMessageParts.ReceivedIncrementFolderCount) .ExpectOne(() => { actor.Tell(new IncrementFolderCountMessage(new ZipMessage(path, ZipKind.Regular).ZipKind)); }); }
public void testParentChild() { var probe = CreateTestProbe(); var subject = Sys.ActorOf(Props.Create(() => new Master())); subject.Tell(new Master.Initialize(5)); Regex regex = new Regex(@"\[Reply received] Word count: [0-9]+"); EventFilter.Info(regex).Expect(3, () => { subject.Tell("Akka is awesome!"); subject.Tell("Akka!"); subject.Tell("Scala!"); }); }
public void ClusterClient_must_reestablish_connection_to_receptionist_after_server_restart() { Within(30.Seconds(), () => { RunOn(() => { _remainingServerRoleNames.Count.Should().Be(1); var remainingContacts = _remainingServerRoleNames.Select(r => Node(r) / "system" / "receptionist").ToImmutableHashSet(); var c = Sys.ActorOf(ClusterClient.Props(ClusterClientSettings.Create(Sys).WithInitialContacts(remainingContacts)), "client4"); c.Tell(new ClusterClient.Send("/user/service2", "bonjour4", localAffinity: true)); var reply = ExpectMsg <ClusterClientSpecConfig.Reply>(10.Seconds()); reply.Msg.Should().Be("bonjour4-ack"); reply.Node.Should().Be(remainingContacts.First().Address); // TODO: bug, cannot compare with a logsource var logSource = $"{Sys.AsInstanceOf<ExtendedActorSystem>().Provider.DefaultAddress}/user/client4"; EventFilter.Info(start: "Connected to").ExpectOne(() => { EventFilter.Info(start: "Lost contact").ExpectOne(() => { // shutdown server TestConductor.Shutdown(_remainingServerRoleNames.First()).Wait(); }); }); c.Tell(new ClusterClient.Send("/user/service2", "shutdown", localAffinity: true)); Thread.Sleep(2000); // to ensure that it is sent out before shutting down system }, _config.Client); RunOn(() => { Sys.WhenTerminated.Wait(20.Seconds()); // start new system on same port var port = Cluster.Get(Sys).SelfAddress.Port; var sys2 = ActorSystem.Create( Sys.Name, ConfigurationFactory.ParseString($"akka.remote.dot-netty.tcp.port={port}").WithFallback(Sys.Settings.Config)); Cluster.Get(sys2).Join(Cluster.Get(sys2).SelfAddress); var service2 = sys2.ActorOf(Props.Create(() => new ClusterClientSpecConfig.TestService(TestActor)), "service2"); ClusterClientReceptionist.Get(sys2).RegisterService(service2); sys2.WhenTerminated.Wait(20.Seconds()); }, _remainingServerRoleNames.ToArray()); }); }
public void Can_Log_ClassicFormat() { IActorRef loggingTestActor = ActorOf(Props.Create( () => new LoggingTestActor() )); loggingTestActor.Tell("Test1"); Within(TimeSpan.FromSeconds(2), () => { EventFilter.Info("Recieved message 'Test1'.").Match(); ExpectMsg <string>("Message 1 Received"); }); loggingTestActor.Tell("Test Two"); Within(TimeSpan.FromSeconds(2), () => { EventFilter.Info("Recieved message 'Test Two'.").Match(); ExpectMsg <string>("Message 2 Received"); }); }
public void CanLoadFromJournal() { const string ACTOR_NAME = "test-actor"; const string EXPECTED_STATE01 = "State01"; const string EXPECTED_STATE02 = "State02"; var journal = InMemoryPersistence.Get(Sys).JournalSource; var metadata = InMemoryPersistence.Get(Sys).MetadataSource; journal.Add(new JournalEntry() { Id = ACTOR_NAME + "_2", PersistenceId = ACTOR_NAME, SequenceNr = 2, Manifest = "", Payload = new SetStateCommand(EXPECTED_STATE02) }); journal.Add(new JournalEntry() { Id = ACTOR_NAME + "_1", PersistenceId = ACTOR_NAME, SequenceNr = 1, Manifest = "", Payload = new SetStateCommand(EXPECTED_STATE01) }); metadata.Add(new MetadataEntry() { Id = ACTOR_NAME, PersistenceId = ACTOR_NAME, SequenceNr = 2 }); EventFilter.Info(message: "Recovering SetStateCommand.").Expect(2, () => { var actor = Sys.ActorOf(Props.Create(() => new PersistByJournalTestActor()), ACTOR_NAME); actor.Tell(new GetStateCommand()); ExpectMsg <string>(msg => msg == EXPECTED_STATE02); }); }
//TODO: ExpectedTestDuration? void MuteLog(ActorSystem sys = null) { if (sys == null) { sys = Sys; } if (!sys.Log.IsDebugEnabled) { var patterns = new[] { ".*Metrics collection has started successfully.*", ".*Cluster Node.* - is starting up.*", ".*Shutting down cluster Node.*", ".*Cluster node successfully shut down.*", ".*Using a dedicated scheduler for cluster.*" }; foreach (var pattern in patterns) { EventFilter.Info(new Regex(pattern)).Mute(); } MuteDeadLetters(sys, typeof(ClusterHeartbeatSender.Heartbeat), typeof(ClusterHeartbeatSender.HeartbeatRsp), typeof(GossipEnvelope), typeof(GossipStatus), typeof(GossipStatus), typeof(MetricsGossipEnvelope), typeof(ClusterEvent.ClusterMetricsChanged), typeof(InternalClusterAction.ITick), typeof(PoisonPill), typeof(DeathWatchNotification), typeof(Disassociated), typeof(DisassociateUnderlying), typeof(InboundPayload)); } }
public void ShouldLogUpAndRunnning() { EventFilter.Info("Paas up and running...") .ExpectOne(() => ActorOf <PaasActor>()); }
public void GivenNewProcess_WhenStartProcessCommand_ShouldLogFinnishCreatingProcess() { EventFilter.Info($"Created process with Id: {processId}.") .ExpectOne(() => manager.Tell(new StartProcessCommand(processId))); }
/// <summary> /// The expected log info pattern to intercept after a <see cref="Cluster.Down(Address)"/>. /// </summary> /// <param name="expected"></param> protected void Down(string expected) { EventFilter .Info(contains: expected) .ExpectOne(() => _cluster.Down(_selfAddress)); }