当前位置: 首页>>代码示例>>C#>>正文


C# ConnectionFactory.Close方法代码示例

本文整理汇总了C#中NATS.Client.ConnectionFactory.Close方法的典型用法代码示例。如果您正苦于以下问题:C# ConnectionFactory.Close方法的具体用法?C# ConnectionFactory.Close怎么用?C# ConnectionFactory.Close使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在NATS.Client.ConnectionFactory的用法示例。


在下文中一共展示了ConnectionFactory.Close方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: TestCloseDisconnectedHandler

        public void TestCloseDisconnectedHandler()
        {
            bool disconnected = false;
            Object mu = new Object();

            Options o = ConnectionFactory.GetDefaultOptions();
            o.AllowReconnect = false;
            o.DisconnectedEventHandler += (sender, args) => {
                lock (mu)
                {
                    disconnected = true;
                    Monitor.Pulse(mu);
                }
            };

            IConnection c = new ConnectionFactory().CreateConnection(o);
            lock (mu)
            {
                c.Close();
                Monitor.Wait(mu, 20000);
            }
            Assert.IsTrue(disconnected);

            // now test using.
            disconnected = false;
            lock (mu)
            {
                using (c = new ConnectionFactory().CreateConnection(o)) { };
                Monitor.Wait(mu);
            }
            Assert.IsTrue(disconnected);
        }
开发者ID:bendan365,项目名称:csnats-wip,代码行数:32,代码来源:UnitTestConn.cs

示例2: TestConnectionStatus

 public void TestConnectionStatus()
 {
     IConnection c = new ConnectionFactory().CreateConnection();
     Assert.AreEqual(ConnState.CONNECTED, c.State);
     c.Close();
     Assert.AreEqual(ConnState.CLOSED, c.State);
 }
开发者ID:bendan365,项目名称:csnats-wip,代码行数:7,代码来源:UnitTestConn.cs

示例3: connectAndFail

        private void connectAndFail(String url)
        {
            try
            {
                System.Console.WriteLine("Trying: " + url);

                hitDisconnect = 0;
                Options opts = ConnectionFactory.GetDefaultOptions();
                opts.Url = url;
                opts.DisconnectedEventHandler += handleDisconnect;
                IConnection c = new ConnectionFactory().CreateConnection(url);

                Assert.Fail("Expected a failure; did not receive one");
                
                c.Close();
            }
            catch (Exception e)
            {
                if (e.Message.Contains("Authorization"))
                {
                    System.Console.WriteLine("Success with expected failure: " + e.Message);
                }
                else
                {
                    Assert.Fail("Unexpected exception thrown: " + e);
                }
            }
            finally
            {
                if (hitDisconnect > 0)
                    Assert.Fail("The disconnect event handler was incorrectly invoked.");
            }
        }
开发者ID:bendan365,项目名称:csnats-wip,代码行数:33,代码来源:UnitTestAuth.cs

示例4: TestAuthSuccess

 public void TestAuthSuccess()
 {
     using (NATSServer s = util.CreateServerWithConfig(TestContext, "auth_1222.conf"))
     {
         IConnection c = new ConnectionFactory().CreateConnection("nats://username:[email protected]:1222");
         c.Close();
     }
 }
开发者ID:ColinSullivan1,项目名称:csnats,代码行数:8,代码来源:UnitTestAuth.cs

示例5: TestClosedConnections

        public void TestClosedConnections()
        {
            IConnection c = new ConnectionFactory().CreateConnection();
            ISyncSubscription s = c.SubscribeSync("foo");

            c.Close();

            // While we can annotate all the exceptions in the test framework,
            // just do it manually.
            UnitTestUtilities.testExpectedException(
                () => { c.Publish("foo", null); },
                typeof(NATSConnectionClosedException));

            UnitTestUtilities.testExpectedException(
                () => { c.Publish(new Msg("foo")); },
                typeof(NATSConnectionClosedException));

            UnitTestUtilities.testExpectedException(
                () => { c.SubscribeAsync("foo"); },
                typeof(NATSConnectionClosedException));

            UnitTestUtilities.testExpectedException(
                () => { c.SubscribeSync("foo"); },
                typeof(NATSConnectionClosedException));

            UnitTestUtilities.testExpectedException(
                () => { c.SubscribeAsync("foo", "bar"); },
                typeof(NATSConnectionClosedException));

            UnitTestUtilities.testExpectedException(
                () => { c.SubscribeSync("foo", "bar"); },
                typeof(NATSConnectionClosedException));

            UnitTestUtilities.testExpectedException(
                () => { c.Request("foo", null); },
                typeof(NATSConnectionClosedException));

            UnitTestUtilities.testExpectedException(
                () => { s.NextMessage(); },
                typeof(NATSConnectionClosedException));

            UnitTestUtilities.testExpectedException(
                () => { s.NextMessage(100); },
                typeof(NATSConnectionClosedException));

            UnitTestUtilities.testExpectedException(
                () => { s.Unsubscribe(); },
                typeof(NATSConnectionClosedException));

            UnitTestUtilities.testExpectedException(
                () => { s.AutoUnsubscribe(1); },
                typeof(NATSConnectionClosedException));
        }
开发者ID:ColinSullivan1,项目名称:csnats,代码行数:53,代码来源:UnitTestConn.cs

示例6: TestCloseHandler

        public void TestCloseHandler()
        {
            bool closed = false;

            Options o = ConnectionFactory.GetDefaultOptions();
            o.ClosedEventHandler += (sender, args) => { closed = true; };
            IConnection c = new ConnectionFactory().CreateConnection(o);
            c.Close();
            Assert.IsTrue(closed);

            // now test using.
            closed = false;
            using (c = new ConnectionFactory().CreateConnection(o)) { };
            Assert.IsTrue(closed);
        }
开发者ID:bendan365,项目名称:csnats-wip,代码行数:15,代码来源:UnitTestConn.cs

示例7: TestMultipleClose

        public void TestMultipleClose()
        {
            IConnection c = new ConnectionFactory().CreateConnection();
            
            Task[] tasks = new Task[10];

            for (int i = 0; i < 10; i++)
            {

                tasks[i] = new Task(() => { c.Close(); });
                tasks[i].Start();
            }

            Task.WaitAll(tasks);
        }
开发者ID:bendan365,项目名称:csnats-wip,代码行数:15,代码来源:UnitTestBasic.cs

示例8: TestConnectedServer

        public void TestConnectedServer()
        {
            IConnection c = new ConnectionFactory().CreateConnection();
           
            string u = c.ConnectedUrl;
            
            if (string.IsNullOrWhiteSpace(u))
                Assert.Fail("Invalid connected url {0}.", u);
                
            if (!Defaults.Url.Equals(u))
                Assert.Fail("Invalid connected url {0}.", u);

            c.Close();
            u = c.ConnectedUrl;

            if (u != null)
                Assert.Fail("Url is not null after connection is closed.");
        }
开发者ID:bendan365,项目名称:csnats-wip,代码行数:18,代码来源:UnitTestBasic.cs

示例9: NATSServer

 public NATSServer(bool verify)
 {
     createProcessStartInfo();
     p = Process.Start(psInfo);
     if (verify)
     {
         for (int i = 0; i < 10; i++)
         {
             try
             {
                 var c = new ConnectionFactory().CreateConnection();
                 c.Close();
                 break;
             }
             catch
             {
                 Thread.Sleep(i * 250);
             }
         }
     }
 }
开发者ID:nats-io,项目名称:csnats,代码行数:21,代码来源:UnitTestUtilities.cs

示例10: connectAndFail

        private void connectAndFail(String url)
        {
            try
            {
                hitDisconnect = 0;
                Options opts = util.DefaultTestOptions;
                opts.Url = url;
                opts.DisconnectedEventHandler += handleDisconnect;
                IConnection c = new ConnectionFactory().CreateConnection(url);
                Assert.True(false, "Expected a failure; did not receive one");

                c.Close();
            }
            catch (Exception e)
            {
                Assert.True(e.Message.Contains("Authorization"));
            }
            finally
            {
                Assert.False(hitDisconnect > 0, "The disconnect event handler was incorrectly invoked.");
            }
        }
开发者ID:nats-io,项目名称:csnats,代码行数:22,代码来源:UnitTestAuth.cs

示例11: TestServerStopDisconnectedHandler

        public void TestServerStopDisconnectedHandler()
        {
            bool disconnected = false;
            Object mu = new Object();

            Options o = ConnectionFactory.GetDefaultOptions();
            o.AllowReconnect = false;
            o.DisconnectedEventHandler += (sender, args) =>
            {
                lock (mu)
                {
                    disconnected = true;
                    Monitor.Pulse(mu);
                }
            };

            IConnection c = new ConnectionFactory().CreateConnection(o);
            lock (mu)
            {
                utils.bounceDefaultServer(1000);
                Monitor.Wait(mu);
            }
            c.Close();
            Assert.IsTrue(disconnected);
        }
开发者ID:bendan365,项目名称:csnats-wip,代码行数:25,代码来源:UnitTestConn.cs

示例12: TestCloseSubRelease

        public void TestCloseSubRelease()
        {
            using (IConnection c = new ConnectionFactory().CreateConnection())
            {
                using (ISyncSubscription s = c.SubscribeSync("foo"))
                {
                    Stopwatch sw = new Stopwatch();
                    sw.Start();
                    try
                    {
                        new Task(() => { Thread.Sleep(100); c.Close(); }).Start();
                         s.NextMessage(10000);
                    }
                    catch (Exception) { /* ignore */ }

                    sw.Stop();

                    Assert.IsTrue(sw.ElapsedMilliseconds < 10000);
                }
            }
        }
开发者ID:bendan365,项目名称:csnats-wip,代码行数:21,代码来源:UnitTestSub.cs

示例13: TestIsReconnectingAndStatus

        public void TestIsReconnectingAndStatus()
        {
            bool disconnected = false;
            object disconnectedLock = new object();

            bool reconnected = false;
            object reconnectedLock = new object();

            IConnection c = null;

            Options opts = utils.DefaultTestOptions;
            opts.Url = "nats://localhost:22222";
            opts.AllowReconnect = true;
            opts.MaxReconnect = 10000;
            opts.ReconnectWait = 100;

            opts.DisconnectedEventHandler += (sender, args) =>
            {
                lock (disconnectedLock)
                {
                    disconnected = true;
                    Monitor.Pulse(disconnectedLock);
                }
            };

            opts.ReconnectedEventHandler += (sender, args) =>
            {
                lock (reconnectedLock)
                {
                    reconnected = true;
                    Monitor.Pulse(reconnectedLock);
                }
            };

            using (NATSServer s = utils.CreateServerOnPort(22222))
            {
                c = new ConnectionFactory().CreateConnection(opts);

                Assert.True(c.State == ConnState.CONNECTED);
                Assert.True(c.IsReconnecting() == false);
            }
            // server stops here...

            lock (disconnectedLock)
            {
                if (!disconnected)
                    Assert.True(Monitor.Wait(disconnectedLock, 10000));
            }

            Assert.True(c.State == ConnState.RECONNECTING);
            Assert.True(c.IsReconnecting() == true);

            // restart the server
            using (NATSServer s = utils.CreateServerOnPort(22222))
            {
                lock (reconnectedLock)
                {
                    // may have reconnected, if not, wait
                    if (!reconnected)
                        Assert.True(Monitor.Wait(reconnectedLock, 10000));
                }

                Assert.True(c.IsReconnecting() == false);
                Assert.True(c.State == ConnState.CONNECTED);

                c.Close();
            }

            Assert.True(c.IsReconnecting() == false);
            Assert.True(c.State == ConnState.CLOSED);
        }
开发者ID:nats-io,项目名称:csnats,代码行数:71,代码来源:UnitTestReconnect.cs

示例14: 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

示例15: TestCloseAndDispose

 public void TestCloseAndDispose()
 {
     using (IConnection c = new ConnectionFactory().CreateConnection())
     {
         c.Close();
     }
 }
开发者ID:ColinSullivan1,项目名称:csnats,代码行数:7,代码来源:UnitTestBasic.cs


注:本文中的NATS.Client.ConnectionFactory.Close方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。