public void TestConnectionTimeout()
        {
            var initiator = new TcpInitiator
            {
                OperationalContext = new DefaultOperationalContext()
            };
            Stream       stream    = GetType().Assembly.GetManifestResourceStream("Tangosol.Resources.s4hc-timeout-cache-config.xml");
            IXmlDocument xmlConfig = XmlHelper.LoadXml(stream);

            IXmlElement initConfig = xmlConfig.FindElement("caching-schemes/remote-cache-scheme/initiator-config");

            initiator.Configure(initConfig);
            initiator.RegisterProtocol(CacheServiceProtocol.Instance);
            initiator.RegisterProtocol(NamedCacheProtocol.Instance);
            initiator.Start();
            Assert.AreEqual(initiator.IsRunning, true);

            IConnection conn            = null;
            bool        exceptionCaught = false;

            try {
                conn = initiator.EnsureConnection();
            }
            catch (Tangosol.Net.Messaging.ConnectionException)
            {
                // good, should time out
                exceptionCaught = true;
            }
            Assert.IsNull(conn);
            Assert.IsTrue(exceptionCaught);
            initiator.Stop();
        }
        public void TestEnsureAndCloseConnection()
        {
            IConnection  conn;
            TcpInitiator initiator = GetInitiator();

            initiator.Start();
            conn = initiator.EnsureConnection();
            Assert.IsNotNull(conn);
            Assert.AreEqual(conn.IsOpen, true);
            conn.Close();
            Assert.AreEqual(conn.IsOpen, false);
            initiator.Stop();
        }
        public void TestEnsureAndCloseConnectionSocket()
        {
            TcpConnection conn;
            TcpInitiator  initiator = GetInitiator();

            initiator.Start();
            conn = (TcpConnection)initiator.EnsureConnection();
            Assert.IsNotNull(conn);
            Assert.AreEqual(conn.IsOpen, true);
            conn.Client.Close();
            Thread.Sleep(2000);
            Assert.AreEqual(conn.IsOpen, false);
            initiator.Stop();
        }
        public void TestTcpConnectionRemoteHostAddress()
        {
            TcpInitiator     initiator       = GetInitiator();
            IAddressProvider addressProvider = initiator.RemoteAddressProvider;

            Assert.IsTrue(addressProvider is ConfigurableAddressProvider);

            TcpConnection conn = (TcpConnection)initiator.EnsureConnection();

            Assert.IsNotNull(conn);
            Assert.AreEqual(conn.IsOpen, true);
            Assert.True(addressProvider is ConfigurableAddressProvider);
            Assert.AreEqual(((ConfigurableAddressProvider)addressProvider).RemoteHostAddress, "127.0.0.1");
            conn.Close();
            Assert.AreEqual(conn.IsOpen, false);

            initiator.Stop();
            Assert.AreEqual(initiator.IsRunning, false);
        }
        public void TestWithAddressProvider()
        {
            var initiator = new TcpInitiator
            {
                OperationalContext = new DefaultOperationalContext()
            };
            Stream       stream            = GetType().Assembly.GetManifestResourceStream("Tangosol.Resources.s4hc-cache-config.xml");
            IXmlDocument xmlConfig         = XmlHelper.LoadXml(stream);
            IXmlElement  remoteAddressNode = xmlConfig.FindElement(
                "caching-schemes/remote-cache-scheme/initiator-config/tcp-initiator/remote-addresses");

            if (null != remoteAddressNode)
            {
                IXmlElement socketAddressNode = remoteAddressNode.GetElement("socket-address");
                if (null != socketAddressNode)
                {
                    XmlHelper.RemoveElement(remoteAddressNode, "socket-address");
                }

                remoteAddressNode.AddElement("address-provider").AddElement("class-name").SetString(
                    "Tangosol.Net.ConfigurableAddressProviderTests+LoopbackAddressProvider, Coherence.Tests");
            }

            IXmlElement initConfig = xmlConfig.FindElement("caching-schemes/remote-cache-scheme/initiator-config");

            initiator.Configure(initConfig);
            initiator.RegisterProtocol(CacheServiceProtocol.Instance);
            initiator.RegisterProtocol(NamedCacheProtocol.Instance);
            initiator.Start();
            Assert.AreEqual(initiator.IsRunning, true);

            IConnection conn = initiator.EnsureConnection();

            Assert.IsNotNull(conn);
            Assert.AreEqual(conn.IsOpen, true);
            conn.Close();
            initiator.Stop();
        }