示例#1
0
        public void IsLoopbackAddressTest()
        {
            Assert.IsTrue(NetworkUtils.IsLoopbackAddress(IPAddress.Loopback));
            IPAddress address = NetworkUtils.GetLocalHostAddress();

            Assert.IsFalse(NetworkUtils.IsLoopbackAddress(address));
        }
示例#2
0
        public void IsAnyLocalAddressTest()
        {
            IPAddress address = NetworkUtils.GetLocalHostAddress();

            Assert.IsFalse(NetworkUtils.IsAnyLocalAddress(address));
            Assert.IsTrue(NetworkUtils.IsAnyLocalAddress(IPAddress.Any));
        }
示例#3
0
        public void UUIDTest()
        {
            long epochTime = new DateTime(1970, 1, 1).Ticks / 10000;

            UUID   uuid1 = new UUID();
            UUID   uuid2 = new UUID();
            String id1   = uuid1.ToString();
            String id2   = uuid2.ToString();

            Assert.AreNotEqual(id1, id2);
            Assert.AreEqual(uuid1.Address, uuid2.Address);
            Assert.AreNotEqual(uuid1.Port, uuid2.Port);
            Assert.Less(uuid1.Count, uuid2.Count);
            Assert.IsTrue(uuid1.Timestamp <= uuid2.Timestamp);
            Assert.AreNotEqual(uuid1.GetHashCode(), uuid2.GetHashCode());
            Assert.IsTrue(uuid1.IsGenerated);
            Assert.IsTrue(uuid1.IsAddressIncluded);

            IPAddress addr = NetworkUtils.GetLocalHostAddress();

            uuid1 = new UUID(epochTime, addr, 8080, 1);
            uuid2 = new UUID(epochTime, addr, 8080, 1);
            id1   = uuid1.ToString();
            id2   = uuid2.ToString();
            Assert.AreEqual(id1, id2);
            Assert.AreEqual(uuid1.Address, uuid2.Address);
            Assert.AreEqual(uuid1.GetHashCode(), uuid2.GetHashCode());
            Assert.IsTrue(uuid1.CompareTo(uuid2) == 0);

            addr = new IPAddress(new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 });
            UUID   uuid3 = new UUID(epochTime, addr, 8080, 2);
            String id3   = uuid3.ToString();

            Assert.AreNotEqual(uuid1.Address, uuid3.Address);
            Assert.IsTrue(uuid1.CompareTo(uuid3) > 0);

            byte[] byteArray = uuid3.ToByteArray();
            uuid1 = new UUID(byteArray);
            uuid2 = new UUID(id3);
            id1   = uuid1.ToString();
            id2   = uuid2.ToString();
            Assert.AreEqual(id1, id2);
            Assert.AreEqual(uuid1.Address, uuid2.Address);
            Assert.AreEqual(uuid1.GetHashCode(), uuid2.GetHashCode());
            Assert.IsTrue(uuid1.CompareTo(uuid2) == 0);
            Assert.IsFalse(uuid1.IsGenerated);
            Assert.IsTrue(uuid1.Equals(uuid2));
            Assert.IsTrue(uuid2.Equals(uuid1));

            UUID uuid4 = new UUID(epochTime, new byte[0], 8080, 1);

            uuid4 = new UUID(epochTime, (byte[])null, 8080, 1);
        }
示例#4
0
        public void UUIDSerializationTest()
        {
            IPAddress        addr = NetworkUtils.GetLocalHostAddress();
            UUID             uuid = new UUID(DateTimeUtils.GetSafeTimeMillis(), addr, 8080, 1);
            SimplePofContext ctx  = new SimplePofContext();

            ctx.RegisterUserType(20, typeof(UUID), new PortableObjectSerializer(20));
            Stream stream = new MemoryStream();

            ctx.Serialize(new DataWriter(stream), uuid);
            stream.Position = 0;
            UUID result = (UUID)ctx.Deserialize(new DataReader(stream));

            Assert.AreEqual(uuid.ToString(), result.ToString());
        }
示例#5
0
        public void UUIDFetchFromClusterTest()
        {
            // COH-8647 - verify that the timestamp in the Coherence cluster corresponds
            // to the local timestamp.  It would be nice to verify the UUID in LocalMember
            // transfers to the Cluster and back but the UUID is a private data member and
            // LocalMember.Equals() is not implemented.
            INamedCache cache   = CacheFactory.GetCache(CacheName);
            UUID        uuid    = new UUID(DateTimeUtils.GetSafeTimeMillis(), NetworkUtils.GetLocalHostAddress(), 51717, 1);
            string      uuidKey = "UUID";

            cache[uuidKey] = uuid;
            UUID cachedUUID = (UUID)cache[uuidKey];

            Assert.AreEqual(uuid, cachedUUID);
            Assert.AreEqual(DateTimeUtils.GetDateTime(uuid.Timestamp).ToString(), cache.Invoke(uuidKey, new ProcessorPrintUUIDTimestamp()));
            cache.Clear();
            CacheFactory.Shutdown();
        }
示例#6
0
 public void UUIDTestDateBeforeEpoch()
 {
     IPAddress addr  = NetworkUtils.GetLocalHostAddress();
     UUID      uuid1 = new UUID(1L, addr, 8080, 1);
 }
示例#7
0
        public void GetLocalHostTest()
        {
            IPAddress address = NetworkUtils.GetLocalHostAddress();

            Assert.IsFalse(IPAddress.IsLoopback(address));
        }
示例#8
0
        /// <summary>
        /// Initialize host address information.
        /// </summary>
        static UUID()
        {
            bool isRealAddress = false;
            bool isIPv6        = false;
            int  addr1         = 0x00000000;
            int  addr2         = 0x00000000;
            int  addr3         = 0x00000000;
            int  addr4         = 0x00000000;

            try
            {
                IPAddress addr = NetworkUtils.GetLocalHostAddress();

                byte[] ipBytes = NO_BYTES;
                if (addr != null)
                {
                    ipBytes = addr.GetAddressBytes();
                }

                switch (ipBytes.Length)
                {
                case 4:
                {
                    int ip = (ipBytes[0] & 0xFF) << 24 | (ipBytes[1] & 0xFF) << 16 | (ipBytes[2] & 0xFF) << 8 | (ipBytes[3] & 0xFF);
                    if (ip != 0x00000000 && ip != 0x7F000001)
                    {
                        isRealAddress = true;
                        addr1         = ip;
                    }
                }
                break;


                case 16:
                {
                    int ip1 = (ipBytes[0] & 0xFF) << 24 | (ipBytes[1] & 0xFF) << 16 | (ipBytes[2] & 0xFF) << 8 | (ipBytes[3] & 0xFF);
                    int ip2 = (ipBytes[4] & 0xFF) << 24 | (ipBytes[5] & 0xFF) << 16 | (ipBytes[6] & 0xFF) << 8 | (ipBytes[7] & 0xFF);
                    int ip3 = (ipBytes[8] & 0xFF) << 24 | (ipBytes[9] & 0xFF) << 16 | (ipBytes[10] & 0xFF) << 8 | (ipBytes[11] & 0xFF);
                    int ip4 = (ipBytes[12] & 0xFF) << 24 | (ipBytes[13] & 0xFF) << 16 | (ipBytes[14] & 0xFF) << 8 | (ipBytes[15] & 0xFF);

                    if (!(ip1 == 0x00000000 && ip2 == 0x00000000 && ip3 == 0x00000000 && (ip4 == 0x00000000 || ip4 == 0x00000001)) && !((ipBytes[0] & 0xFF) == 0xFE && (ipBytes[1] & 0xC0) == 0x80))
                    // link-local
                    {
                        isRealAddress = true;
                        isIPv6        = true;
                        addr1         = ip1;
                        addr2         = ip2;
                        addr3         = ip3;
                        addr4         = ip4;
                    }
                }
                break;
                }
            }
            catch (Exception)
            {}

            s_isRealAddress = isRealAddress;
            s_isIPv6        = isIPv6;
            s_addr1         = addr1;
            s_addr2         = addr2;
            s_addr3         = addr3;
            s_addr4         = addr4;
        }