Exemple #1
0
        public void TestMultiThreadedReadsAndWrites()
        {
            Mongo db = new Mongo();

            db.Connect();

            IMongoCollection col = db["tests"]["threadreadinserts"];

            List <string> identifiers = new List <string> {
                "A", "B", "C", "D"
            };
            List <string> colnames = new List <string> {
                "smallreads", "smallreads", "smallreads", "smallreads"
            };
            List <Thread> threads         = new List <Thread>();
            List <Reader> readers         = new List <Reader>();
            int           writeiterations = 100;
            int           readiterations  = 50;

            foreach (string identifier in identifiers)
            {
                Inserter ins = new Inserter {
                    Iterations = writeiterations, Identifier = identifier, Collection = col
                };
                ThreadStart ts     = new ThreadStart(ins.DoInserts);
                Thread      thread = new Thread(ts);
                threads.Add(thread);
            }
            foreach (string colname in colnames)
            {
                Reader r = new Reader {
                    Iterations = readiterations, Collection = db["tests"][colname]
                };
                readers.Add(r);
                ThreadStart ts     = new ThreadStart(r.DoReads);
                Thread      thread = new Thread(ts);
                threads.Add(thread);
            }

            RunAndWait(threads);
            try{
                Assert.AreEqual(identifiers.Count * writeiterations, col.Count());
            }catch (Exception e) {
                Assert.Fail(e.Message);
            }
            foreach (Reader r in readers)
            {
                Assert.AreEqual(readiterations, r.Count, "A reader did not read everytime.");
            }
        }
        //[Test]
        public void TestMultiThreadedWrites()
        {
            Mongo db = new Mongo();
            db.Connect();

            IMongoCollection col = db["tests"]["threadinserts"];

            List<string> identifiers = new List<string>{"A", "B", "C", "D"};
            List<Thread> threads = new List<Thread>();
            int iterations = 100;

            foreach(string identifier in identifiers){
                Inserter ins = new Inserter {Iterations = iterations, Identifier = identifier, Collection = col};
                ThreadStart ts = new ThreadStart(ins.DoInserts);
                Thread thread = new Thread(ts);
                threads.Add(thread);
            }

            RunAndWait(threads);

            try{
                Assert.AreEqual(identifiers.Count * iterations, col.Count());
            }catch(Exception e){
                Assert.Fail(e.Message);
            }
        }
        public void TestMultiThreadedReadsAndWrites()
        {
            Mongo db = new Mongo();
            db.Connect();

            IMongoCollection col = db["tests"]["threadreadinserts"];

            List<string> identifiers = new List<string>{"A", "B", "C", "D"};
            List<string> colnames = new List<string>{"smallreads", "smallreads", "smallreads", "smallreads"};
            List<Thread> threads = new List<Thread>();
            List<Reader> readers = new List<Reader>();
            int writeiterations = 100;
            int readiterations = 50;
            foreach(string identifier in identifiers){
                Inserter ins = new Inserter {Iterations = writeiterations, Identifier = identifier, Collection = col};
                ThreadStart ts = new ThreadStart(ins.DoInserts);
                Thread thread = new Thread(ts);
                threads.Add(thread);
            }
            foreach(string colname in colnames){
                Reader r = new Reader{Iterations = readiterations, Collection = db["tests"][colname]};
                readers.Add(r);
                ThreadStart ts = new ThreadStart(r.DoReads);
                Thread thread = new Thread(ts);
                threads.Add(thread);
            }

            RunAndWait(threads);
            try{
                Assert.AreEqual(identifiers.Count * writeiterations, col.Count());
            }catch(Exception e){
                Assert.Fail(e.Message);
            }
            foreach(Reader r in readers){
                Assert.AreEqual(readiterations, r.Count, "A reader did not read everytime.");
            }
        }