本文整理汇总了C#中NATS.Client.ConnectionFactory.IsClosed方法的典型用法代码示例。如果您正苦于以下问题:C# ConnectionFactory.IsClosed方法的具体用法?C# ConnectionFactory.IsClosed怎么用?C# ConnectionFactory.IsClosed使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NATS.Client.ConnectionFactory
的用法示例。
在下文中一共展示了ConnectionFactory.IsClosed方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestTimeoutOnNoServers
public void TestTimeoutOnNoServers()
{
Options opts = ConnectionFactory.GetDefaultOptions();
Object dmu = new Object();
Object cmu = new Object();
opts.Servers = testServersShortList;
opts.NoRandomize = true;
opts.MaxReconnect = 2;
opts.ReconnectWait = 100; // millis
bool disconnectHandlerCalled = false;
bool closedHandlerCalled = false;
opts.DisconnectedEventHandler = (sender, args) =>
{
lock (dmu)
{
disconnectHandlerCalled = true;
Monitor.Pulse(dmu);
}
};
opts.ClosedEventHandler = (sender, args) =>
{
lock (cmu)
{
closedHandlerCalled = true;
Monitor.Pulse(cmu);
}
};
using (NATSServer s1 = utils.CreateServerOnPort(1222))
{
using (IConnection c = new ConnectionFactory().CreateConnection(opts))
{
s1.Shutdown();
lock (dmu)
{
if (!disconnectHandlerCalled)
Assert.IsTrue(Monitor.Wait(dmu, 20000));
}
Stopwatch sw = new Stopwatch();
sw.Start();
lock (cmu)
{
if (!closedHandlerCalled)
Assert.IsTrue(Monitor.Wait(cmu, 60000));
}
sw.Stop();
int expected = opts.MaxReconnect * opts.ReconnectWait;
// .NET has long connect times, so revisit this after
// a connect timeout has been added.
//Assert.IsTrue(sw.ElapsedMilliseconds < (expected + 500));
Assert.IsTrue(disconnectHandlerCalled);
Assert.IsTrue(closedHandlerCalled);
Assert.IsTrue(c.IsClosed());
}
}
}
示例2: TestProperFalloutAfterMaxAttempts
public void TestProperFalloutAfterMaxAttempts()
{
Options opts = ConnectionFactory.GetDefaultOptions();
Object dmu = new Object();
Object cmu = new Object();
opts.Servers = this.testServersShortList;
opts.NoRandomize = true;
opts.MaxReconnect = 2;
opts.ReconnectWait = 25; // millis
opts.Timeout = 500;
bool disconnectHandlerCalled = false;
opts.DisconnectedEventHandler = (sender, args) =>
{
lock (dmu)
{
disconnectHandlerCalled = true;
Monitor.Pulse(dmu);
}
};
bool closedHandlerCalled = false;
opts.ClosedEventHandler = (sender, args) =>
{
lock (cmu)
{
closedHandlerCalled = true;
Monitor.Pulse(cmu);
}
};
using (NATSServer s1 = utils.CreateServerOnPort(1222))
{
using (IConnection c = new ConnectionFactory().CreateConnection(opts))
{
s1.Shutdown();
lock (dmu)
{
if (!disconnectHandlerCalled)
Assert.IsTrue(Monitor.Wait(dmu, 20000));
}
lock (cmu)
{
if (!closedHandlerCalled)
Assert.IsTrue(Monitor.Wait(cmu, 60000));
}
Assert.IsTrue(disconnectHandlerCalled);
Assert.IsTrue(closedHandlerCalled);
Assert.IsTrue(c.IsClosed());
}
}
}
示例3: TestProperFalloutAfterMaxAttemptsWithAuthMismatch
public void TestProperFalloutAfterMaxAttemptsWithAuthMismatch()
{
Options opts = utils.DefaultTestOptions;
Object dmu = new Object();
Object cmu = new Object();
opts.Servers = new string[] {
"nats://localhost:1220",
"nats://localhost:1222"
};
opts.NoRandomize = true;
opts.MaxReconnect = 2;
opts.ReconnectWait = 25; // millis
opts.Timeout = 1000;
bool disconnectHandlerCalled = false;
opts.DisconnectedEventHandler = (sender, args) =>
{
lock (dmu)
{
disconnectHandlerCalled = true;
Monitor.Pulse(dmu);
}
};
bool closedHandlerCalled = false;
opts.ClosedEventHandler = (sender, args) =>
{
lock (cmu)
{
closedHandlerCalled = true;
Monitor.Pulse(cmu);
}
};
using (NATSServer s1 = utils.CreateServerOnPort(1220),
s2 = utils.CreateServerWithConfig("tls_1222_verify.conf"))
{
using (IConnection c = new ConnectionFactory().CreateConnection(opts))
{
s1.Shutdown();
lock (dmu)
{
if (!disconnectHandlerCalled)
Assert.True(Monitor.Wait(dmu, 20000));
}
lock (cmu)
{
if (!closedHandlerCalled)
Assert.True(Monitor.Wait(cmu, 600000));
}
Assert.True(c.Stats.Reconnects != opts.MaxReconnect);
Assert.True(disconnectHandlerCalled);
Assert.True(closedHandlerCalled);
Assert.True(c.IsClosed());
}
}
}
示例4: TestClose
public void TestClose()
{
Options opts = utils.DefaultTestOptions;
opts.Url = "nats://localhost:22222";
opts.AllowReconnect = true;
opts.MaxReconnect = 60;
using (NATSServer s1 = utils.CreateServerOnPort(22222))
{
IConnection c = new ConnectionFactory().CreateConnection(opts);
Assert.False(c.IsClosed());
s1.Shutdown();
Thread.Sleep(100);
Assert.False(c.IsClosed(), string.Format("Invalid state, expecting not closed, received: {0}", c.State));
using (NATSServer s2 = utils.CreateServerOnPort(22222))
{
Thread.Sleep(1000);
Assert.False(c.IsClosed());
c.Close();
Assert.True(c.IsClosed());
}
}
}
示例5: TestClose
public void TestClose()
{
Options opts = ConnectionFactory.GetDefaultOptions();
opts.Url = "nats://localhost:22222";
opts.AllowReconnect = true;
opts.MaxReconnect = 60;
using (NATSServer s1 = utils.CreateServerOnPort(22222))
{
IConnection c = new ConnectionFactory().CreateConnection(opts);
Assert.IsFalse(c.IsClosed());
s1.Shutdown();
Thread.Sleep(100);
if (c.IsClosed())
{
Assert.Fail("Invalid state, expecting not closed, received: "
+ c.State.ToString());
}
using (NATSServer s2 = utils.CreateServerOnPort(22222))
{
Thread.Sleep(1000);
Assert.IsFalse(c.IsClosed());
c.Close();
Assert.IsTrue(c.IsClosed());
}
}
}