Beispiel #1
0
        static void BullInsertTest(DBCollection cl)
        {
            int times    = 1;
            int bulkSize = 5000;

            for (int i = 0; i < times; i++)
            {
                List <BsonDocument> list = new List <BsonDocument>(bulkSize);
                for (int j = 0; j < bulkSize; j++)
                {
                    BsonDocument obj = new BsonDocument();
                    obj.Add("bbs", "725").
                    Add("csbh", 1817).
                    Add("cljg", "工作状态").
                    Add("sjym", "79H").
                    Add("wxbs", "WX1558").
                    Add("dmzbs", "DMZ2206").
                    Add("cxbz", 0).
                    Add("sjsj", new DateTime()).
                    Add("rksj", new DateTime());
                    list.Add(obj);
                }
                DateTime beginTime = DateTime.Now;
                cl.BulkInsert(list, 0);
                DateTime        endTime = DateTime.Now;
                System.TimeSpan takes   = endTime - beginTime;
                Console.WriteLine(String.Format("Times: {0}, tasks: {1}ms", i, takes.TotalMilliseconds));
            }
        }
        public void BulkInsertTest()
        {
            long count = 0;
            List <BsonDocument> insertor = new List <BsonDocument>();

            /// default
            for (int i = 0; i < 10; i++)
            {
                BsonDocument obj = new BsonDocument();
                obj.Add("operation", "BulkInsert");
                obj.Add("date", DateTime.Now.ToString());
                insertor.Add(obj);
            }
            coll.BulkInsert(insertor, 0);
            BsonDocument condition = new BsonDocument();

            condition.Add("operation", "BulkInsert");
            count = coll.GetCount(condition);
            Assert.IsTrue(count == 10);

            /// set EnsureOID to be false
            insertor.Clear();
            coll.EnsureOID = false;
            for (int i = 0; i < 10; i++)
            {
                BsonDocument obj = new BsonDocument();
                obj.Add("operation", "BulkInsert");
                obj.Add("date", DateTime.Now.ToString());
                insertor.Add(obj);
            }
            coll.BulkInsert(insertor, 0);
            count = coll.GetCount(condition);
            Assert.IsTrue(count == 20);
            /// set EnsureOID to be true
            insertor.Clear();
            coll.EnsureOID = true;
            for (int i = 0; i < 10; i++)
            {
                BsonDocument obj = new BsonDocument();
                obj.Add("operation", "BulkInsert");
                obj.Add("date", DateTime.Now.ToString());
                insertor.Add(obj);
            }
            coll.BulkInsert(insertor, 0);
            count = coll.GetCount(condition);
            Assert.IsTrue(count == 30);
        }
Beispiel #3
0
        public static void Main(string[] args)
        {
            if (args.Length != 1)
            {
                Console.WriteLine("Please give the database server address <IP:Port>");
                Environment.Exit(0);
            }

            // The database server address
            string sdbIP = args[0];
            // The collection space name
            string csName = "SAMPLE";
            // The collection name
            string cName = "employee";

            List <BsonDocument> insertor = new List <BsonDocument>
            {
                CreateEnglisthRecord(),
                CreateChineseRecord(),
            };

            Sequoiadb sdb = new Sequoiadb(sdbIP);

            Common.Connect(sdb);
            CollectionSpace cs  = Common.GetCollecitonSpace(sdb, csName);
            DBCollection    dbc = Common.GetColleciton(cs, cName);

            try
            {
                dbc.BulkInsert(insertor, SDBConst.FLG_INSERT_CONTONDUP);
            }
            catch (BaseException e)
            {
                Console.WriteLine("Failed to insert records, ErrorType = {0}", e.ErrorType);
                Environment.Exit(0);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                Environment.Exit(0);
            }

            Console.WriteLine("Successfully inserted records into database");
            Common.Disconnect(sdb);
        }
Beispiel #4
0
        public void BulkInsertTest()
        {
            List <BsonDocument> insertor = new List <BsonDocument>();

            for (int i = 0; i < 10; i++)
            {
                BsonDocument obj = new BsonDocument();
                obj.Add("operation", "BulkInsert");
                obj.Add("date", DateTime.Now.ToString());
                insertor.Add(obj);
            }
            coll.BulkInsert(insertor, 0);
            BsonDocument condition = new BsonDocument();

            condition.Add("operation", "BulkInsert");
            long count = coll.GetCount(condition);

            Assert.IsTrue(count == 10);
        }
Beispiel #5
0
        public void setSessionAttrTest()
        {
            // create another node
            string       host      = "192.168.20.42";
            int          port      = 55555;
            string       dataPath  = "/opt/sequoiadb/database/data/55555";
            string       groupName = "group1";
            ReplicaGroup rg        = null;

            try
            {
                // get the exist group
                rg = sdb.GetReplicaGroup(groupName);
                // remove the node we going to use
                SequoiaDB.Node node = rg.GetNode(host, port);
                if (node != null)
                {
                    rg.RemoveNode(host, port, new BsonDocument());
                }
                // create node
                Dictionary <string, string> opt = new Dictionary <string, string>();
                rg.CreateNode(host, port, dataPath, opt);
                rg.Start();
                // insert some records first
                int num = 10;
                List <BsonDocument> insertor = new List <BsonDocument>();
                for (int i = 0; i < num; i++)
                {
                    BsonDocument obj = new BsonDocument();
                    obj.Add("id", i);
                    insertor.Add(obj);
                }
                coll.BulkInsert(insertor, 0);
                // begin a new session
                Sequoiadb sdb2 = new Sequoiadb(config.conf.Coord.Address);
                sdb2.Connect(config.conf.UserName, config.conf.Password);
                Assert.IsNotNull(sdb2.Connection);
                // TODO:
                BsonDocument conf = new BsonDocument("PreferedInstance", "m");
                sdb2.SetSessionAttr(conf);
                // check
                // record the slave note "TotalDataRead" before query
                Sequoiadb sddb = new Sequoiadb(host, port);
                sddb.Connect(config.conf.UserName, config.conf.Password);
                DBCursor     cur1    = sddb.GetSnapshot(6, null, null, null);
                BsonDocument status1 = cur1.Next();
                long         count1  = status1.GetValue("TotalDataRead").AsInt64;
                // query
                DBCursor     cursor = coll.Query(null, null, null, null, 0, -1);
                BsonDocument o      = new BsonDocument();
                long         count  = 0;
                while ((o = cursor.Next()) != null)
                {
                    count++;
                }
                // record the slave note "TotalRead" after query
                DBCursor     cur2    = sddb.GetSnapshot(6, null, null, null);
                BsonDocument status2 = cur2.Next();
                long         count2  = status2.GetValue("TotalDataRead").AsInt64;
                //Assert.IsTrue(num == count2 - count1);
                long temp = count2 - count1;
                Console.WriteLine("count2 is " + count2 + ", count1 is " + count1);
                DBCursor     cur3    = sddb.GetSnapshot(6, null, null, null);
                BsonDocument status3 = cur3.Next();
                long         count3  = status3.GetValue("TotalRead").AsInt64;
            }
            finally
            {
                // remove the newly build node
                SequoiaDB.Node node = rg.GetNode(host, port);
                if (node != null)
                {
                    rg.RemoveNode(host, port, new BsonDocument());
                }
            }
        }
        public void GetQueryMetaTest()
        {
            try{
                // create cl
                DBCollection coll2  = null;
                string       cName2 = "testbar2";
                if (cs.IsCollectionExist(cName2))
                {
                    cs.DropCollection(cName);
                }
                coll2 = cs.CreateCollection(cName2);
                // create index
                coll2.CreateIndex("ageIndex", new BsonDocument("age", -1), false, false);
                // prepare record
                Random ro                    = new Random();
                int    recordNum             = 10000;
                List <BsonDocument> insertor = new List <BsonDocument>();
                for (int i = 0; i < recordNum; i++)
                {
                    BsonDocument obj = new BsonDocument();
                    obj.Add("Id", i);
                    obj.Add("age", ro.Next(0, 100));
                    obj.Add("date", DateTime.Now.ToString());
                    insertor.Add(obj);
                }
                coll2.BulkInsert(insertor, 0);

                // TODO:

                // query
                BsonDocument subobj = new BsonDocument();
                BsonDocument query  = new BsonDocument();
                query.Add("age", subobj);
                subobj.Add("$gt", 1);
                subobj.Add("$lt", 99);
                // hint
                BsonDocument hint = new BsonDocument();
                hint.Add("", "ageIndex");
                // orderBy
                BsonDocument orderBy = new BsonDocument();
                orderBy.Add("Indexblocks", 1);
                // execute getQueryMeta
                DBCursor cursor     = coll2.GetQueryMeta(query, orderBy, null, 0, -1);
                DBCursor datacursor = null;
                long     count      = 0;
                while (cursor.Next() != null)
                {
                    BsonDocument temp = new BsonDocument();
                    temp = cursor.Current();
                    BsonDocument h = new BsonDocument();
                    if (temp.Contains("Indexblocks") && temp["Indexblocks"].IsBsonArray)
                    {
                        h.Add("Indexblocks", temp["Indexblocks"].AsBsonArray);
                    }
                    datacursor = coll2.Query(null, null, null, h, 0, -1);
                    while (datacursor.Next() != null)
                    {
                        count++;
                    }
                }
                Assert.IsTrue(recordNum == count);
            }catch (BaseException e)
            {
                Console.WriteLine(e.ErrorType);
                return;
            }
        }