Beispiel #1
0
        public void TestNoRandomization()
        {
            var opts = ConnectionFactory.GetDefaultOptions();

            opts.Servers     = startUrls;
            opts.NoRandomize = true;

            for (int i = 0; i < 10; i++)
            {
                var sp = new ServerPool();
                sp.Setup(opts);

                var poolUrls = sp.GetServerList(false);
                Assert.True(poolUrls.Length == startUrls.Length);
                Assert.True(poolUrls.SequenceEqual(startUrls));
            }

            for (int i = 0; i < 10; i++)
            {
                var sp = new ServerPool();
                sp.Setup(opts);

                var poolUrls = sp.GetServerList(false);
                Assert.True(poolUrls.Length == startUrls.Length);
                Assert.True(poolUrls.SequenceEqual(startUrls));

                string[] impUrls =
                {
                    "nats://impA:4222", "nats://impB:4222", "nats://impC:4222", "nats://impD:4222",
                    "nats://impE:4222", "nats://impF:4222", "nats://impG:4222", "nats://impH:4222",
                };
                sp.Add(impUrls, true);
                Assert.True(poolUrls.SequenceEqual(startUrls));
            }
        }
Beispiel #2
0
        public void TestIdempotency()
        {
            var opts = ConnectionFactory.GetDefaultOptions();

            opts.Servers = startUrls;

            var sp = new ServerPool();

            sp.Setup(opts);

            var poolUrls = sp.GetServerList(false);

            Assert.True(poolUrls.Length == startUrls.Length);

            sp.Add(startUrls, true);
            Assert.True(poolUrls.Length == startUrls.Length);
        }
Beispiel #3
0
        public void TestImplicitRandomization()
        {
            var opts = ConnectionFactory.GetDefaultOptions();

            opts.Url     = null;
            opts.Servers = startUrls;

            var sp = new ServerPool();

            sp.Setup(opts);

            string[] impUrls =
            {
                "nats://impA:4222", "nats://impB:4222", "nats://impC:4222", "nats://impD:4222",
                "nats://impE:4222", "nats://impF:4222", "nats://impG:4222", "nats://impH:4222",
            };
            sp.Add(impUrls, true);

            var poolUrls = sp.GetServerList(false);

            // Ensure length is OK and that we have randomized the list
            Assert.True(poolUrls.Length == startUrls.Length + impUrls.Length);
            Assert.False(poolUrls.SequenceEqual(startUrls));

            // Ensure implicit urls aren't placed at the end of the list.
            int i;

            for (i = 0; i < startUrls.Length; i++)
            {
                if (poolUrls[i].Contains("imp"))
                {
                    break;
                }
            }
            Assert.True(i != startUrls.Length);
        }
Beispiel #4
0
 public void Post([FromBody] string value, [FromServices] ServerPool servers)
 {
     servers.Add("http://localhost:" + value);
 }