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)); } }
public void TestDefault() { var sp = new ServerPool(); sp.Setup(new Options()); var poolUrls = sp.GetServerList(false); Assert.True(poolUrls.Length == 1); Assert.Equal(poolUrls[0], Defaults.Url); }
public void TestBasicRandomization() { var opts = ConnectionFactory.GetDefaultOptions(); opts.Servers = 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.False(poolUrls.SequenceEqual(startUrls)); } }
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); }
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); }