Example #1
0
        public async Task Ask_from_local_actor_without_remote_association_should_work()
        {
            // create actor in Sys1
            const string actorName = "actor1";

            Sys1.ActorOf(dsl => dsl.ReceiveAny((m, ctx) => TestActor.Tell(m)), actorName);

            // create ActorSelection from Sys2 --> Sys1
            var sel = Sys2.ActorSelection(new RootActorPath(Sys1Address) / "user" / actorName);

            // make sure that actor1 is able to resolve temporary actor's path
            // see https://github.com/akkadotnet/akka.net/issues/4384 - tmp actor should belong to Sys2 here
            var msg = await sel.Ask <ActorIdentity>(new Identify("foo"), TimeSpan.FromSeconds(30));

            msg.MessageId.Should().Be("foo");
        }
Example #2
0
        public async Task ConsistentHashingPoolRoutersShouldWorkAsExpectedWithHashMapping()
        {
            var poolRouter =
                Sys1.ActorOf(Props.Create(() => new ReporterActor(TestActor)).WithRouter(new ConsistentHashingPool(5,
                                                                                                                   msg =>
            {
                if (msg is IConsistentHashable c)
                {
                    return(c.ConsistentHashKey);
                }
                return(msg);
            })),
                             "router1");

            // use some auto-received messages to ensure that those still work
            var numRoutees = (await poolRouter.Ask <Routees>(new GetRoutees(), TimeSpan.FromSeconds(2))).Members.Count();

            // establish association between ActorSystems
            var sys2Probe   = CreateTestProbe(Sys2);
            var secondActor = Sys1.ActorOf(act => act.ReceiveAny((o, ctx) => ctx.Sender.Tell(o)), "foo");

            Sys2.ActorSelection(new RootActorPath(Sys1Address) / "user" / secondActor.Path.Name).Tell("foo", sys2Probe);
            sys2Probe.ExpectMsg("foo");

            // have ActorSystem2 message it via tell
            var sel = Sys2.ActorSelection(new RootActorPath(Sys1Address) / "user" / "router1");

            sel.Tell(new HashableString("foo"));
            ExpectMsg <HashableString>(str => str.Str.Equals("foo"));

            // have ActorSystem2 message it via Ask
            sel.Ask(new Identify("bar2"), TimeSpan.FromSeconds(3)).PipeTo(sys2Probe);
            var remoteRouter = sys2Probe.ExpectMsg <ActorIdentity>(x => x.MessageId.Equals("bar2"), TimeSpan.FromSeconds(5)).Subject;

            var s2Actor = Sys2.ActorOf(act =>
            {
                act.ReceiveAny((o, ctx) =>
                               sel.Ask <ActorIdentity>(new Identify(o), TimeSpan.FromSeconds(3)).PipeTo(sys2Probe));
            });

            s2Actor.Tell("hit");
            sys2Probe.ExpectMsg <ActorIdentity>(x => x.MessageId.Equals("hit"), TimeSpan.FromSeconds(5));
        }