コード例 #1
0
        public void Remoting_should_contain_correct_configuration_values_in_ReferenceConf()
        {
            var remoteSettings = RARP.For(Sys).Provider.RemoteSettings;

            Assert.False(remoteSettings.LogReceive);
            Assert.False(remoteSettings.LogSend);
            Assert.False(remoteSettings.UntrustedMode);
            Assert.Empty(remoteSettings.TrustedSelectionPaths);
            Assert.Equal(TimeSpan.FromSeconds(10), remoteSettings.ShutdownTimeout);
            Assert.Equal(TimeSpan.FromSeconds(2), remoteSettings.FlushWait);
            Assert.Equal(TimeSpan.FromSeconds(10), remoteSettings.StartupTimeout);
            Assert.Equal(TimeSpan.FromSeconds(5), remoteSettings.RetryGateClosedFor);
            Assert.Equal("akka.remote.default-remote-dispatcher", remoteSettings.Dispatcher);
            Assert.True(remoteSettings.UsePassiveConnections);
            Assert.Equal(TimeSpan.FromMilliseconds(50), remoteSettings.BackoffPeriod);
            Assert.Equal(TimeSpan.FromSeconds(0.3d), remoteSettings.SysMsgAckTimeout);
            Assert.Equal(TimeSpan.FromSeconds(2), remoteSettings.SysResendTimeout);
            Assert.Equal(20000, remoteSettings.SysMsgBufferSize);
            Assert.Equal(TimeSpan.FromMinutes(3), remoteSettings.InitialSysMsgDeliveryTimeout);
            Assert.Equal(TimeSpan.FromDays(5), remoteSettings.QuarantineDuration);
            Assert.Equal(TimeSpan.FromDays(2), remoteSettings.QuarantineSilentSystemTimeout);
            Assert.Equal(TimeSpan.FromSeconds(30), remoteSettings.CommandAckTimeout);
            Assert.Single(remoteSettings.Transports);
            Assert.Equal(typeof(TcpTransport), Type.GetType(remoteSettings.Transports.Head().TransportClass));
            Assert.Equal(typeof(PhiAccrualFailureDetector), Type.GetType(remoteSettings.WatchFailureDetectorImplementationClass));
            Assert.Equal(TimeSpan.FromSeconds(1), remoteSettings.WatchHeartBeatInterval);
            Assert.Equal(TimeSpan.FromSeconds(1), remoteSettings.WatchHeartbeatExpectedResponseAfter);
            Assert.Equal(TimeSpan.FromSeconds(1), remoteSettings.WatchUnreachableReaperInterval);
            Assert.Equal(10, remoteSettings.WatchFailureDetectorConfig.GetDouble("threshold"));
            Assert.Equal(200, remoteSettings.WatchFailureDetectorConfig.GetDouble("max-sample-size"));
            Assert.Equal(TimeSpan.FromSeconds(10), remoteSettings.WatchFailureDetectorConfig.GetTimeSpan("acceptable-heartbeat-pause"));
            Assert.Equal(TimeSpan.FromMilliseconds(100), remoteSettings.WatchFailureDetectorConfig.GetTimeSpan("min-std-deviation"));

            var remoteSettingsAdaptersStandart = new List <KeyValuePair <string, Type> >()
            {
                new KeyValuePair <string, Type>("gremlin", typeof(FailureInjectorProvider)),
                new KeyValuePair <string, Type>("trttl", typeof(ThrottlerProvider))
            };

            var remoteSettingsAdapters =
                remoteSettings.Adapters.Select(kv => new KeyValuePair <string, Type>(kv.Key, Type.GetType(kv.Value)));

            Assert.Empty(remoteSettingsAdapters.Except(remoteSettingsAdaptersStandart));

            remoteSettings.Config.GetString("akka.remote.log-frame-size-exceeding").ShouldBe("off");
        }
コード例 #2
0
        private void CreateOutboundStateActor(Address remoteAddress,
                                              TaskCompletionSource <AssociationHandle> statusPromise, int?refuseUid)
        {
            var stateActorLocalAddress     = localAddress;
            var stateActorSettings         = _settings;
            var stateActorWrappedTransport = _wrappedTransport;
            var failureDetector            = CreateTransportFailureDetector();

            Context.ActorOf(RARP.For(Context.System).ConfigureDispatcher(ProtocolStateActor.OutboundProps(
                                                                             new HandshakeInfo(stateActorLocalAddress, AddressUidExtension.Uid(Context.System)),
                                                                             remoteAddress,
                                                                             statusPromise,
                                                                             stateActorWrappedTransport,
                                                                             stateActorSettings,
                                                                             new AkkaPduProtobuffCodec(), failureDetector, refuseUid)),
                            ActorNameFor(remoteAddress));
        }
コード例 #3
0
        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)));
            }
        }
コード例 #4
0
        public void AkkaProtocolTransport_must_guarantee_at_most_once_delivery_and_message_ordering_despite_packet_loss()
        {
            //todo mute both systems for deadletters for any type of message
            var mc =
                RARP.For(Sys)
                .Provider.Transport.ManagementCommand(new FailureInjectorTransportAdapter.One(AddressB,
                                                                                              new FailureInjectorTransportAdapter.Drop(0.1, 0.1)));

            AwaitCondition(() => mc.IsCompleted && mc.Result, TimeSpan.FromSeconds(3));

            var here = Here;

            var tester = Sys.ActorOf(Props.Create(() => new SequenceVerifier(here, TestActor)));

            tester.Tell("start");

            ExpectMsg <Tuple <int, int> >(TimeSpan.FromSeconds(60));
        }
コード例 #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));

            System2 = ActorSystem.Create("SystemB" + ActorSystemNameCounter.Next(), CreateActorSystemConfig("SystemB" + ActorSystemNameCounter.Current, "127.0.0.1", 0));

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

            var canStart  = System2.ActorOf(Props.Create(() => new AllStartedActor()), "canStart");
            var echoProps = Props.Create(() => new EchoActor()).WithDeploy(new Deploy(new RemoteScope(system1Address)));

            for (var i = 0; i < NumClients; i++)
            {
                var echo = System2.ActorOf(echoProps, "echo" + i);
                var ts   = new TaskCompletionSource <long>();
                _tasks.Add(ts.Task);
                var receiver =
                    System2.ActorOf(
                        Props.Create(() => new BenchmarkActor(_remoteMessageThroughput, RemoteMessageCount, ts, echo)),
                        "benchmark" + i);

                _receivers.Add(receiver);

                canStart.Tell(echo);
                canStart.Tell(receiver);
            }

            try
            {
                var testReady = canStart.Ask <bool>(new AllStartedActor.AllStarted(), TimeSpan.FromSeconds(10)).Result;
                if (!testReady)
                {
                    throw new NBenchException("Received report that 1 or more remote actor is unable to begin the test. Aborting run.");
                }
            }
            catch (Exception ex)
            {
                context.Trace.Error(ex, "error occurred during setup.");
                throw; // re-throw the error to blow up the benchmark
            }
        }
コード例 #6
0
        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();
                }
        }
コード例 #7
0
        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));

            //InitializeLogger(_inbound);
            //InitializeLogger(_outbound);

            _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);
        }
コード例 #8
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));
        }
コード例 #9
0
        public void Remoting_should_contain_correct_socket_worker_pool_configuration_values_in_ReferenceConf()
        {
            var c = RARP.For(Sys).Provider.RemoteSettings.Config.GetConfig("akka.remote.dot-netty.tcp");

            // server-socket-worker-pool
            {
                var pool = c.GetConfig("server-socket-worker-pool");
                Assert.Equal(2, pool.GetInt("pool-size-min", 0));
                Assert.Equal(1.0d, pool.GetDouble("pool-size-factor", 0));
                Assert.Equal(2, pool.GetInt("pool-size-max", 0));
            }

            //client-socket-worker-pool
            {
                var pool = c.GetConfig("client-socket-worker-pool");
                Assert.Equal(2, pool.GetInt("pool-size-min", 0));
                Assert.Equal(1.0d, pool.GetDouble("pool-size-factor", 0));
                Assert.Equal(2, pool.GetInt("pool-size-max", 0));
            }
        }
コード例 #10
0
 protected override void Ready(object message)
 {
     message.Match()
     .With <InboundAssociation>(ia =>    //need to create an Inbound ProtocolStateActor
     {
         var handle = ia.Association;
         var stateActorLocalAddress        = localAddress;
         var stateActorAssociationListener = associationListener;
         var stateActorSettings            = _settings;
         var failureDetector = CreateTransportFailureDetector();
         Context.ActorOf(RARP.For(Context.System).ConfigureDispatcher(ProtocolStateActor.InboundProps(
                                                                          new HandshakeInfo(stateActorLocalAddress, AddressUidExtension.Uid(Context.System)),
                                                                          handle,
                                                                          stateActorAssociationListener,
                                                                          stateActorSettings,
                                                                          new AkkaPduProtobuffCodec(),
                                                                          failureDetector)), ActorNameFor(handle.RemoteAddress));
     })
     .With <AssociateUnderlying>(au => CreateOutboundStateActor(au.RemoteAddress, au.StatusPromise, null))    //need to create an Outbound ProtocolStateActor
     .With <AssociateUnderlyingRefuseUid>(au => CreateOutboundStateActor(au.RemoteAddress, au.StatusCompletionSource, au.RefuseUid));
 }
コード例 #11
0
        public void DotNettyTcpTransport_should_communicate_without_pooling()
        {
            var sys2 = ActorSystem.Create(Sys.Name, Sys.Settings.Config);

            InitializeLogger(sys2);
            try
            {
                var echo = sys2.ActorOf(act => { act.ReceiveAny((o, context) => context.Sender.Tell(o)); }, "echo");

                var address1 = RARP.For(Sys).Provider.DefaultAddress;
                var address2 = RARP.For(sys2).Provider.DefaultAddress;
                var echoPath = new RootActorPath(address2) / "user" / "echo";
                var probe    = CreateTestProbe();
                Sys.ActorSelection(echoPath).Tell("hello", probe.Ref);
                probe.ExpectMsg("hello");
            }
            finally
            {
                Shutdown(sys2);
            }
        }
コード例 #12
0
        public Property HeliosTransport_Should_Resolve_DNS(EndPoint inbound, EndPoint outbound, bool dnsIpv6)
        {
            if (IsAnyIp(inbound) || IsAnyIp(outbound))
            {
                return(true.Label("Can't connect directly to an ANY address"));
            }
            try
            {
                Setup(EndpointGenerators.ParseAddress(inbound), EndpointGenerators.ParseAddress(outbound), useIpv6Dns: dnsIpv6);
                var outboundReceivedAck = true;
                var inboundReceivedAck  = true;
                _outbound.ActorSelection(_inboundAck).Tell("ping", _outboundProbe.Ref);
                try
                {
                    _outboundProbe.ExpectMsg("ack");
                }
                catch
                {
                    outboundReceivedAck = false;
                }

                _inbound.ActorSelection(_outboundAck).Tell("ping", _inboundProbe.Ref);
                try
                {
                    _inboundProbe.ExpectMsg("ack");
                }
                catch
                {
                    inboundReceivedAck = false;
                }


                return(outboundReceivedAck.Label($"Expected (outbound: {RARP.For(_outbound).Provider.DefaultAddress}) to be able to successfully message and receive reply from (inbound: {RARP.For(_inbound).Provider.DefaultAddress})")
                       .And(inboundReceivedAck.Label($"Expected (inbound: {RARP.For(_inbound).Provider.DefaultAddress}) to be able to successfully message and receive reply from (outbound: {RARP.For(_outbound).Provider.DefaultAddress})")));
            }
            finally
            {
                Cleanup();
            }
        }
コード例 #13
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";

            _remoteReceiver = System1.ActorSelection(system2RemoteActorPath).ResolveOne(TimeSpan.FromSeconds(2)).Result;
            _remoteEcho     =
                System2.ActorSelection(system1EchoActorPath).ResolveOne(TimeSpan.FromSeconds(2)).Result;
        }
コード例 #14
0
        public void RemoteGatePiercing_must_allow_restarted_node_to_pass_through_gate()
        {
            Sys.ActorOf <RemoteGatePiercingMultiNetSpec.Subject>("subject");
            EnterBarrier("actors-started");

            RunOn(() =>
            {
                _identify(_config.Second, "subject");
                EnterBarrier("actors-communicate");

                EventFilter.Warning(null, null, contains: "address is now gated").ExpectOne(() =>
                {
                    var cmd =
                        RARP.For(Sys)
                        .Provider.Transport.ManagementCommand(
                            new ForceDisassociateExplicitly(Node(_config.Second).Address, DisassociateInfo.Unknown));
                    cmd.Wait(TimeSpan.FromSeconds(3));
                });

                EnterBarrier("gated");
                EnterBarrier("gate-pierced");
            }, _config.First);

            RunOn(() =>
            {
                EnterBarrier("actors-communicate");
                EnterBarrier("gated");

                // Pierce the gate
                Within(TimeSpan.FromSeconds(30), () =>
                {
                    AwaitAssert(() => _identify(_config.First, "subject"));
                });

                EnterBarrier("gate-pierced");
            }, _config.Second);
        }
コード例 #15
0
        public void Must_receive_Terminated_when_system_of_deserialized_ActorRef_is_not_running()
        {
            var probe = CreateTestProbe();

            Sys.EventStream.Subscribe(probe.Ref, typeof(QuarantinedEvent));
            var rarp = RARP.For(Sys).Provider;
            // pick an unused port (not going to use a socket address generator here; just a port not used by either actor system)
            int port = rarp.DefaultAddress.Port.Value;

            while (port == rarp.DefaultAddress.Port.Value || port == 2666)
            {
                port = ThreadLocalRandom.Current.Next(1, 65535);
            }
            // simulate de-serialized ActorRef
            var @ref = rarp.ResolveActorRef($"akka.tcp://OtherSystem@localhost:{port}/user/foo/bar#1752527294");
            Action <IActorDsl> act = dsl =>
            {
                dsl.OnPreStart = context =>
                {
                    context.Watch(@ref);
                };
                dsl.Receive <Terminated>((t, ctx) =>
                {
                    TestActor.Tell(t.ActorRef);
                });
            };

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

            ExpectMsg(@ref, TimeSpan.FromSeconds(20));
            // we don't expect real quarantine when the UID is unknown, i.e. QuarantinedEvent is not published
            probe.ExpectNoMsg(TimeSpan.FromSeconds(3));
            // The following verifies that re-delivery of Watch message is stopped.
            // It was observed as periodic logging of "address is now gated" when the gate was lifted.
            Sys.EventStream.Subscribe(probe.Ref, typeof(Warning));
            probe.ExpectNoMsg(TimeSpan.FromSeconds(rarp.RemoteSettings.RetryGateClosedFor.TotalSeconds * 2));
        }
コード例 #16
0
        public void While_probing_through_the_quarantine_remoting_must_not_lose_existing_quarantine_marker()
        {
            RunOn(() =>
            {
                EnterBarrier("actors-started");

                // Communicate with second system
                Sys.ActorSelection(Node(_config.Second) / "user" / "subject").Tell("getuid");
                var uid = ExpectMsg <int>(TimeSpan.FromSeconds(10));
                EnterBarrier("actor-identified");

                // Manually Quarantine the other system
                RARP.For(Sys).Provider.Transport.Quarantine(Node(_config.Second).Address, uid);

                // Quarantining is not immediate
                Thread.Sleep(1000);

                // Quarantine is up - Should not be able to communicate with remote system any more
                for (var i = 1; i <= 4; i++)
                {
                    Sys.ActorSelection(Node(_config.Second) / "user" / "subject").Tell("getuid");

                    ExpectNoMsg(TimeSpan.FromSeconds(2));
                }

                EnterBarrier("quarantine-intact");
            }, _config.First);

            RunOn(() =>
            {
                Sys.ActorOf <Subject>("subject");
                EnterBarrier("actors-started");
                EnterBarrier("actor-identified");
                EnterBarrier("quarantine-intact");
            }, _config.Second);
        }
コード例 #17
0
        public void DotNetty_transport_can_communicate_with_Helios_transport()
        {
            LoggingFactory.DefaultFactory = new XunitLoggingFactory(Output);
            var heliosConfig = ConfigurationFactory.ParseString(@"
                akka {
                    actor.provider = ""Akka.Remote.RemoteActorRefProvider, Akka.Remote""

                    remote {
                        enabled-transports = [""akka.remote.helios.tcp""]
                        helios.tcp {
                            hostname = ""localhost""
                            port = 11223
                        }
                    }
                }");

            using (var heliosSystem = ActorSystem.Create("helios-system", heliosConfig))
            {
                InitializeLogger(heliosSystem);
                heliosSystem.ActorOf(Props.Create <Echo>(), "echo");

                var heliosProvider = RARP.For(heliosSystem).Provider;

                Assert.Equal(
                    "Akka.Remote.Transport.Helios.HeliosTcpTransport, Akka.Remote.Transport.Helios",
                    heliosProvider.RemoteSettings.Transports.First().TransportClass);

                var address = heliosProvider.DefaultAddress;

                Assert.Equal(11223, address.Port.Value);

                var echo = Sys.ActorSelection(new RootActorPath(address) / "user" / "echo");
                echo.Tell("hello", TestActor);
                ExpectMsg("hello");
            }
        }
コード例 #18
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.dot-netty.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.dot-netty.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.dot-netty.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.dot-netty.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(() => { });

            AwaitAssert(() =>
            {
                AssertActors(initialActors, targets.SelectMany(CollectLiveActors).ToImmutableHashSet());
            }, 5.Seconds());
        }
コード例 #19
0
        public Property HeliosTransport_Should_Resolve_DNS_with_PublicHostname(IPEndPoint inbound, DnsEndPoint publicInbound,
                                                                               IPEndPoint outbound, DnsEndPoint publicOutbound, bool dnsUseIpv6, bool enforceIpFamily)
        {
            // TODO: Mono does not support IPV6 Uris correctly https://bugzilla.xamarin.com/show_bug.cgi?id=43649 (Aaronontheweb 8/22/2016)
            if (IsMono)
            {
                enforceIpFamily = true;
            }
            if (IsMono && dnsUseIpv6)
            {
                return(true.Label("Mono DNS does not support IPV6 as of 4.4*"));
            }
            if (IsMono &&
                (inbound.AddressFamily == AddressFamily.InterNetworkV6 ||
                 (outbound.AddressFamily == AddressFamily.InterNetworkV6)))
            {
                return(true.Label("Mono DNS does not support IPV6 as of 4.4*"));
            }

            if (dnsUseIpv6 &&
                (inbound.AddressFamily == AddressFamily.InterNetwork ||
                 (outbound.AddressFamily == AddressFamily.InterNetwork)))
            {
                return(true.Label("Can't connect to IPV4 socket using IPV6 DNS resolution"));
            }
            if (!dnsUseIpv6 &&
                (inbound.AddressFamily == AddressFamily.InterNetworkV6 ||
                 (outbound.AddressFamily == AddressFamily.InterNetworkV6)))
            {
                return(true.Label("Need to apply DNS resolution and IP stack verison consistently."));
            }


            try
            {
                try
                {
                    Setup(EndpointGenerators.ParseAddress(inbound),
                          EndpointGenerators.ParseAddress(outbound),
                          EndpointGenerators.ParseAddress(publicInbound),
                          EndpointGenerators.ParseAddress(publicOutbound),
                          dnsUseIpv6,
                          enforceIpFamily);
                }
                catch
                {
                    //if ip family is enforced, there are some special cases when it is normal to unable
                    //to create actor system
                    if (enforceIpFamily && IsExpectedFailure(inbound, outbound, dnsUseIpv6))
                    {
                        return(true.ToProperty());
                    }
                    throw;
                }
                var outboundReceivedAck = true;
                var inboundReceivedAck  = true;
                _outbound.ActorSelection(_inboundAck).Tell("ping", _outboundProbe.Ref);
                try
                {
                    _outboundProbe.ExpectMsg("ack");
                }
                catch
                {
                    outboundReceivedAck = false;
                }

                _inbound.ActorSelection(_outboundAck).Tell("ping", _inboundProbe.Ref);
                try
                {
                    _inboundProbe.ExpectMsg("ack");
                }
                catch
                {
                    inboundReceivedAck = false;
                }


                return(outboundReceivedAck.Label($"Expected (outbound: {RARP.For(_outbound).Provider.DefaultAddress}) to be able to successfully message and receive reply from (inbound: {RARP.For(_inbound).Provider.DefaultAddress})")
                       .And(inboundReceivedAck.Label($"Expected (inbound: {RARP.For(_inbound).Provider.DefaultAddress}) to be able to successfully message and receive reply from (outbound: {RARP.For(_outbound).Provider.DefaultAddress})")));
            }
            finally
            {
                Cleanup();
            }
        }
コード例 #20
0
        public Property HeliosTransport_Should_Resolve_DNS(EndPoint inbound, EndPoint outbound, bool dnsIpv6, bool enforceIpFamily)
        {
            // TODO: Mono does not support IPV6 Uris correctly https://bugzilla.xamarin.com/show_bug.cgi?id=43649 (Aaronontheweb 8/22/2016)
            if (IsMono)
            {
                enforceIpFamily = true;
                dnsIpv6         = false;
            }


            if (IsAnyIp(inbound) || IsAnyIp(outbound))
            {
                return(true.Label("Can't connect directly to an ANY address"));
            }
            try
            {
                try
                {
                    Setup(EndpointGenerators.ParseAddress(inbound),
                          EndpointGenerators.ParseAddress(outbound),
                          useIpv6Dns: dnsIpv6,
                          enforceIpFamily: enforceIpFamily);
                }
                catch
                {
                    //if ip family is enforced, there are some special cases when it is normal to unable
                    //to create actor system
                    if (enforceIpFamily && IsExpectedFailure(inbound, outbound, dnsIpv6))
                    {
                        return(true.ToProperty());
                    }
                    throw;
                }

                var outboundReceivedAck = true;
                var inboundReceivedAck  = true;
                _outbound.ActorSelection(_inboundAck).Tell("ping", _outboundProbe.Ref);
                try
                {
                    _outboundProbe.ExpectMsg("ack");
                }
                catch
                {
                    outboundReceivedAck = false;
                }

                _inbound.ActorSelection(_outboundAck).Tell("ping", _inboundProbe.Ref);
                try
                {
                    _inboundProbe.ExpectMsg("ack");
                }
                catch
                {
                    inboundReceivedAck = false;
                }

                return(outboundReceivedAck.Label($"Expected (outbound: {RARP.For(_outbound).Provider.DefaultAddress}) to be able to successfully message and receive reply from (inbound: {RARP.For(_inbound).Provider.DefaultAddress})")
                       .And(inboundReceivedAck.Label($"Expected (inbound: {RARP.For(_inbound).Provider.DefaultAddress}) to be able to successfully message and receive reply from (outbound: {RARP.For(_outbound).Provider.DefaultAddress})")));
            }
            finally
            {
                Cleanup();
            }
        }
コード例 #21
0
        public void A_restarted_quarantined_system_should_not_crash_the_other_system()
        {
            Sys.ActorOf <RemoteRestartedQuarantinedMultiNetSpec.Subject>("subject");
            EnterBarrier("subject-started");

            RunOn(() =>
            {
                var secondAddress = Node(_config.Second).Address;
                var uid           = _identifyWithUid(_config.Second, "subject").Item1;

                RARP.For(Sys).Provider.Transport.Quarantine(Node(_config.Second).Address, uid);

                EnterBarrier("quarantined");
                EnterBarrier("still-quarantined");

                TestConductor.Shutdown(_config.Second).Wait();

                Within(TimeSpan.FromSeconds(30), () =>
                {
                    AwaitAssert(() =>
                    {
                        Sys.ActorSelection(new RootActorPath(secondAddress) / "user" / "subject")
                        .Tell(new Identify("subject"));
                        ExpectMsg <ActorIdentity>(i => i.Subject != null, TimeSpan.FromSeconds(1));
                    });
                });

                Sys.ActorSelection(new RootActorPath(secondAddress) / "user" / "subject").Tell("shutdown");
            }, _config.First);

            RunOn(() =>
            {
                var addr         = ((ExtendedActorSystem)Sys).Provider.DefaultAddress;
                var firstAddress = Node(_config.First).Address;
                Sys.EventStream.Subscribe(TestActor, typeof(ThisActorSystemQuarantinedEvent));

                var actorRef = _identifyWithUid(_config.First, "subject").Item2;

                EnterBarrier("quarantined");

                // Check that quarantine is intact
                Within(TimeSpan.FromSeconds(10), () =>
                {
                    AwaitAssert(() =>
                    {
                        EventFilter.Warning(null, null, "The remote system has quarantined this system")
                        .ExpectOne(() => actorRef.Tell("boo!"));
                    });
                });

                ExpectMsg <ThisActorSystemQuarantinedEvent>(TimeSpan.FromSeconds(10));

                EnterBarrier("still-quarantined");

                Sys.WhenTerminated.Wait(TimeSpan.FromSeconds(10));

                var sb = new StringBuilder()
                         .AppendLine("akka.remote.retry-gate-closed-for = 0.5 s")
                         .AppendLine("akka.remote.helios.tcp {")
                         .AppendLine("hostname = " + addr.Host)
                         .AppendLine("port = " + addr.Port)
                         .AppendLine("}");
                var freshSystem = ActorSystem.Create(Sys.Name,
                                                     ConfigurationFactory.ParseString(sb.ToString()).WithFallback(Sys.Settings.Config));

                var probe = CreateTestProbe(freshSystem);

                freshSystem.ActorSelection(new RootActorPath(firstAddress) / "user" / "subject")
                .Tell(new Identify("subject"), probe.Ref);

                // TODO sometimes it takes long time until the new connection is established,
                //      It seems like there must first be a transport failure detector timeout, that triggers
                //      "No response from remote. Handshake timed out or transport failure detector triggered"
                probe.ExpectMsg <ActorIdentity>(i => i.Subject != null, TimeSpan.FromSeconds(30));

                freshSystem.ActorOf <RemoteRestartedQuarantinedMultiNetSpec.Subject>("subject");

                freshSystem.WhenTerminated.Wait(TimeSpan.FromSeconds(10));
            }, _config.Second);
        }
コード例 #22
0
        public void RemoteNodeShutdownAndComesBack_must_properly_reset_system_message_buffer_state_when_new_system_with_same_Address_comes_up()
        {
            RunOn(() =>
            {
                var secondAddress = Node(_config.Second).Address;
                Sys.ActorOf <RemoteNodeShutdownAndComesBackMultiNetSpec.Subject>("subject");
                EnterBarrier("actors-started");

                var subject       = _identify(_config.Second, "subject");
                var sysmsgBarrier = _identify(_config.Second, "sysmsgBarrier");

                // Prime up the system message buffer
                Watch(subject);
                EnterBarrier("watch-established");

                // Wait for proper system message propagation
                // (Using a helper actor to ensure that all previous system messages arrived)
                Watch(sysmsgBarrier);
                Sys.Stop(sysmsgBarrier);
                ExpectTerminated(sysmsgBarrier);

                // Drop all messages from this point so no SHUTDOWN is ever received
                TestConductor.Blackhole(_config.Second, _config.First, ThrottleTransportAdapter.Direction.Send).Wait();

                // Shut down all existing connections so that the system can enter recovery mode (association attempts)
                RARP.For(Sys)
                .Provider.Transport.ManagementCommand(new ForceDisassociate(Node(_config.Second).Address))
                .Wait(TimeSpan.FromSeconds(3));

                // Trigger reconnect attempt and also queue up a system message to be in limbo state (UID of remote system
                // is unknown, and system message is pending)
                Sys.Stop(subject);

                // Get rid of old system -- now SHUTDOWN is lost
                TestConductor.Shutdown(_config.Second).Wait();

                // At this point the second node is restarting, while the first node is trying to reconnect without resetting
                // the system message send state

                // Now wait until second system becomes alive again
                Within(TimeSpan.FromSeconds(30), () =>
                {
                    // retry because the Subject actor might not be started yet
                    AwaitAssert(() =>
                    {
                        var p = CreateTestProbe();
                        Sys.ActorSelection(new RootActorPath(secondAddress) / "user" / "subject").Tell(new Identify("subject"), p.Ref);
                        p.ExpectMsg <ActorIdentity>(i => i.Subject != null && "subject".Equals(i.MessageId), TimeSpan.FromSeconds(1));
                    });
                });

                ExpectTerminated(subject, TimeSpan.FromSeconds(10));

                // Establish watch with the new system. This triggers additional system message traffic. If buffers are out
                // of sync the remote system will be quarantined and the rest of the test will fail (or even in earlier
                // stages depending on circumstances).
                Sys.ActorSelection(new RootActorPath(secondAddress) / "user" / "subject").Tell(new Identify("subject"));
                var subjectNew = ExpectMsg <ActorIdentity>(i => i.Subject != null).Subject;
                Watch(subjectNew);

                subjectNew.Tell("shutdown");
                // we are waiting for a Terminated here, but it is ok if it does not arrive
                ReceiveWhile(TimeSpan.FromSeconds(5), msg => msg as ActorIdentity);
            }, _config.First);

            RunOn(() =>
            {
                var addr = ((ExtendedActorSystem)Sys).Provider.DefaultAddress;
                Sys.ActorOf <RemoteNodeShutdownAndComesBackMultiNetSpec.Subject>("subject");
                Sys.ActorOf <RemoteNodeShutdownAndComesBackMultiNetSpec.Subject>("sysmsgBarrier");
                EnterBarrier("actors-started");

                EnterBarrier("watch-established");

                Sys.WhenTerminated.Wait(TimeSpan.FromSeconds(30));

                var freshConfig = new StringBuilder().AppendLine("akka.remote.dot-netty.tcp {").AppendLine("hostname = " + addr.Host)
                                  .AppendLine("port = " + addr.Port)
                                  .AppendLine("}").ToString();

                var freshSystem = ActorSystem.Create(Sys.Name,
                                                     ConfigurationFactory.ParseString(freshConfig)
                                                     .WithFallback(Sys.Settings.Config));

                freshSystem.ActorOf <RemoteNodeShutdownAndComesBackMultiNetSpec.Subject>("subject");

                freshSystem.WhenTerminated.Wait(TimeSpan.FromSeconds(30));
            }, _config.Second);
        }
コード例 #23
0
        public Property HeliosTransport_Should_Resolve_DNS_with_PublicHostname(IPEndPoint inbound, DnsEndPoint publicInbound,
                                                                               IPEndPoint outbound, DnsEndPoint publicOutbound, bool dnsUseIpv6)
        {
            if (dnsUseIpv6 &&
                (inbound.AddressFamily == AddressFamily.InterNetwork ||
                 (outbound.AddressFamily == AddressFamily.InterNetwork)))
            {
                return(true.Label("Can't connect to IPV4 socket using IPV6 DNS resolution"));
            }
            if (!dnsUseIpv6 &&
                (inbound.AddressFamily == AddressFamily.InterNetworkV6 ||
                 (outbound.AddressFamily == AddressFamily.InterNetworkV6)))
            {
                return(true.Label("Need to apply DNS resolution and IP stack verison consistently."));
            }

            try
            {
                Setup(EndpointGenerators.ParseAddress(inbound),
                      EndpointGenerators.ParseAddress(outbound),
                      EndpointGenerators.ParseAddress(publicInbound),
                      EndpointGenerators.ParseAddress(publicOutbound), dnsUseIpv6);
                var outboundReceivedAck = true;
                var inboundReceivedAck  = true;
                _outbound.ActorSelection(_inboundAck).Tell("ping", _outboundProbe.Ref);
                try
                {
                    _outboundProbe.ExpectMsg("ack");
                }
                catch
                {
                    outboundReceivedAck = false;
                }

                _inbound.ActorSelection(_outboundAck).Tell("ping", _inboundProbe.Ref);
                try
                {
                    _inboundProbe.ExpectMsg("ack");
                }
                catch
                {
                    inboundReceivedAck = false;
                }


                return(outboundReceivedAck.Label($"Expected (outbound: {RARP.For(_outbound).Provider.DefaultAddress}) to be able to successfully message and receive reply from (inbound: {RARP.For(_inbound).Provider.DefaultAddress})")
                       .And(inboundReceivedAck.Label($"Expected (inbound: {RARP.For(_inbound).Provider.DefaultAddress}) to be able to successfully message and receive reply from (outbound: {RARP.For(_outbound).Provider.DefaultAddress})")));
            }
            finally
            {
                Cleanup();
            }
        }
コード例 #24
0
 public void Setup(BenchmarkContext context)
 {
     _actorSystem   = ActorSystem.Create("MessageDispatcher" + Counter.GetAndIncrement(), RemoteHocon);
     _systemAddress = RARP.For(_actorSystem).Provider.DefaultAddress;
     _inboundMessageDispatcherCounter = context.GetCounter(MessageDispatcherThroughputCounterName);
     _message = new SerializedMessage {
         SerializerId = 0, Message = ByteString.CopyFromUtf8("foo")
     };
     _dispatcher     = new DefaultMessageDispatcher(_actorSystem.AsInstanceOf <ExtendedActorSystem>(), RARP.For(_actorSystem).Provider, _actorSystem.Log);
     _targetActorRef = new BenchmarkActorRef(_inboundMessageDispatcherCounter, RARP.For(_actorSystem).Provider);
 }
コード例 #25
0
        public void TransportFail_should_reconnect()
        {
            RunOn(() =>
            {
                EnterBarrier("actors-started");
                var subject = Identify(_config.Second, "subject");
                Watch(subject);
                subject.Tell("hello");
                ExpectMsg("hello");
            }, _config.First);

            RunOn(() =>
            {
                Sys.ActorOf(Props.Create(() => new TransportFailSpecConfig.Subject()), "subject");
                EnterBarrier("actors-started");
            }, _config.Second);

            EnterBarrier("watch-established");

            // trigger transport failure detector
            TransportFailSpecConfig.FdAvailable.GetAndSet(false);

            // wait for ungated (also later awaitAssert retry)
            Task.Delay(RARP.For(Sys).Provider.RemoteSettings.RetryGateClosedFor).Wait();
            TransportFailSpecConfig.FdAvailable.GetAndSet(true);

            RunOn(() =>
            {
                EnterBarrier("actors-started2");
                var quarantineProbe = CreateTestProbe();
                Sys.EventStream.Subscribe(quarantineProbe.Ref, typeof(QuarantinedEvent));

                IActorRef subject2 = null;
                AwaitAssert(() =>
                {
                    // TODO: harden
                    Within(TimeSpan.FromSeconds(3), () =>
                    {
                        AwaitCondition(() =>
                        {
                            subject2 = Identify(_config.Second, "subject2");
                            return(subject2 != null);
                        }, RemainingOrDefault, TimeSpan.FromSeconds(1));
                    });
                }, TimeSpan.FromSeconds(5));
                Watch(subject2);
                quarantineProbe.ExpectNoMsg(TimeSpan.FromSeconds(1));
                subject2.Tell("hello2");
                ExpectMsg("hello2");
                EnterBarrier("watch-established2");
                ExpectTerminated(subject2);
            }, _config.First);

            RunOn(() =>
            {
                var subject2 = Sys.ActorOf(Props.Create(() => new TransportFailSpecConfig.Subject()), "subject2");
                EnterBarrier("actors-started2");
                EnterBarrier("watch-established2");
                subject2.Tell(PoisonPill.Instance);
            }, _config.Second);

            EnterBarrier("done");
        }
コード例 #26
0
 public void Setup(BenchmarkContext context)
 {
     _actorSystem   = ActorSystem.Create("MessageDispatcher" + Counter.GetAndIncrement(), RemoteHocon);
     _systemAddress = RARP.For(_actorSystem).Provider.DefaultAddress;
     _inboundMessageDispatcherCounter = context.GetCounter(MessageDispatcherThroughputCounterName);
     _message        = SerializedMessage.CreateBuilder().SetSerializerId(0).SetMessage(ByteString.CopyFromUtf8("foo")).Build();
     _dispatcher     = new DefaultMessageDispatcher(_actorSystem, RARP.For(_actorSystem).Provider, _actorSystem.Log);
     _targetActorRef = new BenchmarkActorRef(_inboundMessageDispatcherCounter, RARP.For(_actorSystem).Provider);
 }
コード例 #27
0
        public void RemoteActorRefProvider_default_address_must_include_adapter_schemes()
        {
            var localAddress = RARP.For(Sys).Provider.DefaultAddress;

            Assert.StartsWith("akka.trttl.gremlin.tcp://", localAddress.ToString());
        }
コード例 #28
0
        public void RemoteNodeRestart_must_allow_restarted_node_to_pass_through_gate()
        {
            Sys.ActorOf(Props.Create(() => new Subject()), "subject");
            EnterBarrier("subject-started");

            RunOn(() =>
            {
                var secondAddress = Node(_specConfig.Second).Address;

                Identify(_specConfig.Second, "subject");

                EventFilter.Warning(new Regex("address is now gated")).ExpectOne(() =>
                {
                    RARP.For(Sys).Provider.Transport.ManagementCommand(
                        new ForceDisassociateExplicitly(Node(_specConfig.Second).Address, DisassociateInfo.Unknown))
                    .Wait(TimeSpan.FromSeconds(3));
                });


                EnterBarrier("gated");
                TestConductor.Shutdown(_specConfig.Second).Wait();
                Within(TimeSpan.FromSeconds(10), () =>
                {
                    AwaitAssert(
                        () =>
                    {
                        Sys.ActorSelection(new RootActorPath(secondAddress) / "user" / "subject")
                        .Tell(new Identify("subject"));
                        ExpectMsg <ActorIdentity>().Subject.ShouldNotBe(null);
                    });
                });
                Sys.ActorSelection(new RootActorPath(secondAddress) / "user" / "subject").Tell("shutdown");
            }, _specConfig.First);

            RunOn(() =>
            {
                var addr         = Sys.AsInstanceOf <ExtendedActorSystem>().Provider.DefaultAddress;
                var firstAddress = Node(_specConfig.First).Address;

                EnterBarrier("gated");

                Sys.WhenTerminated.Wait(TimeSpan.FromSeconds(10));

                var sb = new StringBuilder();
                sb.AppendLine("akka.remote.retry-gate-closed-for = 0.5s")
                .AppendLine(" akka.remote.dot-netty.tcp {")
                .AppendLine("hostname = " + addr.Host)
                .AppendLine("port =" + addr.Port)
                .AppendLine("}");

                var freshSystem = ActorSystem.Create(Sys.Name, ConfigurationFactory.ParseString(sb.ToString())
                                                     .WithFallback(Sys.Settings.Config));

                var probe = CreateTestProbe(freshSystem);

                // Pierce the gate
                Within(TimeSpan.FromSeconds(30), () =>
                {
                    AwaitAssert(() =>

                    {
                        freshSystem.ActorSelection(new RootActorPath(firstAddress) / "user" / "subject")
                        .Tell(new Identify("subject"), probe);
                        probe.ExpectMsg <ActorIdentity>();
                    });
                });

                // Now the other system will be able to pass, too
                freshSystem.ActorOf(Props.Create(() => new Subject()), "subject");
                freshSystem.WhenTerminated.Wait(TimeSpan.FromSeconds(30));
            }, _specConfig.Second);
        }
コード例 #29
0
        public void Properly_quarantine_stashed_inbound_connections()
        {
            var localAddress     = new Address("akka.test", "system1", "localhost", 1);
            var rawLocalAddress  = new Address("test", "system1", "localhost", 1);
            var remoteAddress    = new Address("akka.test", "system2", "localhost", 2);
            var rawRemoteAddress = new Address("test", "system2", "localhost", 2);
            var remoteUID        = 16;

            var config = ConfigurationFactory.ParseString(@"
                  akka.remote.enabled-transports = [""akka.remote.test""]
                  akka.remote.retry-gate-closed-for = 5s     
                  akka.remote.log-remote-lifecycle-events = on  
     
            akka.remote.test {
                registry-key = JMeMndLLsw
                local-address = """ + $"test://{localAddress.System}@{localAddress.Host}:{localAddress.Port}" + @"""
            }").WithFallback(_remoteSystem.Settings.Config);

            var thisSystem = ActorSystem.Create("this-system", config);

            MuteSystem(thisSystem);

            try
            {
                // Set up a mock remote system using the test transport
                var registry             = AssociationRegistry.Get("JMeMndLLsw");
                var remoteTransport      = new TestTransport(rawRemoteAddress, registry);
                var remoteTransportProbe = CreateTestProbe();

                registry.RegisterTransport(remoteTransport, Task.FromResult <IAssociationEventListener>
                                               (new ActorAssociationEventListener(remoteTransportProbe)));

                // Hijack associations through the test transport
                AwaitCondition(() => registry.TransportsReady(rawLocalAddress, rawRemoteAddress));
                var testTransport = registry.TransportFor(rawLocalAddress).Item1;
                testTransport.WriteBehavior.PushConstant(true);

                // Force an outbound associate on the real system (which we will hijack)
                // we send no handshake packet, so this remains a pending connection
                var dummySelection = thisSystem.ActorSelection(ActorPath.Parse(remoteAddress + "/user/noonethere"));
                dummySelection.Tell("ping", Sys.DeadLetters);

                var remoteHandle = remoteTransportProbe.ExpectMsg <InboundAssociation>(TimeSpan.FromMinutes(4));
                remoteHandle.Association.ReadHandlerSource.TrySetResult((IHandleEventListener)(new ActionHandleEventListener(ev => {})));

                // Now we initiate an emulated inbound connection to the real system
                var inboundHandleProbe = CreateTestProbe();
                var inboundHandleTask  = remoteTransport.Associate(rawLocalAddress);
                inboundHandleTask.Wait(TimeSpan.FromSeconds(3));
                var inboundHandle = inboundHandleTask.Result;
                inboundHandle.ReadHandlerSource.SetResult(new ActorHandleEventListener(inboundHandleProbe));

                AwaitAssert(() =>
                {
                    registry.GetRemoteReadHandlerFor(inboundHandle.AsInstanceOf <TestAssociationHandle>()).Should().NotBeNull();
                });

                var pduCodec = new AkkaPduProtobuffCodec(Sys);

                var handshakePacket = pduCodec.ConstructAssociate(new HandshakeInfo(rawRemoteAddress, remoteUID));

                // Finish the inbound handshake so now it is handed up to Remoting
                inboundHandle.Write(handshakePacket);

                // No disassociation now, the connection is still stashed
                inboundHandleProbe.ExpectNoMsg(1000);

                // Quarantine unrelated connection
                RARP.For(thisSystem).Provider.Quarantine(remoteAddress, -1);
                inboundHandleProbe.ExpectNoMsg(1000);

                // Quarantine the connection
                RARP.For(thisSystem).Provider.Quarantine(remoteAddress, remoteUID);

                // Even though the connection is stashed it will be disassociated
                inboundHandleProbe.ExpectMsg <Disassociated>();
            }
            finally
            {
                Shutdown(thisSystem);
            }
        }
コード例 #30
0
        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
        }