コード例 #1
0
        public void TestServerDiscoveredHandler()
        {
            IConnection       c  = null;
            ConnectionFactory cf = new ConnectionFactory();
            Options           o  = utils.DefaultTestOptions;

            o.NoRandomize = true;
            o.Servers     = testServers;

            bool serverDiscoveredCalled = false;

            o.ServerDiscoveredEventHandler += (sender, e) =>
            {
                serverDiscoveredCalled = true;
            };

            string seedServerArgs          = @"-p 1222 -cluster nats://127.0.0.1:1333";
            string secondClusterMemberArgs = @"-p 1223 -cluster nats://127.0.0.1:1334 -routes nats://127.0.0.1:1333";

            // create the seed server for a cluster...
            using (NATSServer ns1 = utils.CreateServerWithArgs(seedServerArgs))
            {
                // ...then connect to it...
                using (c = cf.CreateConnection(o))
                {
                    Assert.Equal(testServers[0], c.ConnectedUrl);

                    // ...then while connected, start up a second server...
                    using (NATSServer ns2 = utils.CreateServerWithArgs(secondClusterMemberArgs))
                    {
                        // ...waiting up to 30 seconds for the second server to start...
                        for (int ii = 0; ii < 6; ii++)
                        {
                            Thread.Sleep(5000);

                            // ...taking an early out if we detected the startup...
                            if (serverDiscoveredCalled)
                            {
                                break;
                            }
                        }

                        // ...and by then we should have received notification of
                        // its awakening.
                        Assert.True(serverDiscoveredCalled);
                    }
                }
            }
        }
コード例 #2
0
        public void TestAuthToken()
        {
            using (NATSServer s = util.CreateServerWithArgs("-auth S3Cr3T0k3n!"))
            {
                connectAndFail("nats://*****:*****@localhost:4222");

                new ConnectionFactory().CreateConnection("nats://S3Cr3T0k3n!@localhost:4222").Close();
            }
        }