本文整理汇总了C#中ConcurrentDictionary.PrintDump方法的典型用法代码示例。如果您正苦于以下问题:C# ConcurrentDictionary.PrintDump方法的具体用法?C# ConcurrentDictionary.PrintDump怎么用?C# ConcurrentDictionary.PrintDump使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ConcurrentDictionary
的用法示例。
在下文中一共展示了ConcurrentDictionary.PrintDump方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Can_handle_multiple_rpc_clients
public void Can_handle_multiple_rpc_clients()
{
int NoOfClients = 10;
int TimeMs = 5000;
var errors = new ConcurrentDictionary<long, string>();
using (var mqServer = CreateMqServer())
{
mqServer.RegisterHandler<Incr>(m =>
new IncrResponse { Result = m.GetBody().Value + 1 });
mqServer.Start();
long counter = 0;
int activeClients = 0;
var activeClientsLock = new object();
NoOfClients.Times(() => {
ThreadPool.QueueUserWorkItem(_ => {
using (var mqClient = mqServer.CreateMessageQueueClient())
{
var sw = Stopwatch.StartNew();
var clientId = Interlocked.Increment(ref activeClients);
while (sw.ElapsedMilliseconds < TimeMs)
{
var next = Interlocked.Increment(ref counter);
try
{
var replyToMq = mqClient.GetTempQueueName();
mqClient.Publish(new Message<Incr>(new Incr { Value = next })
{
ReplyTo = replyToMq
});
var responseMsg = mqClient.Get<IncrResponse>(replyToMq, TimeSpan.FromMilliseconds(TimeMs));
mqClient.Ack(responseMsg);
var actual = responseMsg.GetBody().Result;
var expected = next + 1;
if (actual != expected)
{
errors[next] = string.Format("Actual: {1}, Expected: {0}",
actual, expected);
}
}
catch (Exception ex)
{
errors[next] = ex.Message + "\nStackTrace:\n" + ex.StackTrace;
}
}
"Client {0} finished".Print(clientId);
if (Interlocked.Decrement(ref activeClients) == 0)
{
"All Clients Finished".Print();
lock (activeClientsLock)
Monitor.Pulse(activeClientsLock);
}
}
});
});
lock (activeClientsLock)
Monitor.Wait(activeClientsLock);
"Stopping Server...".Print();
"Requests: {0}".Print(counter);
errors.PrintDump();
}
Assert.That(errors.Count, Is.EqualTo(0));
}