public void RemoteActorRefProvider_should_create_RemoteActorRef_for_nonlocaladdress()
 {
     var nonLocalAddress = new Address("akka.trttl.gremlin.tcp", Sys.Name, "localhost", RARP.For(Sys).Provider.DefaultAddress.Port);
     var nonLocalActorPath = new RootActorPath(nonLocalAddress) / "user" / "foo";
     var resolved = RARP.For(Sys).Provider.ResolveActorRefWithLocalAddress(nonLocalActorPath.ToSerializationFormat(), nonLocalAddress);
     Assert.IsType<RemoteActorRef>(resolved); // should be a remote actorref
 }
        private void HandleMemberUp(ClusterEvent.MemberUp x)
        {
            var rootPath  = new RootActorPath(x.Member.Address);
            var selection = Context.ActorSelection($"{rootPath}/user/*");

            selection.Tell(new Identify("1"));
        }
        public void Inspecting_cluster_sharding_state_should_get_shard_state()
        {
            Within(TimeSpan.FromSeconds(10), () =>
            {
                AwaitAssert(() =>
                {
                    var probe = CreateTestProbe();
                    _region.Value.Tell(GetCurrentRegions.Instance, probe.Ref);
                    var regions = probe.ExpectMsg <CurrentRegions>().Regions;
                    regions.Count.Should().Be(2);

                    foreach (var region in regions)
                    {
                        var path = new RootActorPath(region) / "system" / "sharding" / ShardTypeName;
                        Sys.ActorSelection(path).Tell(GetShardRegionState.Instance, probe.Ref);
                    }

                    var states       = probe.ReceiveWhile(null, m => (CurrentShardRegionState)m, regions.Count);
                    var allEntityIds = states.SelectMany(i => i.Shards).SelectMany(j => j.EntityIds).ToImmutableHashSet();
                    allEntityIds.Should().BeEquivalentTo(new string[] { "1", "2", "3", "4" });
                });
            });

            EnterBarrier("done");
        }
Esempio n. 4
0
        public void A_child_pathIs_equal_to_itself()
        {
            var root           = new RootActorPath("/");
            var childActorPath = new ChildActorPath(root, "Path", 1);

            childActorPath.Equals(childActorPath).Should().BeTrue();
        }
Esempio n. 5
0
        public void Setup(BenchmarkContext context)
        {
            _remoteMessageThroughput = context.GetCounter(RemoteMessageCounterName);
            System1 = ActorSystem.Create("SystemA" + ActorSystemNameCounter.Next(), CreateActorSystemConfig("SystemA" + ActorSystemNameCounter.Current, "127.0.0.1", 0));
            _echo   = System1.ActorOf(Props.Create(() => new EchoActor()), "echo");

            System2   = ActorSystem.Create("SystemB" + ActorSystemNameCounter.Next(), CreateActorSystemConfig("SystemB" + ActorSystemNameCounter.Current, "127.0.0.1", 0));
            _receiver =
                System2.ActorOf(
                    Props.Create(() => new BenchmarkActor(_remoteMessageThroughput, RemoteMessageCount, _resetEvent)),
                    "benchmark");

            var system1Address = RARP.For(System1).Provider.Transport.DefaultAddress;
            var system2Address = RARP.For(System2).Provider.Transport.DefaultAddress;

            var system1EchoActorPath   = new RootActorPath(system1Address) / "user" / "echo";
            var system2RemoteActorPath = new RootActorPath(system2Address) / "user" / "benchmark";

            try
            {
                // set the timeout high here to avoid timeouts
                // TL;DR; - on slow machines it can take longer than 2 seconds to form the association, do the handshake, and reply back
                // using the in-memory transport.
                _remoteReceiver =
                    System1.ActorSelection(system2RemoteActorPath).ResolveOne(TimeSpan.FromSeconds(30)).Result;
                _remoteEcho =
                    System2.ActorSelection(system1EchoActorPath).ResolveOne(TimeSpan.FromSeconds(2)).Result;
            }
            catch (Exception ex)
            {
                context.Trace.Error(ex, "error occurred during setup.");
                throw; // re-throw the error to blow up the benchmark
            }
        }
Esempio n. 6
0
        public void Two_root_paths_with_same_name_Are_equal()
        {
            var root1 = new RootActorPath("root");
            var root2 = new RootActorPath("root");

            root1.CompareTo(root2).Should().Be(0);
        }
Esempio n. 7
0
        public void Must_quarantine_systems_after_unsuccessful_system_message_delivery_if_have_not_communicated_before()
        {
            // Synthesize an ActorRef to a remote system this one has never talked to before.
            // This forces ReliableDeliverySupervisor to start with unknown remote system UID.
            var rarp = RARP.For(Sys).Provider;
            int port = rarp.DefaultAddress.Port.Value;

            while (port == rarp.DefaultAddress.Port.Value || port == 2666)
            {
                port = ThreadLocalRandom.Current.Next(1, 65535);
            }

            var extinctPath = new RootActorPath(new Address("akka.tcp", "extinct-system", "localhost", port)) / "user" / "noone";
            var transport   = rarp.Transport;
            var extinctRef  = new RemoteActorRef(transport, transport.LocalAddressForRemote(extinctPath.Address),
                                                 extinctPath, ActorRefs.Nobody, Props.None, Deploy.None);

            var probe = CreateTestProbe();

            probe.Watch(extinctRef);
            probe.Unwatch(extinctRef);

            probe.ExpectNoMsg(TimeSpan.FromSeconds(5));
            Sys.EventStream.Subscribe(probe.Ref, typeof(Warning));
            probe.ExpectNoMsg(TimeSpan.FromSeconds(rarp.RemoteSettings.RetryGateClosedFor.TotalSeconds * 2));
        }
Esempio n. 8
0
 public RootGuardianSupervisor(RootActorPath root, IActorRefProvider provider, TaskCompletionSource<Status> terminationPromise, ILoggingAdapter log)
 {
     _log = log;
     _terminationPromise = terminationPromise;
     _provider = provider;
     _path = root / "_Root-guardian-supervisor";   //In akka this is root / "bubble-walker" 
 }
Esempio n. 9
0
        public void Create_correct_ToString_with_address()
        {
            var local = new Address("akka.tcp", "mysys");
            var a     = new Address("akka.tcp", "mysys", "aaa", 2552);
            var b     = new Address("akka.tcp", "mysys", "bb", 2552);
            var c     = new Address("akka.tcp", "mysys", "cccc", 2552);
            var d     = new Address("akka.tcp", "mysys", "192.168.107.1", 2552);
            var root  = new RootActorPath(local);

            root.ToStringWithAddress(a).ShouldBe("akka.tcp://mysys@aaa:2552/");
            (root / "user").ToStringWithAddress(a).ShouldBe("akka.tcp://mysys@aaa:2552/user");
            (root / "user" / "foo").ToStringWithAddress(a).ShouldBe("akka.tcp://mysys@aaa:2552/user/foo");

            root.ToStringWithAddress(b).ShouldBe("akka.tcp://mysys@bb:2552/");
            (root / "user").ToStringWithAddress(b).ShouldBe("akka.tcp://mysys@bb:2552/user");
            (root / "user" / "foo").ToStringWithAddress(b).ShouldBe("akka.tcp://mysys@bb:2552/user/foo");

            root.ToStringWithAddress(c).ShouldBe("akka.tcp://mysys@cccc:2552/");
            (root / "user").ToStringWithAddress(c).ShouldBe("akka.tcp://mysys@cccc:2552/user");
            (root / "user" / "foo").ToStringWithAddress(c).ShouldBe("akka.tcp://mysys@cccc:2552/user/foo");


            root.ToStringWithAddress(d).ShouldBe("akka.tcp://[email protected]:2552/");
            (root / "user").ToStringWithAddress(d).ShouldBe("akka.tcp://[email protected]:2552/user");
            (root / "user" / "foo").ToStringWithAddress(d).ShouldBe("akka.tcp://[email protected]:2552/user/foo");

            var rootA = new RootActorPath(a);

            rootA.ToStringWithAddress(b).ShouldBe("akka.tcp://mysys@aaa:2552/");
            (rootA / "user").ToStringWithAddress(b).ShouldBe("akka.tcp://mysys@aaa:2552/user");
            (rootA / "user" / "foo").ToStringWithAddress(b).ShouldBe("akka.tcp://mysys@aaa:2552/user/foo");
        }
Esempio n. 10
0
        public void Two_root_paths_with_different_name_Are_not_equal()
        {
            var root1 = new RootActorPath("root1");
            var root2 = new RootActorPath("root2");

            root1.Equals(root2).Should().BeFalse();
        }
        public void Setup(BenchmarkContext context)
        {
            _remoteMessageThroughput = context.GetCounter(RemoteMessageCounterName);
            System1 = ActorSystem.Create("SystemA" + ActorSystemNameCounter.Next(), CreateActorSystemConfig("SystemA" + ActorSystemNameCounter.Current, "127.0.0.1", 0));
            _echo = System1.ActorOf(Props.Create(() => new EchoActor()), "echo");

            System2 = ActorSystem.Create("SystemB" + ActorSystemNameCounter.Next(), CreateActorSystemConfig("SystemB" + ActorSystemNameCounter.Current, "127.0.0.1", 0));
            _receiver =
                System2.ActorOf(
                    Props.Create(() => new BenchmarkActor(_remoteMessageThroughput, RemoteMessageCount, _resetEvent)),
                    "benchmark");

            var system1Address = RARP.For(System1).Provider.Transport.DefaultAddress;
            var system2Address = RARP.For(System2).Provider.Transport.DefaultAddress;

            var system1EchoActorPath = new RootActorPath(system1Address) / "user" / "echo";
            var system2RemoteActorPath = new RootActorPath(system2Address) / "user" / "benchmark";

            // set the timeout high here to avoid timeouts
            // TL;DR; - on slow machines it can take longer than 2 seconds to form the association, do the handshake, and reply back
            // using the in-memory transport.
            _remoteReceiver = System1.ActorSelection(system2RemoteActorPath).ResolveOne(TimeSpan.FromSeconds(30)).Result;
            _remoteEcho =
                System2.ActorSelection(system1EchoActorPath).ResolveOne(TimeSpan.FromSeconds(2)).Result;
        }
Esempio n. 12
0
        public void A_child_pathIs_equal_to_itself()
        {
            var root           = new RootActorPath("/");
            var childActorPath = new ChildActorPath(root, "Path", 1);

            childActorPath.CompareTo(childActorPath).Should().Be(0);
        }
Esempio n. 13
0
        public void CreateCorrectToStringWithAddress()
        {
            var local = new Address("akka.tcp", "mysys");
            var a = new Address("akka.tcp", "mysys", "aaa", 2552);
            var b = new Address("akka.tcp", "mysys", "bb", 2552);
            var c = new Address("akka.tcp", "mysys", "cccc" , 2552);
            var root = new RootActorPath(local);
            root.ToStringWithAddress(a).ShouldBe("akka.tcp://mysys@aaa:2552/");
            (root / "user").ToStringWithAddress(a).ShouldBe("akka.tcp://mysys@aaa:2552/user");
            (root / "user" / "foo").ToStringWithAddress(a).ShouldBe("akka.tcp://mysys@aaa:2552/user/foo");

            root.ToStringWithAddress(b).ShouldBe("akka.tcp://mysys@bb:2552/");
            (root / "user").ToStringWithAddress(b).ShouldBe("akka.tcp://mysys@bb:2552/user");
            (root / "user" / "foo").ToStringWithAddress(b).ShouldBe("akka.tcp://mysys@bb:2552/user/foo");

            root.ToStringWithAddress(c).ShouldBe("akka.tcp://mysys@cccc:2552/");
            (root / "user").ToStringWithAddress(c).ShouldBe("akka.tcp://mysys@cccc:2552/user");
            (root / "user" / "foo").ToStringWithAddress(c).ShouldBe("akka.tcp://mysys@cccc:2552/user/foo");

            var rootA = new RootActorPath(a);
            rootA.ToStringWithAddress(b).ShouldBe("akka.tcp://mysys@aaa:2552/");
            (rootA / "user").ToStringWithAddress(b).ShouldBe("akka.tcp://mysys@aaa:2552/user");
            (rootA / "user" / "foo").ToStringWithAddress(b).ShouldBe("akka.tcp://mysys@aaa:2552/user/foo");

        }
Esempio n. 14
0
        public TraceLocalActorRefProvider(string systemName, Settings settings, EventStream eventStream, Deployer deployer, Func <ActorPath, IInternalActorRef> deadLettersFactory)
        {
            var rootPath = new RootActorPath(new Address("akka", systemName));

            Log = Logging.GetLogger(eventStream, "TraceLocalActorRefProvider(" + rootPath.Address + ")");
            _localActorRefProvider = new LocalActorRefProvider(systemName, settings, eventStream, deployer, deadLettersFactory);
        }
Esempio n. 15
0
        public void Two_root_paths_with_same_name_Have_same_hashcode()
        {
            var root1 = new RootActorPath("root");
            var root2 = new RootActorPath("root");

            root1.GetHashCode().Should().Be(root2.GetHashCode());
        }
Esempio n. 16
0
        public void Two_root_paths_with_different_name_Have_different_hashcodes()
        {
            var root1 = new RootActorPath("root1");
            var root2 = new RootActorPath("root2");

            root1.GetHashCode().Should().NotBe(root2.GetHashCode());
        }
Esempio n. 17
0
        public void Two_root_paths_with_same_name_Are_equal()
        {
            var root1 = new RootActorPath("root");
            var root2 = new RootActorPath("root");

            root1.Equals(root2).Should().BeTrue();
        }
        public void RemoteActorRefProvider_should_create_RemoteActorRef_for_nonlocaladdress()
        {
            var nonLocalAddress   = new Address("akka.trttl.gremlin.tcp", Sys.Name, "localhost", RARP.For(Sys).Provider.DefaultAddress.Port);
            var nonLocalActorPath = new RootActorPath(nonLocalAddress) / "user" / "foo";
            var resolved          = RARP.For(Sys).Provider.ResolveActorRefWithLocalAddress(nonLocalActorPath.ToSerializationFormat(), nonLocalAddress);

            Assert.IsType <RemoteActorRef>(resolved); // should be a remote actorref
        }
Esempio n. 19
0
        public void Fix2151_not_throw_NRE_on_RootActorPath_ElementsWithUid()
        {
            var a     = new Address("akka.tcp", "mysys");
            var rootA = new RootActorPath(a);
            var uid   = rootA.ElementsWithUid;

            Assert.True(uid.Count == 0); // RootActorPaths return no elements
        }
Esempio n. 20
0
        public void Two_child_paths_with_same_name_but_different_ids_Have_same_hashcodes()
        {
            var root            = new RootActorPath("/");
            var childActorPath1 = new ChildActorPath(root, "Path", 1);
            var childActorPath2 = new ChildActorPath(root, "Path", 2);

            childActorPath1.GetHashCode().Should().Be(childActorPath2.GetHashCode());
        }
Esempio n. 21
0
        public void Two_child_paths_with_sane_name_Are_equal()
        {
            var root            = new RootActorPath("/");
            var childActorPath1 = new ChildActorPath(root, "Path 1", 1);
            var childActorPath2 = new ChildActorPath(root, "Path 1", 1);

            childActorPath1.GetHashCode().Should().Be(childActorPath2.GetHashCode());
        }
Esempio n. 22
0
        public void Two_child_paths_with_different_name_Are_not_equal()
        {
            var root            = new RootActorPath("/");
            var childActorPath1 = new ChildActorPath(root, "Path 1", 1);
            var childActorPath2 = new ChildActorPath(root, "Path 2", 1);

            childActorPath1.Equals(childActorPath2).Should().BeFalse();
        }
Esempio n. 23
0
        public void Two_root_paths_with_different_name_Are_compared_correctly()
        {
            var root1 = new RootActorPath("A");
            var root2 = new RootActorPath("B");

            root1.CompareTo(root2).Should().BeLessOrEqualTo(-1);
            root2.CompareTo(root1).Should().BeLessOrEqualTo(1);
        }
Esempio n. 24
0
        public void Two_child_paths_with_same_name_but_different_ids_Are_equal()
        {
            var root            = new RootActorPath("/");
            var childActorPath1 = new ChildActorPath(root, "Path", 1);
            var childActorPath2 = new ChildActorPath(root, "Path", 2);

            childActorPath1.Equals(childActorPath2).Should().BeTrue();
        }
Esempio n. 25
0
        public void Can_resolve_absolute_path()
        {
            var actorPath = new RootActorPath(TestActor.Path.Address) / "user" / "test";
            var selection = Sys.ActorSelection(actorPath);

            selection.Tell("hello");
            ExpectMsg("hello");
        }
Esempio n. 26
0
        public void Fix2151_not_throw_NRE_on_RootActorPath_ElementsWithUid()
        {
            var a     = new Address("akka.tcp", "mysys");
            var rootA = new RootActorPath(a);
            var uid   = rootA.ElementsWithUid;

            Assert.True(uid.Count > 0); // always at least 1 element when UID is appended
        }
Esempio n. 27
0
        public void Two_child_paths_with_different_name_Have_different_hashcodes()
        {
            var root            = new RootActorPath("/");
            var childActorPath1 = new ChildActorPath(root, "Path 1", 1);
            var childActorPath2 = new ChildActorPath(root, "Path 2", 1);

            childActorPath1.GetHashCode().Should().NotBe(childActorPath2.GetHashCode());
        }
Esempio n. 28
0
        public void Two_child_paths_with_different_name_Are_compared_correctly()
        {
            var root            = new RootActorPath("/");
            var childActorPath1 = new ChildActorPath(root, "Path 1", 1);
            var childActorPath2 = new ChildActorPath(root, "Path 2", 1);

            childActorPath1.CompareTo(childActorPath2).Should().BeLessOrEqualTo(-1);
            childActorPath2.CompareTo(childActorPath1).Should().BeLessOrEqualTo(1);
        }
Esempio n. 29
0
        public void Two_child_paths_with_equal_parents_Have_same_hashcodes()
        {
            var root1           = new RootActorPath("/1");
            var root2           = new RootActorPath("/1");
            var childActorPath1 = new ChildActorPath(root1, "Path", 1);
            var childActorPath2 = new ChildActorPath(root2, "Path", 1);

            childActorPath1.GetHashCode().Should().Be(childActorPath2.GetHashCode());
        }
        public void RemoteActorRefProvider_should_correctly_resolve_valid_LocalActorRef_from_remote_address()
        {
            var actorRef = Sys.ActorOf(BlackHoleActor.Props, "myActor");
            var localAddress = RARP.For(Sys).Provider.DefaultAddress;
            var actorPath = new RootActorPath(localAddress) / "user"  / "myActor";

            var resolvedActorRef = RARP.For(Sys).Provider.ResolveActorRefWithLocalAddress(actorPath.ToStringWithAddress(), localAddress);
            Assert.Equal(actorRef, resolvedActorRef);
        }
Esempio n. 31
0
        public void Two_child_paths_with_different_parents_Are_not_equal()
        {
            var root1           = new RootActorPath("/1");
            var root2           = new RootActorPath("/2");
            var childActorPath1 = new ChildActorPath(root1, "Path", 1);
            var childActorPath2 = new ChildActorPath(root2, "Path", 1);

            childActorPath1.Equals(childActorPath2).Should().BeFalse();
        }
        public Property HeliosTransport_should_map_valid_IPEndpoints_to_ActorPath(IPEndPoint endpoint)
        {
            var addr                = HeliosTransport.MapSocketToAddress(endpoint, "akka.tcp", "foo");
            var actorPath           = new RootActorPath(addr) / "user" / "foo";
            var serializationFormat = actorPath.ToSerializationFormat();
            var reparsedActorPath   = ActorPath.Parse(serializationFormat);

            return(actorPath.Equals(reparsedActorPath).Label($"Should be able to parse endpoint to ActorPath and back; expected {actorPath.ToSerializationFormat()} but was {reparsedActorPath.ToSerializationFormat()}"));
        }
        public Property ActorPath_Should_parse_from_any_valid_EndPoint(EndPoint ep)
        {
            var addr                = EndpointGenerators.ParseAddress(ep);
            var actorPath           = new RootActorPath(addr) / "user" / "foo";
            var serializationFormat = actorPath.ToSerializationFormat();
            var reparsedActorPath   = ActorPath.Parse(serializationFormat);

            return(actorPath.Equals(reparsedActorPath).Label($"Should be able to parse endpoint to ActorPath and back; expected {actorPath.ToSerializationFormat()} but was {reparsedActorPath.ToSerializationFormat()}"));
        }
Esempio n. 34
0
        public void Must_receive_ActorIdentity_null_when_identified_node_is_unknown_host()
        {
            var path = new RootActorPath(new Address("akka.tcp", Sys.Name, "unknownhost2", 2552)) / "user" / "subject";

            Sys.ActorSelection(path).Tell(new Identify(path));
            var identify = ExpectMsg <ActorIdentity>(TimeSpan.FromSeconds(60));

            identify.Subject.ShouldBe(null);
            identify.MessageId.ShouldBe(path);
        }
Esempio n. 35
0
        public void Two_child_paths_with_different_parents_Are_Compared_correctly()
        {
            var root1           = new RootActorPath("/1");
            var root2           = new RootActorPath("/2");
            var childActorPath1 = new ChildActorPath(root1, "Path", 1);
            var childActorPath2 = new ChildActorPath(root2, "Path", 1);

            childActorPath1.CompareTo(childActorPath2).Should().BeLessOrEqualTo(-1);
            childActorPath2.CompareTo(childActorPath1).Should().BeLessOrEqualTo(1);
        }
Esempio n. 36
0
        /// <summary>
        ///     Initializes this instance.
        /// </summary>
        public virtual void Init()
        {
            RootPath = new RootActorPath(Address);
            TempNode = RootPath / "temp";

            RootCell = new ActorCell(System, "", new ConcurrentQueueMailbox());
            DeadLetters = new DeadLetterActorRef(this, RootPath / "deadLetters", System.EventStream);
            Guardian = (LocalActorRef)RootCell.ActorOf<GuardianActor>("user");
            SystemGuardian = (LocalActorRef)RootCell.ActorOf<GuardianActor>("system");
            TempContainer = new VirtualPathContainer(this, TempNode, null);
        }
        public LocalActorRefProvider(string systemName, Settings settings, EventStream eventStream, Deployer deployer, Func<ActorPath, InternalActorRef> deadLettersFactory)
        {
            _settings = settings;
            _eventStream = eventStream;
            _deployer = deployer ?? new Deployer(settings);
            _rootPath = new RootActorPath(new Address("akka", systemName));
            _log = Logging.GetLogger(eventStream, "LocalActorRefProvider(" + _rootPath.Address + ")");
            if (deadLettersFactory == null)
                deadLettersFactory = p => new DeadLetterActorRef(this, p, _eventStream);
            _deadLetters = deadLettersFactory(_rootPath / "deadLetters");
            _tempNumber = new AtomicCounterLong(1);
            _tempNode = _rootPath / "temp";

            //TODO: _guardianSupervisorStrategyConfigurator = dynamicAccess.createInstanceFor[SupervisorStrategyConfigurator](settings.SupervisorStrategyClass, EmptyImmutableSeq).get
            _systemGuardianStrategy = SupervisorStrategy.DefaultStrategy;

        }
        public void RemoteActorRefProvider_should_correctly_resolve_valid_LocalActorRef_from_second_remote_system()
        {
           var sys2 = ActorSystem.Create("Sys2", RemoteConfiguration);
            try
            {
                Within(TimeSpan.FromSeconds(15), () =>
                {
                    var actorRef = sys2.ActorOf(BlackHoleActor.Props, "myActor");
                    var sys2Address = RARP.For(sys2).Provider.DefaultAddress;
                    var actorPath = new RootActorPath(sys2Address) / "user" / "myActor";

                    // get a remoteactorref for the second system
                    var remoteActorRef = Sys.ActorSelection(actorPath).ResolveOne(TimeSpan.FromSeconds(3)).Result;

                    // disconnect us from the second actorsystem
                    var mc =
                        RARP.For(Sys)
                            .Provider.Transport.ManagementCommand(new SetThrottle(sys2Address,
                                ThrottleTransportAdapter.Direction.Both, Blackhole.Instance));
                    Assert.True(mc.Wait(TimeSpan.FromSeconds(3)));

                    // start deathwatch (won't be delivered initially)
                    Watch(remoteActorRef);
                    Task.Delay(TimeSpan.FromSeconds(3)).Wait(); // if we delay the initial send, this spec will fail

                    var mc2 =
                       RARP.For(Sys)
                           .Provider.Transport.ManagementCommand(new SetThrottle(sys2Address,
                               ThrottleTransportAdapter.Direction.Both, Unthrottled.Instance));
                    Assert.True(mc2.Wait(TimeSpan.FromSeconds(3)));

                    // fire off another non-system message
                    var ai =
                        Sys.ActorSelection(actorPath).Ask<ActorIdentity>(new Identify(null), TimeSpan.FromSeconds(3)).Result;

                   
                    remoteActorRef.Tell(PoisonPill.Instance); // WATCH should be applied first
                    ExpectTerminated(remoteActorRef);
                });
            }
            finally
            {
                Assert.True(sys2.Terminate().Wait(TimeSpan.FromSeconds(5)));
            }
        }
        public void AssociationStress(BenchmarkContext context)
        {
            var registryKey = CreateRegistryKey();
            using (
                var system1 = ActorSystem.Create("SystemA" + ActorSystemNameCounter.Next(),
                    CreateActorSystemConfig("SystemA" + ActorSystemNameCounter.Current, "127.0.0.1", 0, registryKey)))
            using (
                var system2 = ActorSystem.Create("SystemB" + ActorSystemNameCounter.Next(),
                    CreateActorSystemConfig("SystemB" + ActorSystemNameCounter.Current, "127.0.0.1", 0, registryKey)))
            {
                var echo = system1.ActorOf(ActorProps, "echo");
                var system1Address = RARP.For(system1).Provider.Transport.DefaultAddress;
                var system1EchoActorPath = new RootActorPath(system1Address) / "user" / "echo";

               var remoteActor = system2.ActorSelection(system1EchoActorPath)
                   .Ask<ActorIdentity>(new Identify(null), TimeSpan.FromSeconds(2)).Result.Subject;
                AssociationCounter.Increment();
            }
        }
Esempio n. 40
0
 public void Must_receive_ActorIdentity_null_when_identified_node_is_unknown_host()
 {
     var path = new RootActorPath(new Address("akka.tcp", Sys.Name, "unknownhost2", 2552)) / "user" / "subject";
     Sys.ActorSelection(path).Tell(new Identify(path));
     var identify = ExpectMsg<ActorIdentity>(TimeSpan.FromSeconds(60));
     identify.Subject.ShouldBe(null);
     identify.MessageId.ShouldBe(path);
 }
Esempio n. 41
0
        public void An_actor_watching_a_remote_actor_in_the_cluster_must_receive_terminated_when_watched_node_becomes_down_removed()
        {
            Within(TimeSpan.FromSeconds(30), () =>
            {
                AwaitClusterUp(_config.First, _config.Second, _config.Third, _config.Fourth);
                EnterBarrier("cluster-up");

                RunOn(() =>
                {
                    EnterBarrier("subjected-started");

                    var path2 = new RootActorPath(GetAddress(_config.Second)) / "user" / "subject";
                    var path3 = new RootActorPath(GetAddress(_config.Third)) / "user" / "subject";
                    var watchEstablished = new TestLatch(2);
                    Sys.ActorOf(Props.Create(() => new Observer(path2, path3, watchEstablished, TestActor))
                        .WithDeploy(Deploy.Local), "observer1");

                    watchEstablished.Ready();
                    EnterBarrier("watch-established");
                    ExpectMsg(path2);
                    ExpectNoMsg(TimeSpan.FromSeconds(2));
                    EnterBarrier("second-terminated");
                    MarkNodeAsUnavailable(GetAddress(_config.Third));
                    AwaitAssert(() => Assert.True(ClusterView.UnreachableMembers.Select(x => x.Address).Contains(GetAddress(_config.Third))));
                    Cluster.Down(GetAddress(_config.Third));
                    //removed
                    AwaitAssert(() => Assert.False(ClusterView.Members.Select(x => x.Address).Contains(GetAddress(_config.Third))));
                    AwaitAssert(() => Assert.False(ClusterView.UnreachableMembers.Select(x => x.Address).Contains(GetAddress(_config.Third))));
                    ExpectMsg(path3);
                    EnterBarrier("third-terminated");
                }, _config.First);

                RunOn(() =>
                {
                    Sys.ActorOf(BlackHoleActor.Props, "subject");
                    EnterBarrier("subjected-started");
                    EnterBarrier("watch-established");
                    RunOn(() =>
                    {
                        MarkNodeAsUnavailable(GetAddress(_config.Second));
                        AwaitAssert(() => Assert.True(ClusterView.UnreachableMembers.Select(x => x.Address).Contains(GetAddress(_config.Second))));
                        Cluster.Down(GetAddress(_config.Second));
                        //removed
                        AwaitAssert(() => Assert.False(ClusterView.Members.Select(x => x.Address).Contains(GetAddress(_config.Second))));
                        AwaitAssert(() => Assert.False(ClusterView.UnreachableMembers.Select(x => x.Address).Contains(GetAddress(_config.Second))));
                    }, _config.Third);
                    EnterBarrier("second-terminated");
                    EnterBarrier("third-terminated");
                }, _config.Second, _config.Third, _config.Fourth);

                RunOn(() =>
                {
                    EnterBarrier("subjected-started");
                    EnterBarrier("watch-established");
                    EnterBarrier("second-terminated");
                    EnterBarrier("third-terminated");
                }, _config.Fifth);

                EnterBarrier("after-1");
            });
        }
Esempio n. 42
0
 public void Memory_footprint(BenchmarkContext context)
 {
     var actorPaths = new ActorPath[100000];
     for (var i = 0; i < 100000;)
     {
         actorPaths[i] = new RootActorPath(Address.AllSystems);
         ++i;
         _parseThroughput.Increment();
     }
 }
Esempio n. 43
0
 public BenchmarkActorRef(Counter counter, RemoteActorRefProvider provider)
 {
     _counter = counter;
     Provider = provider;
     Path = new RootActorPath(Provider.DefaultAddress) / "user" / "tempRef";
 }
 public Property HeliosTransport_should_map_valid_IPEndpoints_to_ActorPath(IPEndPoint endpoint)
 {
     // TODO: remove this once Mono Uris support IPV6 https://bugzilla.xamarin.com/show_bug.cgi?id=43649 (8/22/2016 Aaronontheweb)
     if (IsMono && endpoint.AddressFamily == AddressFamily.InterNetworkV6)
         return true.Label("Mono does not currently support Uri.TryParse for IPV6");
     var addr = HeliosTransport.MapSocketToAddress(endpoint, "akka.tcp", "foo");
     var actorPath = new RootActorPath(addr) / "user" / "foo";
     var serializationFormat = actorPath.ToSerializationFormat();
     var reparsedActorPath = ActorPath.Parse(serializationFormat);
     return actorPath.Equals(reparsedActorPath).Label($"Should be able to parse endpoint to ActorPath and back; expected {actorPath.ToSerializationFormat()} but was {reparsedActorPath.ToSerializationFormat()}");
 }
Esempio n. 45
0
        public ClusterSingletonProxy(string singletonManagerPath, ClusterSingletonProxySettings settings)
        {
            _settings = settings;
            _singletonPath = (singletonManagerPath + "/" + settings.SingletonName).Split('/');
            _identityId = CreateIdentifyId(_identityCounter);

            Receive<ClusterEvent.CurrentClusterState>(s => HandleInitial(s));
            Receive<ClusterEvent.MemberUp>(m => Add(m.Member));
            Receive<ClusterEvent.MemberExited>(m => Remove(m.Member));
            Receive<ClusterEvent.MemberRemoved>(m => Remove(m.Member));
            Receive<ClusterEvent.IMemberEvent>(m =>
            {
                /* do nothing */
            });
            Receive<ActorIdentity>(identity =>
                {
                    if (identity.Subject != null)
                    {
                        // if the new singleton is defined, deliver all buffered messages
                        var subject = identity.Subject;
                        Log.Info("Singleton identified at [{0}]", subject.Path);
                        _singleton = subject;
                        Context.Watch(subject);
                        CancelTimer();
                        SendBuffered();
                    }
                });
            Receive<TryToIdentifySingleton>(_ =>
                 {
                     var oldest = _membersByAge.FirstOrDefault();
                     if (oldest != null && _identityTimer != null)
                     {
                         var singletonAddress = new RootActorPath(oldest.Address) / _singletonPath;
                         Log.Debug("Trying to identify singleton at [{0}]", singletonAddress);
                         Context.ActorSelection(singletonAddress).Tell(new Identify(_identityId));
                     }
                 });
            Receive<Terminated>(terminated =>
                {
                    if (Equals(_singleton, terminated.ActorRef))
                    {
                        // buffering mode, identification of new will start when old node is removed
                        _singleton = null;
                    }
                });
            ReceiveAny(msg =>
                {
                    if (_singleton != null)
                    {
                        if (Log.IsDebugEnabled)
                            Log.Debug("Forwarding message of type [{0}] to current singleton instance at [{1}]", msg.GetType(), _singleton.Path);
                        _singleton.Forward(msg);
                    }
                    else
                        Buffer(msg);
                });
        }
Esempio n. 46
0
        public void Must_receive_terminated_when_watched_node_is_unknown_host()
        {
            var path = new RootActorPath(new Address("akka.tcp", Sys.Name, "unknownhost", 2552)) / "user" / "subject";
            var rarp = RARP.For(Sys).Provider;
            Action<IActorDsl> act = dsl =>
            {
                dsl.OnPreStart = context =>
                {
                    context.Watch(rarp.ResolveActorRef(path));
                };
                dsl.Receive<Terminated>((t, ctx) =>
                {
                    TestActor.Tell(t.ActorRef.Path);
                });
            };

            Sys.ActorOf(Props.Create(() => new Act(act)).WithDeploy(Deploy.Local), "observer2");

            ExpectMsg(path, TimeSpan.FromSeconds(60));
        }
Esempio n. 47
0
 public Property ActorPath_Should_parse_from_any_valid_EndPoint(EndPoint ep)
 {
     var addr = EndpointGenerators.ParseAddress(ep);
     var actorPath = new RootActorPath(addr) / "user" / "foo";
     var serializationFormat = actorPath.ToSerializationFormat();
     var reparsedActorPath = ActorPath.Parse(serializationFormat);
     return actorPath.Equals(reparsedActorPath).Label($"Should be able to parse endpoint to ActorPath and back; expected {actorPath.ToSerializationFormat()} but was {reparsedActorPath.ToSerializationFormat()}");
 }
        private void Setup(string inboundHostname, string outboundHostname, string inboundPublicHostname = null, string outboundPublicHostname = null, bool useIpv6Dns = false, bool enforceIpFamily = false)
        {
            _inbound = ActorSystem.Create("Sys1", BuildConfig(inboundHostname, 0, inboundPublicHostname, useIpv6Dns, enforceIpFamily));
            _outbound = ActorSystem.Create("Sys2", BuildConfig(outboundHostname, 0, outboundPublicHostname, useIpv6Dns, enforceIpFamily));

            _inbound.ActorOf(Props.Create(() => new AssociationAcker()), "ack");
            _outbound.ActorOf(Props.Create(() => new AssociationAcker()), "ack");

            var addrInbound = RARP.For(_inbound).Provider.DefaultAddress;
            var addrOutbound = RARP.For(_outbound).Provider.DefaultAddress;

            _inboundAck = new RootActorPath(addrInbound) / "user" / "ack";
            _outboundAck = new RootActorPath(addrOutbound) / "user" / "ack";

            _inboundProbe = CreateTestProbe(_inbound);
            _outboundProbe = CreateTestProbe(_outbound);
        }
 protected override void OnReceive(object message)
 {
     message.Match()
         .With<ClusterEvent.CurrentClusterState>(HandleInitial)
         .With<ClusterEvent.MemberUp>(m => Add(m.Member))
         .With<ClusterEvent.MemberExited>(m => Remove(m.Member))
         .With<ClusterEvent.MemberRemoved>(m => Remove(m.Member))
         .With<ActorIdentity>(identity =>
         {
             if (identity.Subject != null)
             {
                 // if the new singleton is defined, deliver all buffered messages
                 var subject = identity.Subject;
                 Log.Info("Singleton identified at [{0}]", subject.Path);
                 _singleton = subject;
                 Context.Watch(subject);
                 CancelTimer();
                 SendBuffered();
             }
         })
         .With<TryToIdentifySingleton>(() =>
         {
             var oldest = _membersByAge.FirstOrDefault();
             if (oldest != null && _identityTimer != null)
             {
                 var singletonAddress = new RootActorPath(oldest.Address) / _singletonPath;
                 Log.Debug("Trying to identify singleton at [{0}]", singletonAddress);
                 Context.ActorSelection(singletonAddress).Tell(new Identify(_identityId));
             }
         })
         .With<Terminated>(terminated =>
         {
             if (Equals(_singleton, terminated.ActorRef))
             {
                 // buffering mode, identification of new will start when old node is removed
                 _singleton = null;
             }
         })
         .Default(msg =>
         {
             if (_singleton != null)
             {
                 if (Log.IsDebugEnabled)
                     Log.Debug("Forwarding message of type [{0}] to current singleton instance at [{1}]", msg.GetType(), _singleton.Path);
                 _singleton.Forward(msg);
             }
             else
                 Buffer(msg);
         });
 }
Esempio n. 50
0
 public void SupportsParsingItsStringRep()
 {
     var path = new RootActorPath(new Address("akka.tcp", "mysys")) / "user";
     ActorPathParse(path.ToString()).ShouldBe(path);
 }
Esempio n. 51
0
        public LocalActorRefProvider(string systemName, Settings settings, EventStream eventStream, Deployer deployer, Func<ActorPath, IInternalActorRef> deadLettersFactory)
        {
            _settings = settings;
            _eventStream = eventStream;
            _deployer = deployer ?? new Deployer(settings);
            _rootPath = new RootActorPath(new Address("akka", systemName));
            _log = Logging.GetLogger(eventStream, "LocalActorRefProvider(" + _rootPath.Address + ")");
            if(deadLettersFactory == null)
                deadLettersFactory = p => new DeadLetterActorRef(this, p, _eventStream);
            _deadLetters = deadLettersFactory(_rootPath / "deadLetters");
            _tempNumber = new AtomicCounterLong(1);
            _tempNode = _rootPath / "temp";

            _systemGuardianStrategy = SupervisorStrategy.DefaultStrategy;
            _userGuardianStrategyConfigurator = SupervisorStrategyConfigurator.CreateConfigurator(Settings.SupervisorStrategyClass);
        }
Esempio n. 52
0
        public void Remoting_must_not_leak_actors()
        {
            var actorRef = Sys.ActorOf(EchoActor.Props(this, true), "echo");
            var echoPath = new RootActorPath(RARP.For(Sys).Provider.DefaultAddress)/"user"/"echo";

            var targets = new[] {"/system/endpointManager", "/system/transports"}.Select(x =>
            {
                Sys.ActorSelection(x).Tell(new Identify(0));
                return ExpectMsg<ActorIdentity>().Subject;
            }).ToList();

            var initialActors = targets.SelectMany(CollectLiveActors).ToImmutableHashSet();

            // Clean shutdown case
            for (var i = 1; i <= 3; i++)
            {
                var remoteSystem = ActorSystem.Create("remote",
                    ConfigurationFactory.ParseString("akka.remote.helios.tcp.port = 0")
                        .WithFallback(Sys.Settings.Config));

                try
                {
                    var probe = CreateTestProbe(remoteSystem);
                    remoteSystem.ActorSelection(echoPath).Tell(new Identify(1), probe.Ref);
                    probe.ExpectMsg<ActorIdentity>().Subject.ShouldNotBe(null);
                }
                finally
                {
                    remoteSystem.Terminate();
                }

                remoteSystem.WhenTerminated.Wait(TimeSpan.FromSeconds(10)).ShouldBeTrue();
            }

            // Quarantine an old incarnation case
            for (var i = 1; i <= 3; i++)
            {
                // always use the same address
                var remoteSystem = ActorSystem.Create("remote",
                    ConfigurationFactory.ParseString("akka.remote.helios.tcp.port = 2553")
                        .WithFallback(Sys.Settings.Config));

                try
                {
                    var remoteAddress = RARP.For(remoteSystem).Provider.DefaultAddress;
                    remoteSystem.ActorOf(Props.Create(() => new StoppableActor()), "stoppable");

                    // the message from remote to local will cause inbound connection established
                    var probe = CreateTestProbe(remoteSystem);
                    remoteSystem.ActorSelection(echoPath).Tell(new Identify(1), probe.Ref);
                    probe.ExpectMsg<ActorIdentity>().Subject.ShouldNotBe(null);

                    var beforeQuarantineActors = targets.SelectMany(CollectLiveActors).ToImmutableHashSet();

                    // it must not quarantine the current connection
                    RARP.For(Sys)
                        .Provider.Transport.Quarantine(remoteAddress, AddressUidExtension.Uid(remoteSystem) + 1);

                    // the message from local to remote should reuse passive inbound connection
                    Sys.ActorSelection(new RootActorPath(remoteAddress) / "user" / "stoppable").Tell(new Identify(1));
                    ExpectMsg<ActorIdentity>().Subject.ShouldNotBe(null);

                    var afterQuarantineActors = targets.SelectMany(CollectLiveActors).ToImmutableHashSet();

                    AssertActors(beforeQuarantineActors, afterQuarantineActors);
                }
                finally
                {
                    remoteSystem.Terminate();
                }
                remoteSystem.WhenTerminated.Wait(TimeSpan.FromSeconds(10)).ShouldBeTrue();
            }

            // Missing SHUTDOWN case
            for (var i = 1; i <= 3; i++)
            {
                var remoteSystem = ActorSystem.Create("remote",
                    ConfigurationFactory.ParseString("akka.remote.helios.tcp.port = 0")
                        .WithFallback(Sys.Settings.Config));
                var remoteAddress = RARP.For(remoteSystem).Provider.DefaultAddress;

                try
                {
                    var probe = CreateTestProbe(remoteSystem);
                    remoteSystem.ActorSelection(echoPath).Tell(new Identify(1), probe.Ref);
                    probe.ExpectMsg<ActorIdentity>().Subject.ShouldNotBe(null);

                    // This will make sure that no SHUTDOWN message gets through
                    RARP.For(Sys).Provider.Transport.ManagementCommand(new ForceDisassociate(remoteAddress))
                        .Wait(TimeSpan.FromSeconds(3)).ShouldBeTrue();
                }
                finally
                {
                    remoteSystem.Terminate();
                }

                EventFilter.Warning(contains: "Association with remote system").ExpectOne(() =>
                {
                    remoteSystem.WhenTerminated.Wait(TimeSpan.FromSeconds(10)).ShouldBeTrue();
                });
            }

            // Remote idle for too long case
            var idleRemoteSystem = ActorSystem.Create("remote",
                    ConfigurationFactory.ParseString("akka.remote.helios.tcp.port = 0")
                        .WithFallback(Sys.Settings.Config));
            var idleRemoteAddress = RARP.For(idleRemoteSystem).Provider.DefaultAddress;

            idleRemoteSystem.ActorOf(Props.Create<StoppableActor>(), "stoppable");

            try
            {
                var probe = CreateTestProbe(idleRemoteSystem);

                idleRemoteSystem.ActorSelection(echoPath).Tell(new Identify(1), probe.Ref);
                probe.ExpectMsg<ActorIdentity>().Subject.ShouldNotBe(null);

                // Watch a remote actor - this results in system message traffic
                Sys.ActorSelection(new RootActorPath(idleRemoteAddress) / "user" / "stoppable").Tell(new Identify(1));
                var remoteActor = ExpectMsg<ActorIdentity>().Subject;
                Watch(remoteActor);
                remoteActor.Tell("stop");
                ExpectTerminated(remoteActor);
                // All system messages have been acked now on this side

                // This will make sure that no SHUTDOWN message gets through
                RARP.For(Sys).Provider.Transport.ManagementCommand(new ForceDisassociate(idleRemoteAddress))
                        .Wait(TimeSpan.FromSeconds(3)).ShouldBeTrue();
            }
            finally
            {
                idleRemoteSystem.Terminate();
            }

            EventFilter.Warning(contains: "Association with remote system").ExpectOne(() =>
            {
                idleRemoteSystem.WhenTerminated.Wait(TimeSpan.FromSeconds(10)).ShouldBeTrue();
            });

            /*
             * Wait for the ReliableDeliverySupervisor to receive its "TooLongIdle" message,
             * which will throw a HopelessAssociation wrapped around a TimeoutException.
             */
            EventFilter.Exception<TimeoutException>().ExpectOne(() => { });

            var finalActors = targets.SelectMany(CollectLiveActors).ToImmutableHashSet();

            AssertActors(initialActors, finalActors);
        }
Esempio n. 53
0
 public void Fix2151_not_throw_NRE_on_RootActorPath_ElementsWithUid()
 {
     var a = new Address("akka.tcp", "mysys");
     var rootA = new RootActorPath(a);
     var uid = rootA.ElementsWithUid;
     Assert.True(uid.Count > 0); // always at least 1 element when UID is appended
 }
Esempio n. 54
0
        public void Must_quarantine_systems_after_unsuccessful_system_message_delivery_if_have_not_communicated_before()
        {
            // Synthesize an ActorRef to a remote system this one has never talked to before.
            // This forces ReliableDeliverySupervisor to start with unknown remote system UID.
            var rarp = RARP.For(Sys).Provider;
            int port = rarp.DefaultAddress.Port.Value;
            while (port == rarp.DefaultAddress.Port.Value || port == 2666)
                port = ThreadLocalRandom.Current.Next(1, 65535);

            var extinctPath = new RootActorPath(new Address("akka.tcp", "extinct-system", "localhost", port)) / "user" / "noone";
            var transport = rarp.Transport;
            var extinctRef = new RemoteActorRef(transport, transport.LocalAddressForRemote(extinctPath.Address), 
                extinctPath, ActorRefs.Nobody, Props.None, Deploy.None);

            var probe = CreateTestProbe();
            probe.Watch(extinctRef);
            probe.Unwatch(extinctRef);

            probe.ExpectNoMsg(TimeSpan.FromSeconds(5));
            Sys.EventStream.Subscribe(probe.Ref, typeof(Warning));
            probe.ExpectNoMsg(TimeSpan.FromSeconds(rarp.RemoteSettings.RetryGateClosedFor.TotalSeconds * 2));
        }