// 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); }
public Options GetNatsTestOptions(TestServerInfo serverInfo) { var opts = ConnectionFactory.GetDefaultOptions(); opts.Url = serverInfo.Url; return(opts); }
public Options GetNatsTestOptions(TestServerInfo serverInfo) { var opts = ConnectionFactory.GetDefaultOptions(); opts.Url = serverInfo.Url; opts.ReconnectBufferSize = Options.ReconnectBufferDisabled; return(opts); }
public StanOptions GetStanTestOptions(TestServerInfo serverInfo, int timeout = 5000) { var opts = StanOptions.GetDefaultOptions(); opts.NatsURL = serverInfo.Url; opts.ConnectTimeout = timeout; return(opts); }
public void RunInServer(TestServerInfo testServerInfo, Action <IConnection> test) { using (var s = NATSServer.CreateFastAndVerify(testServerInfo.Port)) { using (var c = OpenConnection(testServerInfo.Port)) { test(c); } } }
protected static bool IsRunning(TestServerInfo serverInfo) { try { using (var cn = new ConnectionFactory().CreateConnection(serverInfo.Url)) { cn.Close(); return(true); } } catch { return(false); } }
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); } } } }
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); } }
public OneServerSuiteContext() { Server1 = new TestServerInfo(TestSeedPorts.AutoPort.Increment()); }
public NatsServer StartNatsServer(TestServerInfo serverInfo, string args = null) => NatsServer.Start(serverInfo, args);
public NatsStreamingServer StartStreamingServerWithExternal(TestServerInfo serverInfo, string args = null) => NatsStreamingServer.StartWithExternal(serverInfo, ClusterId, args);
public IConnection GetNatsConnection(TestServerInfo serverInfo) => NatsConnectionFactory.CreateConnection(GetNatsTestOptions(serverInfo));
public IStanConnection GetStanConnection(TestServerInfo serverInfo, string clusterId = null, string clientId = null) => StanConnectionFactory.CreateConnection(clusterId ?? ClusterId, clientId ?? ClientId, GetStanTestOptions(serverInfo));