public void AtLeastOnceDeliveryActorSetsDeliverySnapshotDuringRecovery()
        {
            var atLeastOnceDeliverySettings = new PersistenceSettings.AtLeastOnceDeliverySettings(TimeSpan.FromMilliseconds(200), 2, 5, 10);
            // TestActor is the destination actor.
            var alodActorProps = Props.Create <AlodActor>(atLeastOnceDeliverySettings, TestActor);
            var alodActor      = Sys.ActorOf(alodActorProps);

            alodActor.Tell(new Msg("payload"));
            Thread.Sleep(TimeSpan.FromSeconds(1)); // Allow for some retries.
            ExpectMsg <AlodEnvelope>(alode => LastSender.Tell(new Confirmation(alode.DeliveryId)));
            ReceiveWhile <object>(obj => obj as string == "Message delivered!", TimeSpan.FromSeconds(3));
            ReceiveWhile <object>(obj => true, TimeSpan.FromSeconds(3)); // Discard remaining messages.

            alodActor.Tell("snap");
            alodActor.Tell("delete");

            Watch(alodActor);
            alodActor.Tell(PoisonPill.Instance);
            ExpectTerminated(alodActor);
            Unwatch(alodActor);

            alodActor = Sys.ActorOf(alodActorProps);
            ExpectNoMsg(TimeSpan.FromSeconds(5));

            alodActor.Tell("last");
            ExpectMsg <long>(l => l == 1L);
        }
Exemplo n.º 2
0
        public void ImplicitSender_should_not_change_when_creating_TestActors()
        {
            var testActor2 = CreateTestActor("test2");

            TestActor.Tell("message");
            ReceiveOne();
            LastSender.ShouldBe(TestActor);
        }
        public void DistributedPubSubMediator_must_keep_track_of_added_users()
        {
            Within(TimeSpan.FromSeconds(15), () =>
            {
                RunOn(() =>
                {
                    var u1 = CreateChatUser("u1");
                    Mediator.Tell(new Put(u1));

                    var u2 = CreateChatUser("u2");
                    Mediator.Tell(new Put(u2));

                    AwaitCount(2);

                    // send to actor at the same node
                    u1.Tell(new Whisper("/user/u2", "hello"));
                    ExpectMsg("hello");
                    LastSender.Should().Be(u2);
                }, _first);

                RunOn(() =>
                {
                    var u3 = CreateChatUser("u3");
                    Mediator.Tell(new Put(u3));
                }, _second);

                RunOn(() =>
                {
                    AwaitCount(3);
                }, _first, _second);
                EnterBarrier("3-registered");

                RunOn(() =>
                {
                    var u4 = CreateChatUser("u4");
                    Mediator.Tell(new Put(u4));
                }, _second);

                RunOn(() =>
                {
                    AwaitCount(4);
                }, _first, _second);
                EnterBarrier("4-registered");

                RunOn(() =>
                {
                    // send to an actor on another node
                    ChatUser("u1").Tell(new Whisper("/user/u4", "hi there"));
                }, _first);

                RunOn(() =>
                {
                    ExpectMsg("hi there");
                    LastSender.Path.Name.Should().Be("u4");
                }, _second);
                EnterBarrier("after-2");
            });
        }
Exemplo n.º 4
0
        public void ImplicitSender_should_not_change_when_creating_Testprobes()
        {
            //Verifies that bug #459 has been fixed
            var testProbe = CreateTestProbe();

            TestActor.Tell("message");
            ReceiveOne();
            LastSender.ShouldBe(TestActor);
        }
Exemplo n.º 5
0
        public void Remoting_must_lookup_actors_across_node_boundaries()
        {
            Action <IActorDsl> act = dsl =>
            {
                dsl.Receive <Tuple <Props, string> >((t, ctx) => ctx.Sender.Tell(ctx.ActorOf(t.Item1, t.Item2)));
                dsl.Receive <string>((s, ctx) =>
                {
                    var sender = ctx.Sender;
                    ctx.ActorSelection(s).ResolveOne(TimeSpan.FromSeconds(3)).PipeTo(sender);
                });
            };

            var l = Sys.ActorOf(Props.Create(() => new Act(act)), "looker");

            // child is configured to be deployed on remote-sys (remoteSystem)
            l.Tell(Tuple.Create(Props.Create <Echo1>(), "child"));
            var child = ExpectMsg <IActorRef>();

            // grandchild is configured to be deployed on RemotingSpec (Sys)
            child.Tell(Tuple.Create(Props.Create <Echo1>(), "grandchild"));
            var grandchild = ExpectMsg <IActorRef>();

            grandchild.AsInstanceOf <IActorRefScope>().IsLocal.ShouldBeTrue();
            grandchild.Tell(43);
            ExpectMsg(43);
            var myRef = Sys.ActorSelection("/user/looker/child/grandchild").ResolveOne(TimeSpan.FromSeconds(3)).Result;

            (myRef is LocalActorRef).ShouldBeTrue(); // due to a difference in how ActorFor and ActorSelection are implemented, this will return a LocalActorRef
            myRef.Tell(44);
            ExpectMsg(44);
            LastSender.ShouldBe(grandchild);
            LastSender.ShouldBeSame(grandchild);
            child.AsInstanceOf <RemoteActorRef>().Parent.ShouldBe(l);

            var cRef = Sys.ActorSelection("/user/looker/child").ResolveOne(TimeSpan.FromSeconds(3)).Result;

            cRef.ShouldBe(child);
            l.Ask <IActorRef>("child/..", TimeSpan.FromSeconds(3)).Result.ShouldBe(l);
            Sys.ActorSelection("/user/looker/child").Ask <ActorSelection>(new ActorSelReq(".."), TimeSpan.FromSeconds(3))
            .ContinueWith(ts => ts.Result.ResolveOne(TimeSpan.FromSeconds(3))).Unwrap().Result.ShouldBe(l);

            Watch(child);
            child.Tell(PoisonPill.Instance);
            ExpectMsg("postStop");
            ExpectTerminated(child);
            l.Tell(Tuple.Create(Props.Create <Echo1>(), "child"));
            var child2 = ExpectMsg <IActorRef>();

            child2.Tell(45);
            ExpectMsg(45);
            // msg to old IActorRef (different uid) should not get through
            child2.Path.Uid.ShouldNotBe(child.Path.Uid);
            child.Tell(46);
            ExpectNoMsg(TimeSpan.FromSeconds(1));
            Sys.ActorSelection("user/looker/child").Tell(47);
            ExpectMsg(47);
        }
Exemplo n.º 6
0
        public void A_lightweight_creator_must_support_nested_declarations()
        {
            var a = Sys.ActorOf(act =>
            {
                var b = act.ActorOf(act2 =>
                {
                    act2.OnPreStart = context => context.Parent.Tell("hello from " + context.Self.Path);
                }, "barney");
                act.ReceiveAny((x, _) => TestActor.Tell(x));
            }, "fred");

            ExpectMsg("hello from akka://" + Sys.Name + "/user/fred/barney");
            LastSender.ShouldBe(a);
        }
Exemplo n.º 7
0
        public async Task A_Graph_stage_ActorRef_must_be_able_to_be_replied_to()
        {
            var t = Source.Maybe <int>().ToMaterialized(SumStage(TestActor), Keep.Both).Run(Materializer);

            var stageRef = ExpectMsg <IActorRef>();

            stageRef.Tell(new AddAndTell(1));
            ExpectMsg(1);
            stageRef.Should().Be(LastSender);
            LastSender.Tell(new AddAndTell(9));
            ExpectMsg(10);

            stageRef.Tell(StopNow.Instance);
            (await t.Item2).Should().Be(10);
        }
Exemplo n.º 8
0
        public void A_Graph_stage_ActorRef_must_be_able_to_be_replied_to()
        {
            var t   = Source.Maybe <int>().ToMaterialized(SumStage(TestActor), Keep.Both).Run(Materializer);
            var res = t.Item2;

            var stageRef = ExpectMsg <IActorRef>();

            stageRef.Tell(new AddAndTell(1));
            ExpectMsg(1);
            stageRef.Should().Be(LastSender);
            LastSender.Tell(new AddAndTell(9));
            ExpectMsg(10);

            stageRef.Tell(StopNow.Instance);
            res.Wait(TimeSpan.FromSeconds(3)).Should().BeTrue();
            res.Result.Should().Be(10);
        }
Exemplo n.º 9
0
        public void Creating_routees_must_allow_sending_to_context_parent()
        {
            int n = 100;

            Sys.ActorOf(new RoundRobinPool(n).Props(Props.Create(() => new ForwardActor(TestActor))));
            var gotIt = ReceiveWhile <string>(msg =>
            {
                if (msg.Equals("two"))
                {
                    return(LastSender.ToString());
                }

                return(null);
            }, msgs: n);

            ExpectNoMsg(100.Milliseconds());

            gotIt.Count.Should().Be(n, $"Got only {gotIt.Count} from [{string.Join(", ", gotIt)}]");
        }
Exemplo n.º 10
0
        public async Task A_Graph_stage_ActorRef_must_yield_the_same_self_ref_each_time()
        {
            var t = Source.Maybe <int>().ToMaterialized(SumStage(TestActor), Keep.Both).Run(Materializer);

            var stageRef = ExpectMsg <IActorRef>();

            stageRef.Tell(CallInitStageActorRef.Instance);
            var explicitlyObtained = ExpectMsg <IActorRef>();

            stageRef.Should().Be(explicitlyObtained);
            explicitlyObtained.Tell(new AddAndTell(1));
            ExpectMsg(1);
            LastSender.Tell(new AddAndTell(2));
            ExpectMsg(3);
            stageRef.Tell(new AddAndTell(3));
            ExpectMsg(6);

            stageRef.Tell(StopNow.Instance);

            (await t.Item2).Should().Be(6);
        }
Exemplo n.º 11
0
        public void A_Graph_stage_ActorRef_must_yield_the_same_self_ref_each_time()
        {
            var t   = Source.Maybe <int>().ToMaterialized(SumStage(TestActor), Keep.Both).Run(Materializer);
            var res = t.Item2;

            var stageRef = ExpectMsg <IActorRef>();

            stageRef.Tell(CallInitStageActorRef.Instance);
            var explicitlyObtained = ExpectMsg <IActorRef>();

            stageRef.Should().Be(explicitlyObtained);
            explicitlyObtained.Tell(new AddAndTell(1));
            ExpectMsg(1);
            LastSender.Tell(new AddAndTell(2));
            ExpectMsg(3);
            stageRef.Tell(new AddAndTell(3));
            ExpectMsg(6);

            stageRef.Tell(StopNow.Instance);
            res.Wait(TimeSpan.FromSeconds(3)).Should().BeTrue();
            res.Result.Should().Be(6);
        }
Exemplo n.º 12
0
 public void An_ActorSelection_must_forward_to_selection()
 {
     _c2.Tell(new Forward("c21", "hello"), TestActor);
     ExpectMsg("hello");
     LastSender.ShouldBe(_c21);
 }
Exemplo n.º 13
0
 public void An_ActorSelection_must_send_messages_to_actor_path()
 {
     Sys.ActorSelection(_c2.Path / "c21").Tell(new GetSender(TestActor));
     ExpectMsg(TestActor);
     LastSender.ShouldBe(_c21);
 }
Exemplo n.º 14
0
 public void An_ActorSelection_must_send_messages_to_string_path()
 {
     Sys.ActorSelection("/user/c2/c21").Tell(new GetSender(TestActor));
     ExpectMsg(TestActor);
     LastSender.ShouldBe(_c21);
 }
Exemplo n.º 15
0
 public void An_ActorSelection_must_send_messages_directly()
 {
     new ActorSelection(_c1, "").Tell(new GetSender(TestActor));
     ExpectMsg(TestActor);
     LastSender.ShouldBe(_c1);
 }
Exemplo n.º 16
0
        public void Remoting_must_select_actors_across_node_boundaries()
        {
            Action <IActorDsl> act = dsl =>
            {
                dsl.Receive <Tuple <Props, string> >((t, ctx) => ctx.Sender.Tell(ctx.ActorOf(t.Item1, t.Item2)));
                dsl.Receive <ActorSelReq>((req, ctx) => ctx.Sender.Tell(ctx.ActorSelection(req.S)));
            };

            var l = Sys.ActorOf(Props.Create(() => new Act(act)), "looker");

            // child is configured to be deployed on remoteSystem
            l.Tell(Tuple.Create(Props.Create <Echo1>(), "child"));
            var child = ExpectMsg <IActorRef>();

            // grandchild is configured to be deployed on RemotingSpec (system)
            child.Tell(Tuple.Create(Props.Create <Echo1>(), "grandchild"));
            var grandchild = ExpectMsg <IActorRef>();

            (grandchild as IActorRefScope).IsLocal.ShouldBeTrue();
            grandchild.Tell(53);
            ExpectMsg(53);
            var myself = Sys.ActorSelection("user/looker/child/grandchild");

            myself.Tell(54);
            ExpectMsg(54);
            LastSender.ShouldBe(grandchild);
            LastSender.ShouldBeSame(grandchild);
            myself.Tell(new Identify(myself));
            var grandchild2 = ExpectMsg <ActorIdentity>().Subject;

            grandchild2.ShouldBe(grandchild);
            Sys.ActorSelection("user/looker/child").Tell(new Identify(null));
            ExpectMsg <ActorIdentity>().Subject.ShouldBe(child);
            l.Tell(new ActorSelReq("child/.."));
            ExpectMsg <ActorSelection>().Tell(new Identify(null));
            ExpectMsg <ActorIdentity>().Subject.ShouldBeSame(l);
            Sys.ActorSelection("user/looker/child").Tell(new ActorSelReq(".."));
            ExpectMsg <ActorSelection>().Tell(new Identify(null));
            ExpectMsg <ActorIdentity>().Subject.ShouldBeSame(l);

            grandchild.Tell(Tuple.Create(Props.Create <Echo1>(), "grandgrandchild"));
            var grandgrandchild = ExpectMsg <IActorRef>();

            Sys.ActorSelection("/user/looker/child").Tell(new Identify("idReq1"));
            ExpectMsg <ActorIdentity>(i => i.MessageId.Equals("idReq1")).Subject.ShouldBe(child);

            Sys.ActorSelection(child.Path).Tell(new Identify("idReq2"));
            ExpectMsg <ActorIdentity>(i => i.MessageId.Equals("idReq2")).Subject.ShouldBe(child);
            Sys.ActorSelection("/user/looker/*").Tell(new Identify("idReq3"));
            ExpectMsg <ActorIdentity>(i => i.MessageId.Equals("idReq3")).Subject.ShouldBe(child);

            Sys.ActorSelection("/user/looker/child/grandchild").Tell(new Identify("idReq4"));
            ExpectMsg <ActorIdentity>(i => i.MessageId.Equals("idReq4")).Subject.ShouldBe(grandchild);

            Sys.ActorSelection(child.Path / "grandchild").Tell(new Identify("idReq5"));
            ExpectMsg <ActorIdentity>(i => i.MessageId.Equals("idReq5")).Subject.ShouldBe(grandchild);
            Sys.ActorSelection("/user/looker/*/grandchild").Tell(new Identify("idReq6"));
            ExpectMsg <ActorIdentity>(i => i.MessageId.Equals("idReq6")).Subject.ShouldBe(grandchild);
            Sys.ActorSelection("/user/looker/child/*").Tell(new Identify("idReq7"));
            ExpectMsg <ActorIdentity>(i => i.MessageId.Equals("idReq7")).Subject.ShouldBe(grandchild);

            Sys.ActorSelection(child.Path / "*").Tell(new Identify("idReq8"));
            ExpectMsg <ActorIdentity>(i => i.MessageId.Equals("idReq8")).Subject.ShouldBe(grandchild);

            Sys.ActorSelection("/user/looker/child/grandchild/grandgrandchild").Tell(new Identify("idReq9"));
            ExpectMsg <ActorIdentity>(i => i.MessageId.Equals("idReq9")).Subject.ShouldBe(grandgrandchild);

            Sys.ActorSelection(child.Path / "grandchild" / "grandgrandchild").Tell(new Identify("idReq10"));
            ExpectMsg <ActorIdentity>(i => i.MessageId.Equals("idReq10")).Subject.ShouldBe(grandgrandchild);
            Sys.ActorSelection("/user/looker/child/*/grandgrandchild").Tell(new Identify("idReq11"));
            ExpectMsg <ActorIdentity>(i => i.MessageId.Equals("idReq11")).Subject.ShouldBe(grandgrandchild);
            Sys.ActorSelection("/user/looker/child/*/*").Tell(new Identify("idReq12"));
            ExpectMsg <ActorIdentity>(i => i.MessageId.Equals("idReq12")).Subject.ShouldBe(grandgrandchild);

            Sys.ActorSelection(child.Path / "*" / "grandgrandchild").Tell(new Identify("idReq13"));
            ExpectMsg <ActorIdentity>(i => i.MessageId.Equals("idReq13")).Subject.ShouldBe(grandgrandchild);

            //ActorSelection doesn't support ToSerializationFormat directly
            //var sel1 = Sys.ActorSelection("/user/looker/child/grandchild/grandgrandchild");
            //Sys.ActorSelection(sel1.ToSerializationFormat()).Tell(new Identify("idReq18"));
            //ExpectMsg<ActorIdentity>(i => i.MessageId.Equals("idReq18")).Subject.ShouldBe(grandgrandchild);

            child.Tell(new Identify("idReq14"));
            ExpectMsg <ActorIdentity>(i => i.MessageId.Equals("idReq14")).Subject.ShouldBe(child);
            Watch(child);
            child.Tell(PoisonPill.Instance);
            ExpectMsg("postStop");
            ExpectMsg <Terminated>().ActorRef.ShouldBe(child);
            l.Tell(Tuple.Create(Props.Create <Echo1>(), "child"));
            var child2 = ExpectMsg <IActorRef>();

            child2.Tell(new Identify("idReq15"));
            ExpectMsg <ActorIdentity>(i => i.MessageId.Equals("idReq15")).Subject.ShouldBe(child2);

            Sys.ActorSelection(child.Path).Tell(new Identify("idReq16"));
            ExpectMsg <ActorIdentity>(i => i.MessageId.Equals("idReq16")).Subject.ShouldBe(child2);
            child.Tell(new Identify("idReq17"));
            ExpectMsg <ActorIdentity>(i => i.MessageId.Equals("idReq17")).Subject.ShouldBe(null);

            child2.Tell(55);
            ExpectMsg(55);
            // msg to old ActorRef (different uid) should not get through
            child2.Path.Uid.ShouldNotBe(child.Path.Uid);
            child.Tell(56);
            ExpectNoMsg(TimeSpan.FromSeconds(1));
            Sys.ActorSelection("user/looker/child").Tell(57);
            ExpectMsg(57);
        }