Beispiel #1
0
        public void InterNetwork()
        {
            DnsEndPoint dep = new DnsEndPoint("localhost", 0, AddressFamily.InterNetwork);

            Assert.AreEqual("localhost", dep.Host, "Host");
            Assert.AreEqual(AddressFamily.InterNetwork, dep.AddressFamily, "AddressFamily");
            Assert.AreEqual("localhost", dep.Host, "Host");
            Assert.AreEqual(0, dep.Port, "Port");
            Assert.IsFalse(dep.Equals(null), "Equals(null)");
            Assert.IsTrue(dep.Equals(dep), "Equals(self)");
            Assert.AreEqual("InterNetwork/localhost:0", dep.ToString());
        }
Beispiel #2
0
        public void Unspecified()
        {
            DnsEndPoint dep = new DnsEndPoint("localhost", 0, AddressFamily.Unspecified);

            Assert.AreEqual("localhost", dep.Host, "Host");
            Assert.AreEqual(AddressFamily.Unspecified, dep.AddressFamily, "AddressFamily");
            Assert.AreEqual("localhost", dep.Host, "Host");
            Assert.AreEqual(0, dep.Port, "Port");
            Assert.IsFalse(dep.Equals(null), "Equals(null)");
            Assert.IsTrue(dep.Equals(dep), "Equals(self)");
            Assert.AreEqual("Unspecified/localhost:0", dep.ToString());
        }
Beispiel #3
0
        public void Constructor_StringInt()
        {
            Assert.Throws <ArgumentNullException> (delegate {
                new DnsEndPoint(null, 0);
            }, "ctor(null,0)");
            Assert.Throws <ArgumentException> (delegate {
                new DnsEndPoint(String.Empty, 0);
            }, "ctor(Empty,0)");
            Assert.Throws <ArgumentOutOfRangeException> (delegate {
                new DnsEndPoint("localhost", -1);
            }, "ctor(localhost,-1)");
            Assert.Throws <ArgumentOutOfRangeException> (delegate {
                new DnsEndPoint("localhost", (0xffff + 1));
            }, "ctor(localhost,(0xffff + 1))");

            DnsEndPoint dep = new DnsEndPoint("localhost", 65535);

            Assert.AreEqual(AddressFamily.Unspecified, dep.AddressFamily, "AddressFamily");
            Assert.AreEqual("localhost", dep.Host, "Host");
            Assert.AreEqual(65535, dep.Port, "Port");
            Assert.IsFalse(dep.Equals(null), "Equals(null)");
            Assert.IsTrue(dep.Equals(dep), "Equals(self)");
            Assert.AreEqual("Unspecified/localhost:65535", dep.ToString());
        }
Beispiel #4
0
        public static void Equals_Compare_Success()
        {
            DnsEndPoint ep1 = new DnsEndPoint("name", 500, AddressFamily.InterNetwork);
            DnsEndPoint ep2 = new DnsEndPoint("name", 500, AddressFamily.InterNetwork);
            DnsEndPoint ep3 = new DnsEndPoint("name", 700, AddressFamily.InterNetwork);
            DnsEndPoint ep4 = new DnsEndPoint("name", 500, AddressFamily.InterNetworkV6);

            Assert.NotEqual(ep1, null);
            Assert.False(ep1.Equals("string"));

            Assert.Equal(ep1, ep2);
            Assert.Equal(ep2, ep1);
            Assert.Equal(ep1.GetHashCode(), ep2.GetHashCode());

            Assert.NotEqual(ep1, ep3);
            Assert.NotEqual(ep1.GetHashCode(), ep3.GetHashCode());

            Assert.NotEqual(ep1, ep4);
            Assert.NotEqual(ep1.GetHashCode(), ep4.GetHashCode());
        }
Beispiel #5
0
        public static void Equals_Compare_Success()
        {
            DnsEndPoint ep1 = new DnsEndPoint("name", 500, AddressFamily.InterNetwork);
            DnsEndPoint ep2 = new DnsEndPoint("name", 500, AddressFamily.InterNetwork);
            DnsEndPoint ep3 = new DnsEndPoint("name", 700, AddressFamily.InterNetwork);
            DnsEndPoint ep4 = new DnsEndPoint("name", 500, AddressFamily.InterNetworkV6);

            Assert.NotEqual(ep1, null);
            Assert.False(ep1.Equals("string"));

            Assert.Equal(ep1, ep2);
            Assert.Equal(ep2, ep1);
            Assert.Equal(ep1.GetHashCode(), ep2.GetHashCode());

            Assert.NotEqual(ep1, ep3);
            Assert.NotEqual(ep1.GetHashCode(), ep3.GetHashCode());

            Assert.NotEqual(ep1, ep4);
            Assert.NotEqual(ep1.GetHashCode(), ep4.GetHashCode());
        }
Beispiel #6
0
        private async ValueTask <ConnectionOpened> CreateConnection(DnsEndPoint logicalAddress, DnsEndPoint physicalAddress, int connectionKey)
        {
            if (_log.IsDebugEnabled)
            {
                _log.Debug($"Connection for {logicalAddress} not found in cache");
            }
            var targetBroker = $"{physicalAddress.Host}:{physicalAddress.Port}";

            if (!logicalAddress.Equals(physicalAddress))
            {
                targetBroker = $"{logicalAddress.Host}:{logicalAddress.Port}";
            }

            var cnx = _context.ActorOf(Props.Create(() => new ClientCnx(_clientConfig, physicalAddress, targetBroker)), $"{targetBroker}{connectionKey}".ToAkkaNaming());
            var ask = await cnx.Ask <AskResponse>(Connect.Instance);

            if (ask.Failed)
            {
                //in a situation where we cannot connect, and since this will be retried,
                //in order to avoid conflicting actor names, lets kill it
                _context.Stop(cnx);
                await Task.Delay(TimeSpan.FromSeconds(1));

                throw ask.Exception;
            }

            var connection = ask.ConvertTo <ConnectionOpened>();

            if (_pool.TryGetValue(_logicalEndpoint, out _))
            {
                _pool[_logicalEndpoint][_randomKey] = connection;
            }
            else
            {
                _pool.Add(_logicalEndpoint, new Dictionary <int, ConnectionOpened> {
                    { _randomKey, connection }
                });
            }

            return(connection);
        }