Esempio n. 1
0
        public void TestServersOption()
        {
            IConnection       c  = null;
            ConnectionFactory cf = new ConnectionFactory();
            Options           o  = utils.DefaultTestOptions;

            o.NoRandomize = true;

            Assert.ThrowsAny <NATSNoServersException>(() => cf.CreateConnection());

            o.Servers = testServers;

            Assert.ThrowsAny <NATSNoServersException>(() => cf.CreateConnection(o));

            // Make sure we can connect to first server if running
            using (NATSServer ns = utils.CreateServerOnPort(1222))
            {
                c = cf.CreateConnection(o);
                Assert.Equal(testServers[0], c.ConnectedUrl);
                c.Close();
            }

            // make sure we can connect to a non-first server.
            using (NATSServer ns = utils.CreateServerOnPort(1227))
            {
                c = cf.CreateConnection(o);
                Assert.Equal(testServers[5], c.ConnectedUrl);
                c.Close();
            }
        }
Esempio n. 2
0
        public void TestReconnectDisallowedFlags()
        {
            Options opts = utils.DefaultTestOptions;

            opts.Url            = "nats://localhost:22222";
            opts.AllowReconnect = false;

            Object testLock = new Object();

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

            using (NATSServer ns = utils.CreateServerOnPort(22222))
            {
                using (IConnection c = new ConnectionFactory().CreateConnection(opts))
                {
                    lock (testLock)
                    {
                        ns.Shutdown();
                        Assert.True(Monitor.Wait(testLock, 1000));
                    }
                }
            }
        }