当前位置: 首页>>代码示例>>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;未经允许,请勿转载。