예제 #1
0
        // This method connects to two servers, and attempts to send
        // messages through them for a number of iterations over a timeout.
        // If a message has been received, we know there is connectivity
        // (a route) between the url1 and url2 server endpoints.
        private bool waitForRoute(TestServerInfo serverInfo1, TestServerInfo serverInfo2, int timeout)
        {
            AutoResetEvent ev = new AutoResetEvent(false);
            bool           routeEstablished = false;

            // create conn 1
            var opts1 = Context.GetNatsTestOptions(serverInfo1);

            opts1.AllowReconnect = false;

            using (var nc1 = Context.GetNatsConnection(opts1))
            {
                // create conn 2, wait for a message
                var opts2 = Context.GetNatsTestOptions(serverInfo2);
                opts1.AllowReconnect = false;

                using (var nc2 = Context.GetNatsConnection(opts2))
                {
                    nc2.SubscribeAsync("routecheck", (obj, args) => { ev.Set(); });
                    nc2.Flush();

                    for (int i = 0; i < 10 && routeEstablished == false; i++)
                    {
                        nc1.Publish("routecheck", null);
                        nc1.Flush();
                        routeEstablished = ev.WaitOne(timeout / 10);
                    }

                    nc1.Close();
                    nc2.Close();
                }
            }

            return(routeEstablished);
        }
예제 #2
0
        public Options GetNatsTestOptions(TestServerInfo serverInfo)
        {
            var opts = ConnectionFactory.GetDefaultOptions();

            opts.Url = serverInfo.Url;

            return(opts);
        }
예제 #3
0
        public Options GetNatsTestOptions(TestServerInfo serverInfo)
        {
            var opts = ConnectionFactory.GetDefaultOptions();

            opts.Url = serverInfo.Url;
            opts.ReconnectBufferSize = Options.ReconnectBufferDisabled;

            return(opts);
        }
예제 #4
0
        public StanOptions GetStanTestOptions(TestServerInfo serverInfo, int timeout = 5000)
        {
            var opts = StanOptions.GetDefaultOptions();

            opts.NatsURL        = serverInfo.Url;
            opts.ConnectTimeout = timeout;

            return(opts);
        }
예제 #5
0
 public void RunInServer(TestServerInfo testServerInfo, Action <IConnection> test)
 {
     using (var s = NATSServer.CreateFastAndVerify(testServerInfo.Port))
     {
         using (var c = OpenConnection(testServerInfo.Port))
         {
             test(c);
         }
     }
 }
예제 #6
0
        protected static bool IsRunning(TestServerInfo serverInfo)
        {
            try
            {
                using (var cn = new ConnectionFactory().CreateConnection(serverInfo.Url))
                {
                    cn.Close();

                    return(true);
                }
            }
            catch
            {
                return(false);
            }
        }
예제 #7
0
 public void RunInJsServer(TestServerInfo testServerInfo, Action <Options> optionsModifier, Action <IConnection> test)
 {
     using (var s = NATSServer.CreateJetStreamFastAndVerify(testServerInfo.Port, optionsModifier))
     {
         using (var c = OpenConnection(testServerInfo.Port, optionsModifier))
         {
             try
             {
                 test(c);
             }
             finally
             {
                 cleanupJs(c);
             }
         }
     }
 }
예제 #8
0
        protected static bool IsRunning(TestServerInfo serverInfo)
        {
            try
            {
                var opts = ConnectionFactory.GetDefaultOptions();
                opts.Url = serverInfo.Url;
                opts.ReconnectBufferSize = Options.ReconnectBufferDisabled;

                using (var cn = new ConnectionFactory().CreateConnection(opts))
                {
                    cn.Close();

                    return(true);
                }
            }
            catch
            {
                return(false);
            }
        }
예제 #9
0
 public OneServerSuiteContext()
 {
     Server1 = new TestServerInfo(TestSeedPorts.AutoPort.Increment());
 }
예제 #10
0
 public NatsServer StartNatsServer(TestServerInfo serverInfo, string args = null)
 => NatsServer.Start(serverInfo, args);
예제 #11
0
 public NatsStreamingServer StartStreamingServerWithExternal(TestServerInfo serverInfo, string args = null)
 => NatsStreamingServer.StartWithExternal(serverInfo, ClusterId, args);
예제 #12
0
 public IConnection GetNatsConnection(TestServerInfo serverInfo) => NatsConnectionFactory.CreateConnection(GetNatsTestOptions(serverInfo));
예제 #13
0
 public IStanConnection GetStanConnection(TestServerInfo serverInfo, string clusterId = null, string clientId = null)
 => StanConnectionFactory.CreateConnection(clusterId ?? ClusterId, clientId ?? ClientId, GetStanTestOptions(serverInfo));