示例#1
0
        public void HandShakeAcceptMoar()
        {
            var dic = new Dictionary <string, string>();

            string pass = DistCacheConfigBase.GenerateRandomPassword();

            var serverConfig = new DistCacheServerConfig()
            {
                Password = pass
            };

            int toAdd = 16;
            int iters = 2;

            using (var srv = new CacheServer(serverConfig))
            {
                var clientscon = new ConcurrentBag <DistCacheClient>();

                for (int k = 0; k < iters; ++k)
                {
                    List <Task <DistCacheClient> > clients = new List <Task <DistCacheClient> >();
                    var ls = new List <DistCacheClient>();

                    for (int i = 0; i < toAdd; ++i)
                    {
                        clients.Add(new Task <DistCacheClient>(() =>
                        {
                            var o = DistCacheClient.Create(new DistCacheClientConfig()
                            {
                                Password = pass
                            });
                            clientscon.Add(o);
                            return(o);
                        }));
                        clients.Last().Start();
                    }

                    Task.WaitAll(clients.ToArray());
                }
                while (srv.PendingClientsCount > 0)
                {
                    Thread.Sleep(500);
                }
                Assert.AreEqual(toAdd * iters, srv.ConnectedClientsCount);
            }
        }
示例#2
0
        public static void Main(string[] args)
        {
            var dic = new Dictionary <string, string>();

            string pass = DistCacheConfigBase.GenerateRandomPassword();

            var serverConfig = new DistCacheServerConfig()
            {
                Password = pass
            };

            using (var srv = new CacheServer(serverConfig))
            {
                int clients = 1;
                int msgs    = 50000;

                var ls = new ConcurrentBag <DistCacheClient>();

                for (int k = 0; k < clients; ++k)
                {
                    var client = DistCacheClient.Create(new DistCacheClientConfig()
                    {
                        Password = pass
                    });
                    ls.Add(client);
                }

                Stopwatch sw  = Stopwatch.StartNew();
                long      cnt = 0;
                for (int i = 0; i < msgs; ++i)
                {
                    foreach (var cl in ls)
                    {
                        string s = cl.GetMessage($"{Interlocked.Increment(ref cnt)}").Result;
                    }
                }
                string ss = "";
                while (ss != "q")
                {
                    Console.WriteLine($"got {Interlocked.Read(ref cnt)} {sw.Elapsed}");
                    ss = Console.ReadLine();
                }
            }
        }
示例#3
0
        public void HandShakeAccept()
        {
            var dic = new Dictionary <string, string>();

            string pass = DistCacheConfigBase.GenerateRandomPassword();

            var serverConfig = new DistCacheServerConfig()
            {
                Password = pass
            };

            using (var srv = new CacheServer(serverConfig))
            {
                var ls     = new List <DistCacheClient>();
                var client = DistCacheClient.Create(new DistCacheClientConfig()
                {
                    Password = pass
                });
                Thread.Sleep(1000);
                Assert.IsTrue(srv.ConnectedClientsCount == 1);
            }
        }