private ThrottlerHandle WrapHandle(AssociationHandle originalHandle, IAssociationEventListener listener,
                                           bool inbound)
        {
            var managerRef = Self;

            return(new ThrottlerHandle(originalHandle, Context.ActorOf(
                                           RARP.For(Context.System).ConfigureDispatcher(
                                               Props.Create(() => new ThrottledAssociation(managerRef, listener, originalHandle, inbound)).WithDeploy(Deploy.Local)),
                                           "throttler" + nextId())));
        }
Пример #2
0
        public void Remoting_should_contain_correct_BatchWriter_settings_in_ReferenceConf()
        {
            var c = RARP.For(Sys).Provider.RemoteSettings.Config.GetConfig("akka.remote.dot-netty.tcp");
            var s = DotNettyTransportSettings.Create(c);

            s.BatchWriterSettings.EnableBatching.Should().BeTrue();
            s.BatchWriterSettings.FlushInterval.Should().Be(BatchWriterSettings.DefaultFlushInterval);
            s.BatchWriterSettings.MaxPendingBytes.Should().Be(BatchWriterSettings.DefaultMaxPendingBytes);
            s.BatchWriterSettings.MaxPendingWrites.Should().Be(BatchWriterSettings.DefaultMaxPendingWrites);
        }
        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);
        }
Пример #4
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);
 }
        private void Setup(string certPath, string password)
        {
            sys2 = ActorSystem.Create("sys2", TestConfig(certPath, password));
            InitializeLogger(sys2);

            var echo = sys2.ActorOf(Props.Create <Echo>(), "echo");

            address1 = RARP.For(Sys).Provider.DefaultAddress;
            address2 = RARP.For(sys2).Provider.DefaultAddress;
            echoPath = new RootActorPath(address2) / "user" / "echo";
        }
Пример #6
0
        public void When_remoting_works_not_in_Mono_ip_enforcement_should_be_defaulted_to_false()
        {
            if (IsMono)
            {
                return;         // skip IF using Mono
            }
            var c = RARP.For(Sys).Provider.RemoteSettings.Config.GetConfig("akka.remote.dot-netty.tcp");
            var s = DotNettyTransportSettings.Create(c);

            Assert.False(s.EnforceIpFamily);
        }
        public async Task RemoteConnection_should_send_and_decode_Done_message()
        {
            var serverProbe = CreateTestProbe("server");
            var clientProbe = CreateTestProbe("client");

            var serverAddress  = IPAddress.Parse("127.0.0.1");
            var serverEndpoint = new IPEndPoint(serverAddress, 0);

            IChannel server = null;
            IChannel client = null;

            try
            {
                var cts = new CancellationTokenSource();
                cts.CancelAfter(TimeSpan.FromSeconds(10));
                var t1 = RemoteConnection.CreateConnection(Role.Server, serverEndpoint, 3,
                                                           new TestConductorHandler(serverProbe.Ref));
                await t1.WithCancellation(cts.Token);

                server = t1.Result; // task will already be complete or cancelled

                var reachableEndpoint = (IPEndPoint)server.LocalAddress;

                var t2 = RemoteConnection.CreateConnection(Role.Client, reachableEndpoint, 3,
                                                           new PlayerHandler(serverEndpoint, 2, TimeSpan.FromSeconds(1), 3, clientProbe.Ref, Log, Sys.Scheduler));
                await t2.WithCancellation(cts.Token);

                client = t2.Result; // task will already be completed or cancelled

                serverProbe.ExpectMsg("active");
                var serverClientChannel = serverProbe.ExpectMsg <IChannel>();
                clientProbe.ExpectMsg <ClientFSM.Connected>();

                var address = RARP.For(Sys).Provider.DefaultAddress;

                // have the client send a message to the server
                await client.WriteAndFlushAsync(Done.Instance);

                var done = serverProbe.ExpectMsg <Done>();
                done.Should().BeOfType <Done>();

                //have the server send a message back to the client
                await serverClientChannel.WriteAndFlushAsync(Done.Instance);

                var done2 = clientProbe.ExpectMsg <Done>();
                done2.Should().BeOfType <Done>();
            }
            finally
            {
                server?.CloseAsync().Wait(TimeSpan.FromSeconds(2));
                client?.CloseAsync().Wait(TimeSpan.FromSeconds(2));
            }
        }
        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();
            }
        }
        public void RemoteConnection_should_send_and_decode_messages()
        {
            var serverProbe = CreateTestProbe("server");
            var clientProbe = CreateTestProbe("client");

            var serverAddress  = IPAddress.Parse("127.0.0.1");
            var serverEndpoint = new IPEndPoint(serverAddress, 0);

            IChannel server = null;
            IChannel client = null;

            try
            {
                var t1 = RemoteConnection.CreateConnection(Role.Server, serverEndpoint, 3,
                                                           new TestConductorHandler(serverProbe.Ref));
                t1.Wait(TimeSpan.FromSeconds(3)).Should().BeTrue();
                server = t1.Result; // task will already be complete or cancelled

                var reachableEndpoint = (IPEndPoint)server.LocalAddress;

                var t2 = RemoteConnection.CreateConnection(Role.Client, reachableEndpoint, 3,
                                                           new PlayerHandler(serverEndpoint, 2, TimeSpan.FromSeconds(1), 3, clientProbe.Ref, Log, Sys.Scheduler));
                t2.Wait(TimeSpan.FromSeconds(3)).Should().BeTrue();
                client = t2.Result; // task will already be completed or cancelled

                serverProbe.ExpectMsg("active");
                var serverClientChannel = serverProbe.ExpectMsg <IChannel>();
                clientProbe.ExpectMsg <ClientFSM.Connected>();

                var address = RARP.For(Sys).Provider.DefaultAddress;

                // have the client send a message to the server
                client.WriteAndFlushAsync(new Hello("test", address));
                var hello = serverProbe.ExpectMsg <Hello>();
                hello.Name.Should().Be("test");
                hello.Address.Should().Be(address);

                // have the server send a message back to the client
                serverClientChannel.WriteAndFlushAsync(new Hello("test2", address));
                var hello2 = clientProbe.ExpectMsg <Hello>();
                hello2.Name.Should().Be("test2");
                hello2.Address.Should().Be(address);
            }
            finally
            {
                server?.CloseAsync().Wait(TimeSpan.FromSeconds(2));
                client?.CloseAsync().Wait(TimeSpan.FromSeconds(2));
            }
        }
        private void Setup(string inboundHostname, string outboundHostname, string inboundPublicHostname = null, string outboundPublicHostname = null, bool useIpv6Dns = false)
        {
            _inbound  = ActorSystem.Create("Sys1", BuildConfig(inboundHostname, 0, inboundPublicHostname, useIpv6Dns));
            _outbound = ActorSystem.Create("Sys2", BuildConfig(outboundHostname, 0, outboundPublicHostname, useIpv6Dns));

            _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);
        }
Пример #11
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", 0));
            Assert.Equal(200, remoteSettings.WatchFailureDetectorConfig.GetDouble("max-sample-size", 0));
            Assert.Equal(TimeSpan.FromSeconds(10), remoteSettings.WatchFailureDetectorConfig.GetTimeSpan("acceptable-heartbeat-pause", null));
            Assert.Equal(TimeSpan.FromMilliseconds(100), remoteSettings.WatchFailureDetectorConfig.GetTimeSpan("min-std-deviation", null));

            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", null).ShouldBe("off");
        }
Пример #12
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));
        }
        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)));
            }
        }
Пример #14
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));
        }
        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
            }
        }
Пример #16
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));
            }
        }
Пример #17
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));
        }
        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();
                }
        }
        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);
            }
        }
Пример #20
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));
 }
        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();
            }
        }
Пример #22
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;
        }
Пример #23
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);
        }
Пример #24
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));
        }
        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");
            }
        }
Пример #26
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);
        }
Пример #27
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();
            }
        }
Пример #28
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();
            }
        }
        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);
        }
Пример #30
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);
        }