CreateServerOnPort() private method

private CreateServerOnPort ( int p ) : NATSServer
p int
return NATSServer
        public void TestReconnectDisallowedFlags()
        {
            Options opts = ConnectionFactory.GetDefaultOptions();

            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.IsTrue(Monitor.Wait(testLock, 1000));
                    }
                }
            }
        }
Example #2
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.True(testServers[0].Equals(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.True(testServers[5].Equals(c.ConnectedUrl));
                c.Close();
            }
        }
Example #3
0
        public void TestServersOption()
        {
            IConnection       c  = null;
            ConnectionFactory cf = new ConnectionFactory();
            Options           o  = ConnectionFactory.GetDefaultOptions();

            o.NoRandomize = true;

            UnitTestUtilities.testExpectedException(
                () => { cf.CreateConnection(); },
                typeof(NATSNoServersException));

            o.Servers = testServers;

            UnitTestUtilities.testExpectedException(
                () => { cf.CreateConnection(o); },
                typeof(NATSNoServersException));

            // Make sure we can connect to first server if running
            using (NATSServer ns = utils.CreateServerOnPort(1222))
            {
                c = cf.CreateConnection(o);
                Assert.IsTrue(testServers[0].Equals(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.IsTrue(testServers[5].Equals(c.ConnectedUrl));
                c.Close();
            }
        }