Esempio n. 1
0
        public void MultiThreadDispense()
        {
            IdDispenser id = new IdDispenser();
            List<Thread> threads = new List<Thread>();

            for (int i = 0; i < 5; i++)
            {
                var t = new Thread(() =>
                {
                    for (int j = 0; j < 1000; j++)
                    {
                        var _id = id.next;
                    }
                });
                t.Start();
                threads.Add(t);
            }
            foreach (var thread in threads)
            {
                thread.Join();
            }

            Assert.AreEqual(
                5001,
                id.next);
        }
Esempio n. 2
0
        public Cluster(Server parent)
        {
            var config = (Config)parent.config.Clone();

            config.enableCluster = false;
            config.enableDB = false;
            config.port = config.clusterPort;
            config.sessionType = typeof(Cluster.Session);

            this.parent = parent;
            this.server = new Server(config);
            this.server.cluster = this;
            this.dispenser = new IdDispenser();

            this.peers = new Dictionary<int, Peer>();
            this.pendings = new Dictionary<int, RequestInfo>();

            int idx = 0;
            foreach(var peer in config.clusterPeers)
            {
                this.peers[idx++] = new Peer(this, peer.Item1, peer.Item2);
            }
        }