Exemple #1
0
        public void GetListTest()
        {
            BsonDocument dummy  = new BsonDocument();
            BsonDocument bson   = null;
            DBCursor     cursor = null;
            Sequoiadb    db     = new Sequoiadb(config.conf.Coord.Address);

            db.Connect();

            // list transation
            sdb.TransactionBegin();
            try
            {
                BsonDocument o = null;
                coll.Insert(new BsonDocument());
                cursor = sdb.GetList(SDBConst.SDB_LIST_TRANSACTIONS, dummy, dummy, dummy);
                Console.WriteLine("the result of SDB_LIST_TRANSACTIONS is: ");
                while (null != (o = cursor.Next()))
                {
                    Console.WriteLine(o);
                }
                cursor = sdb.GetList(SDBConst.SDB_LIST_TRANSACTIONS_CURRENT, dummy, dummy, dummy);
                Console.WriteLine("the result of SDB_LIST_TRANSACTIONS_CURRENT is: ");
                while (null != (o = cursor.Next()))
                {
                    Console.WriteLine(o);
                }
            }
            finally
            {
                sdb.TransactionCommit();
            }

            // list cs
            cursor = db.GetList(SDBConst.SDB_LIST_COLLECTIONSPACES, dummy, dummy, dummy);
            Assert.IsNotNull(cursor);
            bson = cursor.Next();
            Assert.IsNotNull(bson);

            // list cl
            cursor = db.GetList(SDBConst.SDB_LIST_COLLECTIONS, dummy, dummy, dummy);
            Assert.IsNotNull(cursor);
            bson = cursor.Next();
            Assert.IsNotNull(bson);

            BsonDocument obj = new BsonDocument("test", "test");

            coll.Insert(obj);

            // list groups
            // check whether it is in the cluster environment or not
            if (Constants.isClusterEnv(db))
            {
                cursor = db.GetList(SDBConst.SDB_LIST_GROUPS, dummy, dummy, dummy);
                Assert.IsNotNull(cursor);
                bson = cursor.Next();
                Assert.IsNotNull(bson);
            }

            // list task
            cursor = db.GetList(SDBConst.SDB_LIST_TASKS, dummy, dummy, dummy);
            Assert.IsNotNull(cursor);

            // list domains
            if (Constants.isClusterEnv(db))
            {
                string dmName = "testListDomain";
                Domain dm     = db.CreateDomain(dmName, null);
                cursor = null;
                cursor = db.ListDomains(null, null, null, null);
                Assert.IsNotNull(cursor);
                Assert.IsNotNull(cursor.Next());
                db.DropDomain(dmName);
            }

            // list stored procedure
            cursor = db.GetList(SDBConst.SDB_LIST_STOREPROCEDURES, dummy, dummy, dummy);
            Assert.IsNotNull(cursor);

            // list all the contexts
            if (Constants.isClusterEnv(db))
            {
                db.Disconnect();
                db = new Sequoiadb(config.conf.Data.Address);
                db.Connect(config.conf.UserName, config.conf.Password);
            }
            cursor = db.GetList(SDBConst.SDB_LIST_CONTEXTS, dummy, dummy, dummy);
            Assert.IsNotNull(cursor);
            bson = cursor.Next();
            Assert.IsNotNull(bson);

            // list current context
            cursor = db.GetList(SDBConst.SDB_LIST_CONTEXTS_CURRENT, dummy, dummy, dummy);
            Assert.IsNotNull(cursor);
            bson = cursor.Next();
            Assert.IsNotNull(bson);

            // list all the sessions
            cursor = db.GetList(SDBConst.SDB_LIST_SESSIONS, dummy, dummy, dummy);
            Assert.IsNotNull(cursor);
            bson = cursor.Next();
            Assert.IsNotNull(bson);

            // list current session
            cursor = db.GetList(SDBConst.SDB_LIST_SESSIONS_CURRENT, dummy, dummy, dummy);
            Assert.IsNotNull(cursor);
            bson = cursor.Next();
            Assert.IsNotNull(bson);

            // list storge units
            cursor = db.GetList(SDBConst.SDB_LIST_STORAGEUNITS, dummy, dummy, dummy);
            Assert.IsNotNull(cursor);
            bson = cursor.Next();
            Assert.IsNotNull(bson);
            db.Disconnect();
        }
Exemple #2
0
        public void DomainGlobalTest()
        {
            string       dmName    = "testDomainInCS";
            string       csName    = "domainCS";
            string       clName    = "domainCL";
            string       groupName = config.conf.Groups[0].GroupName;
            BsonDocument options   = new BsonDocument();
            BsonArray    arr       = new BsonArray();

            arr.Add(groupName);
            options.Add(SequoiadbConstants.FIELD_GROUPS, arr);
            Domain       dm     = null;
            DBCursor     cur    = null;
            BsonDocument record = null;

            /// IsDomainExist
            bool flag = sdb.IsDomainExist(dmName);

            Assert.IsFalse(flag);

            /// getDomain
            try
            {
                dm = sdb.GetDomain(dmName);
            }
            catch (BaseException e)
            {
                Assert.IsTrue(e.ErrorType.Equals("SDB_CAT_DOMAIN_NOT_EXIST"));
            }

            /// createDomain
            dm = null;
            dm = sdb.CreateDomain(dmName, options);
            Assert.IsNotNull(dm);

            /// IsDomainExist
            flag = false;
            flag = sdb.IsDomainExist(dmName);
            Assert.IsTrue(flag);

            /// getDomain
            dm = null;
            dm = sdb.GetDomain(dmName);
            Assert.IsNotNull(dm);

            /// listDomains
            cur = sdb.ListDomains(null, null, null, null);
            Assert.IsNotNull(cur);
            record = cur.Next();
            Assert.IsNotNull(record);

            /// getName
            string name = dm.Name;

            Assert.IsTrue(name.Equals(dmName));

            // create cs
            BsonDocument opts1 = new BsonDocument();

            opts1.Add("Domain", dmName);
            CollectionSpace cs = sdb.CreateCollectionSpace(csName, opts1);
            // create cl
            BsonDocument opts2 = new BsonDocument();

            //BsonDocument key = new BsonDocument();
            //key.Add("a", 1);
            opts2.Add("ShardingKey", new BsonDocument("a", 1));
            opts2.Add("ShardingType", "hash");
            opts2.Add("AutoSplit", true);
            DBCollection cl = cs.CreateCollection(clName, opts2);

            /// listCS
            cur = dm.ListCS();
            Assert.IsNotNull(cur);
            record = cur.Next();
            Assert.IsNotNull(record);

            /// listCL
            cur = dm.ListCL();
            Assert.IsNotNull(cur);
            record = cur.Next();
            Assert.IsNotNull(record);

            // dropCS
            sdb.DropCollectionSpace(csName);

            /// alter
            /// TODO: alter should be verified
            BsonDocument opts3 = new BsonDocument();
            BsonArray    arr2  = new BsonArray();

            opts3.Add("Groups", arr2);
            opts3.Add("AutoSplit", false);
            dm.Alter(opts3);

            /// listDomains
            cur = sdb.ListDomains(null, null, null, null);
            Assert.IsNotNull(cur);
            record = cur.Next();
            Assert.IsNotNull(record);

            /// dropDomain
            sdb.DropDomain(dmName);

            /// listDomains
            cur = sdb.ListDomains(null, null, null, null);
            Assert.IsNotNull(cur);
            record = cur.Next();
            Assert.IsNull(record);
        }