當前位置: 首頁>>代碼示例>>C#>>正文


C# ConnectionFactory.IsClosed方法代碼示例

本文整理匯總了C#中NATS.Client.ConnectionFactory.IsClosed方法的典型用法代碼示例。如果您正苦於以下問題:C# ConnectionFactory.IsClosed方法的具體用法?C# ConnectionFactory.IsClosed怎麽用?C# ConnectionFactory.IsClosed使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在NATS.Client.ConnectionFactory的用法示例。


在下文中一共展示了ConnectionFactory.IsClosed方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: TestTimeoutOnNoServers

        public void TestTimeoutOnNoServers()
        {
            Options opts = ConnectionFactory.GetDefaultOptions();
            Object dmu = new Object();
            Object cmu = new Object();

            opts.Servers = testServersShortList;
            opts.NoRandomize = true;
            opts.MaxReconnect = 2;
            opts.ReconnectWait = 100; // millis

            bool disconnectHandlerCalled = false;
            bool closedHandlerCalled = false;

            opts.DisconnectedEventHandler = (sender, args) =>
            {
                lock (dmu)
                {
                    disconnectHandlerCalled = true;
                    Monitor.Pulse(dmu);
                }
            };

            opts.ClosedEventHandler = (sender, args) =>
            {
                lock (cmu)
                {
                    closedHandlerCalled = true;
                    Monitor.Pulse(cmu);
                }
            };

            using (NATSServer s1 = utils.CreateServerOnPort(1222))
            {
                using (IConnection c = new ConnectionFactory().CreateConnection(opts))
                {
                    s1.Shutdown();

                    lock (dmu)
                    {
                        if (!disconnectHandlerCalled)
                           Assert.IsTrue(Monitor.Wait(dmu, 20000));
                    }

                    Stopwatch sw = new Stopwatch();
                    sw.Start();

                    lock (cmu)
                    {
                        if (!closedHandlerCalled)
                            Assert.IsTrue(Monitor.Wait(cmu, 60000));
                    }

                    sw.Stop();

                    int expected = opts.MaxReconnect * opts.ReconnectWait;

                    // .NET has long connect times, so revisit this after
                    // a connect timeout has been added.
                    //Assert.IsTrue(sw.ElapsedMilliseconds < (expected + 500));

                    Assert.IsTrue(disconnectHandlerCalled);
                    Assert.IsTrue(closedHandlerCalled);
                    Assert.IsTrue(c.IsClosed());
                }
            }
        }
開發者ID:bendan365,項目名稱:csnats-wip,代碼行數:67,代碼來源:UnitTestCluster.cs

示例2: TestProperFalloutAfterMaxAttempts

        public void TestProperFalloutAfterMaxAttempts()
        {
            Options opts = ConnectionFactory.GetDefaultOptions();

            Object dmu = new Object();
            Object cmu = new Object();

            opts.Servers = this.testServersShortList;
            opts.NoRandomize = true;
            opts.MaxReconnect = 2;
            opts.ReconnectWait = 25; // millis
            opts.Timeout = 500;

            bool disconnectHandlerCalled = false;

            opts.DisconnectedEventHandler = (sender, args) =>
            {
                lock (dmu)
                {
                    disconnectHandlerCalled = true;
                    Monitor.Pulse(dmu);
                }
            };

            bool closedHandlerCalled = false;
            opts.ClosedEventHandler = (sender, args) =>
            {
                lock (cmu)
                {
                    closedHandlerCalled = true;
                    Monitor.Pulse(cmu);
                }
            };

            using (NATSServer s1 = utils.CreateServerOnPort(1222))
            {
                using (IConnection c = new ConnectionFactory().CreateConnection(opts))
                {
                    s1.Shutdown();

                    lock (dmu)
                    {
                        if (!disconnectHandlerCalled)
                            Assert.IsTrue(Monitor.Wait(dmu, 20000));
                    }

                    lock (cmu)
                    {
                        if (!closedHandlerCalled)
                            Assert.IsTrue(Monitor.Wait(cmu, 60000));
                    }

                    Assert.IsTrue(disconnectHandlerCalled);
                    Assert.IsTrue(closedHandlerCalled);
                    Assert.IsTrue(c.IsClosed());
                }
            }
        }
開發者ID:bendan365,項目名稱:csnats-wip,代碼行數:58,代碼來源:UnitTestCluster.cs

示例3: TestProperFalloutAfterMaxAttemptsWithAuthMismatch

        public void TestProperFalloutAfterMaxAttemptsWithAuthMismatch()
        {
            Options opts = utils.DefaultTestOptions;

            Object dmu = new Object();
            Object cmu = new Object();

            opts.Servers = new string[] {
                "nats://localhost:1220",
                "nats://localhost:1222"
            };

            opts.NoRandomize = true;
            opts.MaxReconnect = 2;
            opts.ReconnectWait = 25; // millis
            opts.Timeout = 1000;

            bool disconnectHandlerCalled = false;

            opts.DisconnectedEventHandler = (sender, args) =>
            {
                lock (dmu)
                {
                    disconnectHandlerCalled = true;
                    Monitor.Pulse(dmu);
                }
            };

            bool closedHandlerCalled = false;
            opts.ClosedEventHandler = (sender, args) =>
            {
                lock (cmu)
                {
                    closedHandlerCalled = true;
                    Monitor.Pulse(cmu);
                }
            };

            using (NATSServer s1 = utils.CreateServerOnPort(1220),
                   s2 = utils.CreateServerWithConfig("tls_1222_verify.conf"))
            {
                using (IConnection c = new ConnectionFactory().CreateConnection(opts))
                {
                    s1.Shutdown();

                    lock (dmu)
                    {
                        if (!disconnectHandlerCalled)
                            Assert.True(Monitor.Wait(dmu, 20000));
                    }

                    lock (cmu)
                    {
                        if (!closedHandlerCalled)
                            Assert.True(Monitor.Wait(cmu, 600000));
                    }

                    Assert.True(c.Stats.Reconnects != opts.MaxReconnect);

                    Assert.True(disconnectHandlerCalled);
                    Assert.True(closedHandlerCalled);
                    Assert.True(c.IsClosed());
                }
            }
        }
開發者ID:nats-io,項目名稱:csnats,代碼行數:65,代碼來源:UnitTestCluster.cs

示例4: TestClose

        public void TestClose()
        {
            Options opts = utils.DefaultTestOptions;
            opts.Url = "nats://localhost:22222";
            opts.AllowReconnect = true;
            opts.MaxReconnect = 60;

            using (NATSServer s1 = utils.CreateServerOnPort(22222))
            {
                IConnection c = new ConnectionFactory().CreateConnection(opts);
                Assert.False(c.IsClosed());

                s1.Shutdown();

                Thread.Sleep(100);
                Assert.False(c.IsClosed(), string.Format("Invalid state, expecting not closed, received: {0}", c.State));

                using (NATSServer s2 = utils.CreateServerOnPort(22222))
                {
                    Thread.Sleep(1000);
                    Assert.False(c.IsClosed());

                    c.Close();
                    Assert.True(c.IsClosed());
                }
            }
        }
開發者ID:nats-io,項目名稱:csnats,代碼行數:27,代碼來源:UnitTestReconnect.cs

示例5: TestClose

        public void TestClose()
        {
            Options opts = ConnectionFactory.GetDefaultOptions();
            opts.Url = "nats://localhost:22222";
            opts.AllowReconnect = true;
            opts.MaxReconnect = 60;

            using (NATSServer s1 = utils.CreateServerOnPort(22222))
            {
                IConnection c = new ConnectionFactory().CreateConnection(opts);
                Assert.IsFalse(c.IsClosed());

                s1.Shutdown();

                Thread.Sleep(100);
                if (c.IsClosed())
                {
                    Assert.Fail("Invalid state, expecting not closed, received: "
                        + c.State.ToString());
                }

                using (NATSServer s2 = utils.CreateServerOnPort(22222))
                {
                    Thread.Sleep(1000);
                    Assert.IsFalse(c.IsClosed());

                    c.Close();
                    Assert.IsTrue(c.IsClosed());
                }
            }
        }
開發者ID:ColinSullivan1,項目名稱:csnats,代碼行數:31,代碼來源:UnitTestReconnect.cs


注:本文中的NATS.Client.ConnectionFactory.IsClosed方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。