public void TestWithValidHostname()
        {
            string hostname = "time.apple.com";  // time.apple.com returns multiple addresses (hopefully)
            string xml      = "<remote-addresses xmlns=\"http://schemas.tangosol.com/cache\"><socket-address><address>"
                              + hostname + "</address><port>80</port></socket-address></remote-addresses>";
            IXmlDocument config = XmlHelper.LoadXml(new StringReader(xml));

            Assert.IsNotNull(config);

            ConfigurableAddressProvider cap = new ConfigurableAddressProvider(config);

            Assert.IsNotNull(cap);
            Assert.AreEqual(cap.ToString(), "[time.apple.com:80]");

            int addressCount = 0;

            for (IPEndPoint endpoint = cap.NextAddress; endpoint != null; endpoint = cap.NextAddress)
            {
                ++addressCount;
                Assert.NotNull(endpoint);
            }
            System.Console.WriteLine("\nConfigurableAddressProvider returned " + addressCount
                                     + " address(es) for host \"" + hostname + "\".");
            Assert.Greater(addressCount, 0);
        }
        public void TestWithInvalidHostname()
        {
            string       xml    = "<remote-addresses xmlns=\"http://schemas.tangosol.com/cache\"><socket-address><address>nonexistenthost.never.ever</address><port>80</port></socket-address></remote-addresses>";
            IXmlDocument config = XmlHelper.LoadXml(new StringReader(xml));

            Assert.IsNotNull(config);

            // safe
            ConfigurableAddressProvider cap = new ConfigurableAddressProvider(config);

            Assert.IsNotNull(cap);
            Assert.AreEqual(cap.ToString(), "[nonexistenthost.never.ever:80]");

            IPEndPoint addr = cap.NextAddress;

            Assert.IsNull(addr);

            // not safe - throw exception on non-resolvable addresses
            cap = new ConfigurableAddressProvider(config, false);
            Assert.IsNotNull(cap);
            Assert.AreEqual(cap.ToString(), "[nonexistenthost.never.ever:80]");

            try
            {
                addr = cap.NextAddress;
                Assert.Fail();
            }
            catch (Exception)
            {
            }
        }
        public void TestWithEmptyConfiguration()
        {
            IXmlDocument config = new SimpleDocument();

            Assert.IsNotNull(config);

            ConfigurableAddressProvider cap = new ConfigurableAddressProvider(config);

            Assert.IsNotNull(cap);
            Assert.AreEqual(cap.ToString(), "[]");
            Assert.IsNull(cap.NextAddress);
        }
        public void TestWithValidConfiguration()
        {
            string       xml    = "<remote-addresses xmlns=\"http://schemas.tangosol.com/cache\"><socket-address><address>10.0.0.120</address><port>80</port></socket-address><socket-address><address>10.0.0.121</address><port>8080</port></socket-address></remote-addresses>";
            IXmlDocument config = XmlHelper.LoadXml(new StringReader(xml));

            Assert.IsNotNull(config);

            ConfigurableAddressProvider cap = new ConfigurableAddressProvider(config);

            Assert.IsNotNull(cap);
            string capString = cap.ToString();

            Assert.IsTrue(capString.Equals("[10.0.0.121:8080,10.0.0.120:80]") ||
                          capString.Equals("[10.0.0.120:80,10.0.0.121:8080]"));

            // without accepting, addresses will be exhausted
            IPEndPoint addr = cap.NextAddress;

            Assert.IsNotNull(addr);
            addr = cap.NextAddress;
            Assert.IsNotNull(addr);
            addr = cap.NextAddress;
            Assert.IsNull(addr);

            addr = cap.NextAddress;
            Assert.IsNotNull(addr);
            cap.Accept();
            if (addr.Port == 80)
            {
                Assert.AreEqual(addr.Address.ToString(), "10.0.0.120");
            }
            else
            {
                Assert.AreEqual(addr.Address.ToString(), "10.0.0.121");
            }

            addr = cap.NextAddress;
            Assert.IsNotNull(addr);
            cap.Reject(null);
        }