public void CollectionTest()
        {
            string          csName = "testCS1";
            string          clName = "testCL1";
            CollectionSpace cs     = null;
            Sequoiadb       sdb    = new Sequoiadb(config.conf.Coord.Address);

            sdb.Connect(config.conf.UserName, config.conf.Password);
            if (sdb.IsCollectionSpaceExist(csName))
            {
                cs = sdb.GetCollecitonSpace(csName);
            }
            else
            {
                cs = sdb.CreateCollectionSpace(csName);
            }
            if (!cs.IsCollectionExist(clName))
            {
                cs.CreateCollection(clName);
            }
            cs.DropCollection(clName);
            Assert.IsFalse(cs.IsCollectionExist(clName));
            sdb.DropCollectionSpace(csName);
            sdb.Disconnect();
        }
示例#2
0
        public void ConnectWithSSLTest()
        {
            ConfigOptions   cfgOpt = null;
            CollectionSpace cs2    = null;
            DBCollection    coll2  = null;
            Sequoiadb       sdb2   = new Sequoiadb(config.conf.Coord.Address);

            System.Console.WriteLine(config.conf.Coord.Address.ToString());

            // set connect using ssl
            cfgOpt        = new ConfigOptions();
            cfgOpt.UseSSL = true;

            // connect to database
            sdb2.Connect("", "", cfgOpt);
            if (true == sdb2.IsCollectionSpaceExist("testSSL"))
            {
                cs2 = sdb2.GetCollecitonSpace("testSSL");
            }
            else
            {
                cs2 = sdb2.CreateCollectionSpace("testSSL");
            }
            if (true == cs2.IsCollectionExist("testSSL"))
            {
                coll2 = cs2.GetCollection("testSSL");
            }
            else
            {
                coll2 = cs2.CreateCollection("testSSL");
            }

            sdb2.DropCollectionSpace("testSSL");
        }
示例#3
0
        /// <summary>
        /// 简单测试。
        /// </summary>
        /// <param name="sdb"></param>
        static void Test1(Sequoiadb sdb)
        {
            if (sdb.IsCollectionSpaceExist("dbo"))
            {
                sdb.DropCollectionSpace("dbo");
            }

            var cs   = sdb.CreateCollectionSpace("dbo");
            var coll = cs.CreateCollection("foo");

            // insert
            BsonDocument insertor = new BsonDocument();
            string       date     = DateTime.Now.ToString();

            insertor.Add("operation", "Insert");
            insertor.Add("date", date);
            Object id = (ObjectId)coll.Insert(insertor);

            BsonDocument matcher = new BsonDocument();
            DBQuery      query   = new DBQuery();

            matcher.Add("date", date);
            query.Matcher = matcher;
            DBCursor     cursor = coll.Query(query);
            BsonDocument bson   = cursor.Next();

            System.Console.WriteLine(bson);
            System.Console.ReadLine();
        }
示例#4
0
        public void MyTestInitialize()
        {
            csArr[0]  = csName1;
            csArr[1]  = csName2;
            csArr[2]  = csName3;
            clArr1[0] = clName1_1;
            clArr1[1] = clName1_2;
            clArr1[2] = clName1_3;
            clArr2[0] = clName2_1;
            clArr2[1] = clName2_2;
            clArr2[2] = clName2_3;
            clArr3[0] = clName3_1;
            clArr3[1] = clName3_2;
            clArr3[2] = clName3_3;
            sdb       = new Sequoiadb(config.conf.Coord.Address);
            sdb.Connect(config.conf.UserName, config.conf.Password);
            BsonDocument options = new BsonDocument();

            options.Add("ReplSize", 0);
            if (sdb.IsCollectionSpaceExist(csName))
            {
                sdb.DropCollectionSpace(csName);
            }
            cs   = sdb.CreateCollectionSpace(csName);
            coll = cs.CreateCollection(cName, options);
        }
 public void MyTestInitialize()
 {
     sdb = new Sequoiadb(config.conf.Coord.Address);
     sdb.Connect(config.conf.UserName, config.conf.Password);
     if (sdb.IsCollectionSpaceExist(csName))
         sdb.DropCollectionSpace(csName);
     cs = sdb.CreateCollectionSpace(csName);
     coll = cs.CreateCollection(cName);
 }
示例#6
0
 public void MyTestInitialize()
 {
     sdb = new Sequoiadb(config.conf.Coord.Address);
     sdb.Connect(config.conf.UserName, config.conf.Password);
     if (sdb.IsCollectionSpaceExist(csName))
     {
         sdb.DropCollectionSpace(csName);
     }
     cs   = sdb.CreateCollectionSpace(csName);
     coll = cs.CreateCollection(cName);
 }
示例#7
0
        public void MyTestInitialize()
        {
            sdb = new Sequoiadb(config.conf.Coord.Address);
            sdb.Connect(config.conf.UserName, config.conf.Password);
            BsonDocument options = new BsonDocument();

            options.Add("ReplSize", 0);
            if (sdb.IsCollectionSpaceExist(csName))
            {
                sdb.DropCollectionSpace(csName);
            }
            cs   = sdb.CreateCollectionSpace(csName);
            coll = cs.CreateCollection(cName, options);
        }
示例#8
0
 public void MyTestInitialize()
 {
     try
     {
         sdb = new Sequoiadb(config.conf.Coord.Address);
         sdb.Connect(config.conf.UserName, config.conf.Password);
         if (sdb.IsCollectionSpaceExist(csName))
             sdb.DropCollectionSpace(csName);
         cs = sdb.CreateCollectionSpace(csName);
         cl = cs.CreateCollection(cName);
     }
     catch (BaseException e)
     {
         Console.WriteLine("Failed to Initialize in DBLobTest, ErrorType = {0}", e.ErrorType);
         Environment.Exit(0);
     }
 }
 public void CollectionTest()
 {
     string csName = "testCS1";
     string clName = "testCL1";
     CollectionSpace cs = null;
     Sequoiadb sdb = new Sequoiadb(config.conf.Coord.Address);
     sdb.Connect(config.conf.UserName, config.conf.Password);
     if(sdb.IsCollectionSpaceExist(csName))
         cs = sdb.GetCollecitonSpace(csName);
     else
         cs = sdb.CreateCollectionSpace(csName);
     if (!cs.IsCollectionExist(clName))
         cs.CreateCollection(clName);
     cs.DropCollection(clName);
     Assert.IsFalse(cs.IsCollectionExist(clName));
     sdb.DropCollectionSpace(csName);
     sdb.Disconnect();
 }
示例#10
0
 public void MyTestInitialize()
 {
     try
     {
         sdb = new Sequoiadb(config.conf.Coord.Address);
         sdb.Connect(config.conf.UserName, config.conf.Password);
         if (sdb.IsCollectionSpaceExist(csName))
         {
             sdb.DropCollectionSpace(csName);
         }
         cs   = sdb.CreateCollectionSpace(csName);
         coll = cs.CreateCollection(cName);
     }
     catch (BaseException e)
     {
         Console.WriteLine("Failed to Initialize in DBCollectionTest, ErrorType = {0}", e.ErrorType);
         Environment.Exit(0);
     }
 }
示例#11
0
        public void CollectionSpaceTest()
        {
            string       csName  = "Test";
            string       csName2 = "Test2";
            BsonDocument option  = new BsonDocument();

            option.Add(SequoiadbConstants.FIELD_PAGESIZE, 4096);

            if (!sdb.IsCollectionSpaceExist(csName))
            {
                // default and with page size
                sdb.CreateCollectionSpace(csName);
            }
            Assert.IsTrue(sdb.IsCollectionSpaceExist(csName));
            sdb.DropCollectionSpace(csName);
            Assert.IsFalse(sdb.IsCollectionSpaceExist(csName));
            // with options
            sdb.CreateCollectionSpace(csName2, option);
            Assert.IsTrue(sdb.IsCollectionSpaceExist(csName2));
            sdb.DropCollectionSpace(csName2);
            Assert.IsFalse(sdb.IsCollectionSpaceExist(csName2));
        }
示例#12
0
        /// <summary>
        /// Update测试。
        /// </summary>
        /// <param name="sdb"></param>
        static void TestUpdate(Sequoiadb sdb)
        {
            // The collection space name
            string csName = "sample";
            // The collection name
            string cName = "sample";

            // connect
            CollectionSpace cs;

            if (sdb.IsCollectionSpaceExist(csName))
            {
                cs = sdb.GetCollecitonSpace(csName);
            }
            else
            {
                cs = sdb.CreateCollectionSpace(csName);
            }

            DBCollection coll = null;

            if (cs.IsCollectionExist(cName))
            {
                coll = cs.GetCollection(cName);
            }
            else
            {
                coll = cs.CreateCollection(cName);
            }

            // delete all records from the collection
            BsonDocument bson = new BsonDocument();

            coll.Delete(bson);

            String[] record = new String[4];
            record[0] = "{cust_id:\"A123\",amount:500,status:\"A\"}";
            record[1] = "{cust_id:\"A123\",amount:250,status:\"A\"}";
            record[2] = "{cust_id:\"B212\",amount:200,status:\"A\"}";
            record[3] = "{cust_id:\"A123\",amount:300,status:\"D\"}";
            // insert record into database
            for (int i = 0; i < record.Length; i++)
            {
                BsonDocument obj = new BsonDocument();
                obj = BsonDocument.Parse(record[i]);
                Console.WriteLine("Record is: " + obj.ToString());
                coll.Insert(obj);
            }

            //准备update
            BsonDocument updater  = new BsonDocument();
            BsonDocument matcher  = new BsonDocument();
            BsonDocument modifier = new BsonDocument();
            BsonDocument hint     = new BsonDocument();

            //条件
            matcher.Add("cust_id", new BsonDocument("$et", "A123"));
            //更新。
            updater.Add("amount", "1000");
            updater.Add("status", "C");
            modifier.Add("$set", updater);
            //update
            coll.Update(matcher, modifier, hint);

            System.Console.ReadLine();
        }
示例#13
0
        static void TestAggregate5(Sequoiadb sdb)
        {
            // The collection space name
            string csName = "sample";
            // The collection name
            string cName = "sample";

            // connect
            CollectionSpace cs;

            if (sdb.IsCollectionSpaceExist(csName))
            {
                cs = sdb.GetCollecitonSpace(csName);
            }
            else
            {
                cs = sdb.CreateCollectionSpace(csName);
            }

            DBCollection coll = null;

            if (cs.IsCollectionExist(cName))
            {
                coll = cs.GetCollection(cName);
            }
            else
            {
                coll = cs.CreateCollection(cName);
            }

            // delete all records from the collection
            BsonDocument bson = new BsonDocument();

            coll.Delete(bson);

            String[] command = new String[2];
            command[0] = "{$match:{status:\"A\"}}";
            command[1] = "{$group:{_id:\"$cust_id\",amount:{\"$sum\":\"$amount\"},cust_id:{\"$first\":\"$cust_id\"}}}";
            String[] record = new String[4];
            record[0] = "{cust_id:\"A123\",amount:500,status:\"A\"}";
            record[1] = "{cust_id:\"A123\",amount:250,status:\"A\"}";
            record[2] = "{cust_id:\"B212\",amount:200,status:\"A\"}";
            record[3] = "{cust_id:\"A123\",amount:300,status:\"D\"}";
            // insert record into database
            for (int i = 0; i < record.Length; i++)
            {
                BsonDocument obj = new BsonDocument();
                obj = BsonDocument.Parse(record[i]);
                Console.WriteLine("Record is: " + obj.ToString());
                coll.Insert(obj);
            }
            List <BsonDocument> list = new List <BsonDocument>();

            for (int i = 0; i < command.Length; i++)
            {
                BsonDocument obj = new BsonDocument();
                obj = BsonDocument.Parse(command[i]);
                list.Add(obj);
            }

            DBCursor cursor = coll.Aggregate(list);
            int      count  = 0;

            while (null != cursor.Next())
            {
                Console.WriteLine("Result is: " + cursor.Current().ToString());
                String str = cursor.Current().ToString();
                count++;
            }

            System.Console.ReadLine();
        }