Example #1
0
        public void Connect_With_Serval_Arg_Test2()
        {
            List <string> list     = new List <string>();
            int           conn_num = 100;

            Sequoiadb [] dbs = new Sequoiadb[100];
            int          i   = 0;

            list.Add("192.168.20.35:12340");
            list.Add("192.168.20.165:11810");
            list.Add("192.168.20.35:12340");
            list.Add("192.168.20.42:50000");
            list.Add("192.168.20.42:11810");

            ConfigOptions options = new ConfigOptions();

            options.MaxAutoConnectRetryTime = 0;
            options.ConnectTimeout          = 100;
            // connect
            for (i = 0; i < conn_num; i++)
            {
                dbs[i] = new Sequoiadb(list);
                dbs[i].Connect("", "", options);
            }
            for (i = 0; i < conn_num; i++)
            {
                dbs[i].Disconnect();
            }
        }
Example #2
0
 public static Boolean isClusterEnv(Sequoiadb sdb)
 {
     try
     {
         sdb.ListReplicaGroups();
     }
     catch (BaseException e)
     {
         int errcode = e.ErrorCode;
         if (new BaseException("SDB_RTN_COORD_ONLY").ErrorCode == errcode)
         {
             return(false);
         }
         else
         {
             throw e;
         }
     }
     catch (System.Exception e)
     {
         Console.WriteLine(e.StackTrace);
         Environment.Exit(0);
     }
     return(true);
 }
        public void createRG()
        {
            // 1. prepare a empty coord by manually

            // 2. get connection
            Sequoiadb db = new Sequoiadb("192.168.20.165", 11810);

            db.Connect();
            //db.ListCollections();

            // 3. create catalog group
            Dictionary <string, string> map = new Dictionary <String, String>();

            map.Add("businessname", "abc");
            map.Add("diaglevel", "5");
            map.Add("omaddr", "susetzb:11830");
            //      db.createReplicaCataGroup("192.168.20.165", 11820, "/opt/sequoiadb/database/cata/11820", map);
            BsonDocument obj = new BsonDocument();

            obj.Add("businessname", "abc");
            obj.Add("diaglevel", 5);
            obj.Add("omaddr", "susetzb:12345");
            db.CreateReplicaCataGroup("192.168.20.165", 11820, "/opt/sequoiadb/database/cata/11820", obj);
            ReplicaGroup rg = db.GetReplicaGroup("SYSCatalogGroup");

            SequoiaDB.Node node = rg.CreateNode("192.168.20.165", 11830, "/opt/sequoiadb/database/cata/11830", map);
            node.Start();
        }
        /// <summary>
        /// Linq测试。
        /// </summary>
        /// <param name="sdb"></param>
        static void TestLinq(Sequoiadb sdb)
        {
            var cs   = sdb.GetCollecitonSpace("dbo");
            var coll = cs.GetCollection <HFareDetail>();

            var vList = coll.AsQueryable <HFareDetail>()
                        .Where(p => p.CreateTime > DateTime.Now.Date.AddMonths(-12))
                        .Skip(10).Take(1000)
                        .ToList();

            System.Console.WriteLine(string.Format("query {0} records", vList.Count));

            var vList2 = coll.AsQueryable <HFareDetail>()
                         .Where(p => p.PNumber == 624)
                         .ToList();

            System.Console.WriteLine(string.Format("query {0} records", vList2.Count));

            int count = coll.AsQueryable <HFareDetail>()
                        .Where(p => p.PNumber == 624)
                        .Count();

            System.Console.WriteLine(string.Format("Count:{0}", count));

            System.Console.ReadLine();
        }
        /// <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();
        }
 public void ConnectTest()
 {
     Sequoiadb sdb2 = new Sequoiadb(config.conf.Coord.Address);
     System.Console.WriteLine(config.conf.Coord.Address.ToString());
     // check whether it is in the cluster environment or not
     if (!Constants.isClusterEnv(sdb))
     {
         System.Console.WriteLine("ConnectWithAuth is for cluster environment only.");
         return;
     }
     sdb.CreateUser("testusr", "testpwd");
     sdb2.Connect("testusr", "testpwd");
     Assert.IsNotNull(sdb.Connection);
     sdb2.RemoveUser("testusr", "testpwd");
     sdb2.Disconnect();
     Assert.IsNull(sdb2.Connection);
     try
     {
         sdb2.Connect("testusr", "testpwd");
     }
     catch (BaseException e)
     {
         Assert.IsTrue(e.ErrorType == "SDB_AUTH_AUTHORITY_FORBIDDEN");
     }
 }
Example #7
0
        public void ConnectTest()
        {
            Sequoiadb sdb2 = new Sequoiadb(config.conf.Coord.Address);

            System.Console.WriteLine(config.conf.Coord.Address.ToString());
            // check whether it is in the cluster environment or not
            if (!Constants.isClusterEnv(sdb))
            {
                System.Console.WriteLine("ConnectWithAuth is for cluster environment only.");
                return;
            }
            sdb.CreateUser("testusr", "testpwd");
            sdb2.Connect("testusr", "testpwd");
            Assert.IsNotNull(sdb.Connection);
            sdb2.RemoveUser("testusr", "testpwd");
            sdb2.Disconnect();
            Assert.IsNull(sdb2.Connection);
            try
            {
                sdb2.Connect("testusr", "testpwd");
            }
            catch (BaseException e)
            {
                Assert.IsTrue(e.ErrorType == "SDB_AUTH_AUTHORITY_FORBIDDEN");
            }
        }
Example #8
0
        // create collection space, if the collection space exists then return
        public static CollectionSpace CreateCollecitonSpace(Sequoiadb sdb, string csName, int pageSize)
        {
            CollectionSpace cs = null;

            try
            {
                cs = sdb.CreateCollectionSpace(csName, pageSize);
            }
            catch (BaseException e)
            {
                // verify whether the collection space exists
                if ("SDB_DMS_CS_EXIST" == e.ErrorType)
                {
                    cs = GetCollecitonSpace(sdb, csName);
                }
                // invalid page size argument
                else if ("SDB_INVALIDARG" == e.ErrorType)
                {
                    Console.WriteLine("Failed to create collection space {0}, invalid page size {1}", csName, pageSize);
                    Environment.Exit(0);
                }
                else
                {
                    Console.WriteLine("Failed to create collection space {0},ErrorType = {1}", csName, e.ErrorType);
                    Environment.Exit(0);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                Environment.Exit(0);
            }

            return(cs);
        }
Example #9
0
        // get collection space, if the collection space does not exist it will try to create one
        public static CollectionSpace GetCollecitonSpace(Sequoiadb sdb, string csName)
        {
            CollectionSpace cs = null;

            try
            {
                cs = sdb.GetCollecitonSpace(csName);
            }
            catch (BaseException e)
            {
                // verify whether the collection space exists
                if ("SDB_DMS_CS_NOTEXIST" == e.ErrorType)
                {
                    // if the collection space does not exist, we are going to create one
                    cs = CreateCollecitonSpace(sdb, csName);
                }
                else
                {
                    Console.WriteLine("Failed to get collection space {0},ErrorType = {1}", csName, e.ErrorType);
                    Environment.Exit(0);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                Environment.Exit(0);
            }

            return(cs);
        }
Example #10
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);
        }
Example #11
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");
        }
Example #12
0
        public void IsValidTest()
        {
            bool      result = false;
            Sequoiadb sdb2   = new Sequoiadb(config.conf.Coord.Address);

            System.Console.WriteLine(config.conf.Coord.Address.ToString());
            sdb2.Connect("", "");
            Assert.IsNotNull(sdb2.Connection);
            // check before disconnect
            result = sdb2.IsValid();
            Assert.IsTrue(result);
            // check after disconnect
            sdb2.Disconnect();
            result = sdb2.IsValid();
            Assert.IsFalse(result);

            /*
             * // check after shutdown database manually
             * sdb2 = new Sequoiadb(config.conf.Coord.Address);
             * sdb2.Connect("", "");
             * result = true;
             * result = sdb2.IsValid();
             * Assert.IsFalse(result);
             */
        }
Example #13
0
        public void CreateReplicaCataSetTest()
        {
            try
            {
                System.Console.WriteLine(config.conf.Groups[2].Nodes[0].HostName.ToString());
                System.Console.WriteLine(config.conf.Groups[2].Nodes[0].Port.ToString());
                System.Console.WriteLine(config.conf.Groups[2].Nodes[0].DBPath.ToString());
                string str1 = config.conf.Groups[2].Nodes[0].HostName.ToString();
                string str2 = config.conf.Groups[2].Nodes[0].Port.ToString();
                string str3 = config.conf.Groups[2].Nodes[0].DBPath.ToString();
                sdb.CreateReplicaCataGroup(config.conf.Groups[2].Nodes[0].HostName,
                                           config.conf.Groups[2].Nodes[0].Port,
                                           config.conf.Groups[2].Nodes[0].DBPath,
                                           null);
            }
            catch (BaseException)
            {
            }
            Sequoiadb sdb2 = new Sequoiadb(config.conf.Groups[2].Nodes[0].HostName,
                                           config.conf.Groups[2].Nodes[0].Port);

            sdb2.Connect();
            Assert.IsNotNull(sdb2.Connection);
            sdb2.Disconnect();
        }
 public static void SequoiadbInitialize(TestContext testContext)
 {
     if ( config == null )
         config = new Config();
     sdb = new Sequoiadb(config.conf.Coord.Address);
     sdb.Connect(config.conf.UserName, config.conf.Password);
 }
        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();
        }
Example #16
0
        /// <summary>
        /// Linq测试。
        /// </summary>
        /// <param name="sdb"></param>
        static void TestAggregate(Sequoiadb sdb)
        {
            var cs   = sdb.GetCollecitonSpace("dbo");
            var coll = cs.GetCollection <HFareDetail>();

            String[] command = new String[2];
            //command[0] = "{$match:{PNumber:\"3\"}}";
            command[0] = string.Empty;
            command[1] = "{$group:{_id:\"$EDeptID\",total:{$sum:\"$Cash\"}}}";
            List <BsonDocument> list = new List <BsonDocument>();

            for (int i = 0; i < command.Length; i++)
            {
                BsonDocument obj = new BsonDocument();
                if (!string.IsNullOrEmpty(command[i]))
                {
                    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();
        }
Example #17
0
        public void Connect_With_Serval_Arg_Test()
        {
            List <string> list = new List <string>();

            list.Add("192.168.20.35:12340");
            list.Add("192.168.20.36:12340");
            list.Add("123:123");
            list.Add("");
            list.Add("192.168.20.40");
            list.Add("192.168.30.161:11810");
            list.Add("localhost:50000");
            list.Add("192.168.20.42:50000");
            list.Add("192.168.20.42:11810");
            list.Add("192.168.20.165:11810");
            list.Add("localhost:12340");
            list.Add("192.168.20.40:12340");

            ConfigOptions options = new ConfigOptions();

            options.MaxAutoConnectRetryTime = 0;
            options.ConnectTimeout          = 100;
            // connect
            Sequoiadb sdb1 = new Sequoiadb(list);

            sdb1.Connect("", "", options);
            // set option and change the connect
            options.ConnectTimeout = 2000;
            sdb1.ChangeConnectionOptions(options);
            // check
            DBCursor cursor = sdb1.GetList(4, null, null, null);

            Assert.IsTrue(cursor != null);
            sdb1.Disconnect();
        }
        public void MyTestInitialize()
        {
            // check whether it is in the cluster environment or not
            if (!Constants.isClusterEnv(sdb))
            {
                Console.WriteLine("removeRG is for cluster environment only.");
                return;
            }
            // argument
            groupName = config.conf.Groups[0].GroupName;
            hostName  = config.conf.Groups[0].Nodes[0].HostName;
            port      = config.conf.Groups[0].Nodes[0].Port;
            dbpath    = config.conf.Groups[0].Nodes[0].DBPath;
            // drop the exist group
            group = sdb.GetReplicaGroup(groupName);
            if (group != null)
            {
                // drop all the cs in current group, and then remove this group
                int nodeNum = group.GetNodeNum(SDBConst.NodeStatus.SDB_NODE_ALL);
                if (nodeNum > 0)
                {
                    var       nd = group.GetMaster();
                    Sequoiadb db = new Sequoiadb(nd.HostName, nd.Port);
                    Assert.IsTrue(nd.Start());
                    db.Connect(config.conf.UserName, config.conf.Password);
                    DBCursor cursor = db.ListCollectionSpaces();
                    while (cursor.Next() != null)
                    {
                        BsonDocument obj  = cursor.Current();
                        string       temp = null;
                        if (obj.Contains("Name"))
                        {
                            temp = obj["Name"].AsString;
                        }
                        sdb.DropCollectionSpace(temp);
                    }
                    db.Disconnect();
                }
                try
                {
                    sdb.RemoveReplicaGroup(group.GroupName);
                }
                catch (BaseException e)
                {
                    string errInfo = e.Message;
                    Console.WriteLine("Error code is: " + errInfo);
                }
            }
            // create a new group
            group = sdb.CreateReplicaGroup(groupName);
            Assert.IsTrue(groupName.Equals(group.GroupName));
            // create a node
            Dictionary <string, string> map = new Dictionary <string, string>();

            map.Add("diaglevel", config.conf.Groups[0].Nodes[0].DiagLevel);
            node = group.CreateNode(hostName, port, dbpath, map);
            Assert.IsNotNull(node);
            group.Start();
        }
Example #19
0
        /** \fn Sequoiadb Connect(string username, string password)
         *  \brief Connect to remote Sequoiadb database node
         *  \username Sequoiadb connection user name
         *  \password Sequoiadb connection password
         *  \return The Sequoiadb handle
         *  \exception SequoiaDB.BaseException
         *  \exception System.Exception
         */
        public Sequoiadb Connect(string username, string password)
        {
            Sequoiadb sdb = null;

            sdb = new Sequoiadb(hostName, port);
            sdb.Connect(username, password);
            return(sdb);
        }
Example #20
0
 internal ReplicaGroup(Sequoiadb sdb, string groupName, int groupID)
 {
     this.sdb       = sdb;
     this.groupName = groupName;
     this.groupID   = groupID;
     isCatalog      = groupName.Equals(SequoiadbConstants.CATALOG_GROUP);
     isBigEndian    = sdb.isBigEndian;
 }
Example #21
0
        internal static DBCursor RunGeneralCmd(Sequoiadb sdb, string command,
                                               BsonDocument matcher, BsonDocument selector,
                                               BsonDocument orderBy, BsonDocument hint,
                                               int flags, ulong reqID, long skipNum, long retNum)
        {
            IConnection  connection  = sdb.Connection;
            bool         isBigEndian = sdb.isBigEndian;
            BsonDocument dummyObj    = new BsonDocument();
            SDBMessage   sdbMessage  = new SDBMessage();

            sdbMessage.OperationCode      = Operation.OP_QUERY;
            sdbMessage.CollectionFullName = command;
            sdbMessage.Version            = SequoiadbConstants.DEFAULT_VERSION;
            sdbMessage.W               = SequoiadbConstants.DEFAULT_W;
            sdbMessage.Padding         = 0;
            sdbMessage.Flags           = flags;
            sdbMessage.NodeID          = SequoiadbConstants.ZERO_NODEID;
            sdbMessage.RequestID       = reqID;
            sdbMessage.SkipRowsCount   = skipNum;
            sdbMessage.ReturnRowsCount = retNum;
            sdbMessage.Matcher         = (null == matcher) ? dummyObj : matcher;
            sdbMessage.Selector        = (null == selector) ? dummyObj : selector;
            sdbMessage.OrderBy         = (null == orderBy) ? dummyObj : orderBy;
            sdbMessage.Hint            = (null == hint) ? dummyObj : hint;

            // check
            if (connection == null)
            {
                throw new BaseException("SDB_NETWORK");
            }
            // build msg
            byte[] request = SDBMessageHelper.BuildQueryRequest(sdbMessage, isBigEndian);
            // send
            connection.SendMessage(request);
            // extract
            SDBMessage rtnSDBMessage = SDBMessageHelper.MsgExtractReply(connection.ReceiveMessage(isBigEndian), isBigEndian);

            // check return msg header
            rtnSDBMessage = SDBMessageHelper.CheckRetMsgHeader(sdbMessage, rtnSDBMessage);
            // check whether error happen
            int errorCode = rtnSDBMessage.Flags;

            if (errorCode != 0)
            {
                // TODO: need to throw error detail(return from engine) out
                throw new BaseException(errorCode);
            }
            // try to build return cursor
            if (SequoiadbConstants.DEFAULT_CONTEXTID == rtnSDBMessage.ContextIDList[0] &&
                (rtnSDBMessage.ObjectList == null || rtnSDBMessage.ObjectList.Count == 0))
            {
                return(null);
            }
            else
            {
                return(new DBCursor(rtnSDBMessage, sdb));
            }
        }
Example #22
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";

            BsonDocument insertor1 = CreateEnglisthRecord();
            BsonDocument insertor2 = CreateChineseRecord();

            Sequoiadb sdb = new Sequoiadb(sdbIP);

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

            try
            {
                ObjectId id = dbc.Insert(insertor1);
                Console.WriteLine("Successfully inserted english records, object ID = {0}", id.ToString());
            }
            catch (BaseException e)
            {
                Console.WriteLine("Failed to insert english record, ErrorType = {0}", e.ErrorType);
                Environment.Exit(0);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                Environment.Exit(0);
            }

            try
            {
                ObjectId id = dbc.Insert(insertor2);
                Console.WriteLine("Successfully inserted chinese records, object ID = {0}", id.ToString());
            }
            catch (BaseException e)
            {
                Console.WriteLine("Failed to insert chinese record, ErrorType = {0}", e.ErrorType);
                Environment.Exit(0);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                Environment.Exit(0);
            }

            Common.Disconnect(sdb);
        }
 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);
 }
 public static void SequoiadbInitialize(TestContext testContext)
 {
     if (config == null)
     {
         config = new Config();
     }
     sdb = new Sequoiadb(config.conf.Coord.Address);
     sdb.Connect(config.conf.UserName, config.conf.Password);
 }
Example #25
0
        public void GetSnapshotTest()
        {
            Sequoiadb sdb2 = new Sequoiadb(config.conf.Coord.Address);

            sdb2.Connect();
            BsonDocument dummy  = new BsonDocument();
            DBCursor     cursor = sdb2.GetSnapshot(SDBConst.SDB_SNAP_CONTEXTS, dummy, dummy, dummy);

            Assert.IsNotNull(cursor);
            BsonDocument bson = cursor.Next();

            Assert.IsNotNull(bson);

            cursor = sdb2.GetSnapshot(SDBConst.SDB_SNAP_CONTEXTS_CURRENT, dummy, dummy, dummy);
            Assert.IsNotNull(cursor);
            bson = cursor.Next();
            Assert.IsNotNull(bson);

            cursor = sdb2.GetSnapshot(SDBConst.SDB_SNAP_SESSIONS, dummy, dummy, dummy);
            Assert.IsNotNull(cursor);
            bson = cursor.Next();
            Assert.IsNotNull(bson);

            cursor = sdb2.GetSnapshot(SDBConst.SDB_SNAP_SESSIONS_CURRENT, dummy, dummy, dummy);
            Assert.IsNotNull(cursor);
            bson = cursor.Next();
            Assert.IsNotNull(bson);

            cursor = sdb2.GetSnapshot(SDBConst.SDB_SNAP_COLLECTIONS, dummy, dummy, dummy);
            Assert.IsNotNull(cursor);
            bson = cursor.Next();
            Assert.IsNotNull(bson);

            cursor = sdb2.GetSnapshot(SDBConst.SDB_SNAP_COLLECTIONSPACES, dummy, dummy, dummy);
            Assert.IsNotNull(cursor);
            bson = cursor.Next();
            Assert.IsNotNull(bson);

            cursor = sdb2.GetSnapshot(SDBConst.SDB_SNAP_DATABASE, dummy, dummy, dummy);
            Assert.IsNotNull(cursor);
            bson = cursor.Next();
            Assert.IsNotNull(bson);

            cursor = sdb2.GetSnapshot(SDBConst.SDB_SNAP_SYSTEM, dummy, dummy, dummy);
            Assert.IsNotNull(cursor);
            bson = cursor.Next();
            Assert.IsNotNull(bson);

            if (Constants.isClusterEnv(sdb))
            {
                cursor = sdb.GetSnapshot(SDBConst.SDB_SNAP_CATALOG, dummy, dummy, dummy);
                Assert.IsNotNull(cursor);
                BsonDocument obj = cursor.Next();
                Assert.IsNotNull(obj);
            }
            sdb2.Disconnect();
        }
Example #26
0
        public void InitClientTest()
        {
            // test1: test default value
            bool      boolValue = true;
            long      longValue = 300 * 1000;
            Sequoiadb db        = new Sequoiadb(config.conf.Coord.Address);

            db.Connect(config.conf.UserName, config.conf.Password);
            // check
            Type         t               = typeof(Sequoiadb);
            BindingFlags flag            = BindingFlags.Static | BindingFlags.NonPublic;
            FieldInfo    f_enableCache   = t.GetField("enableCache", flag);
            FieldInfo    f_cacheInterval = t.GetField("cacheInterval", flag);

            Assert.AreEqual(boolValue, f_enableCache.GetValue(db));
            Assert.AreEqual(longValue, f_cacheInterval.GetValue(db));

            // test2: test user defined value
            boolValue = false;
            longValue = 100;
            ClientOptions opt = new ClientOptions();

            opt.CacheInterval = longValue;
            opt.EnableCache   = boolValue;
            Sequoiadb.InitClient(opt);
            // check
            f_enableCache   = t.GetField("enableCache", flag);
            f_cacheInterval = t.GetField("cacheInterval", flag);
            Assert.AreEqual(boolValue, f_enableCache.GetValue(db));
            Assert.AreEqual(longValue, f_cacheInterval.GetValue(db));

            // test3: test user definded value
            boolValue         = true;
            longValue         = -1;
            opt.CacheInterval = longValue;
            opt.EnableCache   = boolValue;
            Sequoiadb.InitClient(opt);
            // check
            f_enableCache   = t.GetField("enableCache", flag);
            f_cacheInterval = t.GetField("cacheInterval", flag);
            Assert.AreEqual(boolValue, f_enableCache.GetValue(db));
            Assert.AreEqual(300000L, f_cacheInterval.GetValue(db));

            // test4: opt to be null
            boolValue = true;
            longValue = 300000;
            opt       = null;
            Sequoiadb.InitClient(opt);
            // check
            f_enableCache   = t.GetField("enableCache", flag);
            f_cacheInterval = t.GetField("cacheInterval", flag);
            Assert.AreEqual(boolValue, f_enableCache.GetValue(db));
            Assert.AreEqual(300000L, f_cacheInterval.GetValue(db));

            db.Disconnect();
        }
 public void MyTestInitialize()
 {
     // check whether it is in the cluster environment or not
     if (!Constants.isClusterEnv(sdb))
     {
         Console.WriteLine("removeRG is for cluster environment only.");
         return;
     }
     // argument
     groupName = config.conf.Groups[0].GroupName;
     hostName = config.conf.Groups[0].Nodes[0].HostName;
     port = config.conf.Groups[0].Nodes[0].Port;
     dbpath = config.conf.Groups[0].Nodes[0].DBPath;
     // drop the exist group
     group = sdb.GetReplicaGroup(groupName);
     if (group != null)
     {
         // drop all the cs in current group, and then remove this group
         int nodeNum = group.GetNodeNum(SDBConst.NodeStatus.SDB_NODE_ALL);
         if (nodeNum > 0)
         {
             var nd = group.GetMaster();
             Sequoiadb db = new Sequoiadb(nd.HostName, nd.Port);
             Assert.IsTrue(nd.Start());
             db.Connect(config.conf.UserName, config.conf.Password);
             DBCursor cursor = db.ListCollectionSpaces();
             while (cursor.Next() != null)
             {
                 BsonDocument obj = cursor.Current();
                 string temp = null;
                 if (obj.Contains("Name"))
                     temp = obj["Name"].AsString;
                 sdb.DropCollectionSpace(temp);
             }
             db.Disconnect();
         }
         try
         {
             sdb.RemoveReplicaGroup(group.GroupName);
         }
         catch (BaseException e)
         {
             string errInfo = e.Message;
             Console.WriteLine("Error code is: " + errInfo);
         }
     }
     // create a new group
     group = sdb.CreateReplicaGroup(groupName);
     Assert.IsTrue(groupName.Equals(group.GroupName));
     // create a node
     Dictionary<string, string> map = new Dictionary<string, string>();
     map.Add("diaglevel", config.conf.Groups[0].Nodes[0].DiagLevel);
     node = group.CreateNode(hostName, port, dbpath, map);
     Assert.IsNotNull(node);
     group.Start();
 }
Example #28
0
        public void getSessionAttr_data_Test()
        {
            Sequoiadb data = new Sequoiadb(config.conf.Data.Address);

            data.Connect(config.conf.UserName, config.conf.Password);
            Assert.IsNotNull(data.Connection);
            BsonDocument attribute = data.GetSessionAttr();

            Assert.IsNull(attribute);
            data.Disconnect();
        }
Example #29
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);
 }
        public void RGTest()
        {
            String hostName = "192.168.20.166";
            int    port     = 45000;

            // check whether it is in the cluster environment or not
            if (!Constants.isClusterEnv(sdb))
            {
                Console.WriteLine("It's not a cluster environment.");
                return;
            }
            group = sdb.GetReplicaGroup(groupName);
            if (group == null)
            {
                group = sdb.CreateReplicaGroup(groupName);
            }
            ReplicaGroup group1 = sdb.GetReplicaGroup(group.GroupID);

            Assert.AreEqual(group.GroupName, group1.GroupName);
            ReplicaGroup group2 = sdb.GetReplicaGroup(1);

            Assert.IsNotNull(group2);
            node = group.GetNode(hostName, port);
            if (node == null)
            {
                string dbpath = config.conf.Groups[0].Nodes[0].DBPath;
                Dictionary <string, string> map = new Dictionary <string, string>();
                map.Add("diaglevel", config.conf.Groups[0].Nodes[0].DiagLevel);
                node = group.CreateNode(hostName, port, dbpath, map);
            }
            group.Start();
            int num = group.GetNodeNum(SDBConst.NodeStatus.SDB_NODE_ALL);

            Assert.IsTrue(num > 0);
            BsonDocument detail = group.GetDetail();
            string       gn     = detail["GroupName"].AsString;

            Assert.IsTrue(groupName.Equals(gn));
            SequoiaDB.Node master = group.GetMaster();
            Assert.IsNotNull(master);
            SequoiaDB.Node slave = group.GetSlave();
            Assert.IsNotNull(slave);
            Assert.IsTrue(node.Stop());
            Assert.IsTrue(node.Start());
            SDBConst.NodeStatus status = node.GetStatus();
            Assert.IsTrue(status == SDBConst.NodeStatus.SDB_NODE_ACTIVE);

            Sequoiadb db = node.Connect(config.conf.UserName, config.conf.Password);

            db.Disconnect();
            node.Stop();
            group.Stop();
        }
Example #31
0
 public void MyTestInitialize()
 {
     try
     {
         sdb = new Sequoiadb(config.conf.Coord.Address);
         sdb.Connect(config.conf.UserName, config.conf.Password);
     }
     catch (BaseException e)
     {
         Console.WriteLine("Failed to Initialize in DomainTest, ErrorType = {0}", e.ErrorType);
         Environment.Exit(0);
     }
 }
Example #32
0
        public void KeepAlive_Test()
        {
            Sequoiadb    db = null;
            ReplicaGroup rg = null;

            SequoiaDB.Node node = null;

            db = new Sequoiadb("192.168.30.121", 11810);
            db.Connect();
            rg   = db.GetReplicaGroup("group2");
            node = rg.GetNode("ubuntu-hs03", 11840);
            node.Start();
        }
Example #33
0
 // connect to a given database
 public static void Connect(Sequoiadb sdb)
 {
     try
     {
         // connect to database
         sdb.Connect();
     }
     catch (Exception e)
     {
         Console.WriteLine("Failed to connect to database at {0}:{1}", sdb.ServerAddr.Host, sdb.ServerAddr.Port);
         Console.WriteLine(e.Message);
         Environment.Exit(0);
     }
 }
Example #34
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);
        }
Example #35
0
        static void TestAggregate2(Sequoiadb sdb)
        {
            var cs = sdb.GetCollecitonSpace("dbo");

            DBCollection coll = null;

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

            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++;
            }
        }
Example #36
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();
 }
Example #38
0
 public static Boolean isClusterEnv(Sequoiadb sdb)
 {
     try
     {
         sdb.ListReplicaGroups();
     }
     catch (BaseException e)
     {
         int errcode = e.ErrorCode;
         if (new BaseException("SDB_RTN_COORD_ONLY").ErrorCode == errcode)
             return false;
         else
             throw e;
     }
     catch (System.Exception e)
     {
         Console.WriteLine(e.StackTrace);
         Environment.Exit(0);
     }
     return true;
 }
 public void MyTestCleanup()
 {
     // check whether it is in the cluster environment or not
     if (!Constants.isClusterEnv(sdb))
     {
         Console.WriteLine("removeRG is for cluster environment only.");
         return;
     }
     group = sdb.GetReplicaGroup(groupName);
     if (group != null)
     {
         // drop all the cs in current group, and then remove this group
         int nodeNum = group.GetNodeNum(SDBConst.NodeStatus.SDB_NODE_ALL);
         if (nodeNum > 0)
         {
             var nd = group.GetMaster();
             var db = new Sequoiadb(nd.HostName, nd.Port);
             Assert.IsTrue(nd.Start());
             db.Connect(config.conf.UserName, config.conf.Password);
             DBCursor cursor = db.ListCollectionSpaces();
             while (cursor.Next() != null)
             {
                 BsonDocument obj = cursor.Current();
                 string temp = null;
                 if (obj.Contains("Name"))
                     temp = obj["Name"].AsString;
                 sdb.DropCollectionSpace(temp);
             }
             db.Disconnect();
         }
         Assert.IsTrue(group.Stop());
         // remove group
         try
         {
             sdb.RemoveReplicaGroup(group.GroupName);
         }
         catch (BaseException e)
         {
             string errInfo = e.Message;
             Console.WriteLine("Error code is: " + errInfo);
         }
     }
     sdb.Disconnect();
 }
 public void setSessionAttr_Arguments_Test()
 {
     // 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 = null;
     string[] str = { "M", "m", "S", "s", "A", "a" };
     int[] nodeNumber = { 1, 2, 3, 4, 5, 6, 7 };
     Random rnd = new Random();
     int r = rnd.Next(2);
     int n = -1;
     if (r == 0)
     {
         n = rnd.Next(6);
         conf = new BsonDocument("PreferedInstance", str[n]);
     }
     else
     {
         n = rnd.Next(7);
         conf = new BsonDocument("PreferedInstance", nodeNumber[n]);
     }
     try
     {
         sdb2.SetSessionAttr(conf);
     }
     catch (BaseException e) 
     {
         Console.WriteLine(e.ErrorType);
         Assert.Fail();
     }
 }
        public void Connect_With_Serval_Arg_Test()
        {
		    List<string> list = new List<string>();
            
            list.Add("192.168.20.35:12340");
            list.Add("192.168.20.36:12340");
            list.Add("123:123");
            list.Add("");
            list.Add("192.168.20.40");
            list.Add("192.168.30.161:11810");
            list.Add("localhost:50000");
            list.Add("192.168.20.42:11810");
            list.Add("192.168.20.165:11810");
            list.Add("localhost:12340");
            list.Add("192.168.20.40:12340");

	        ConfigOptions options = new ConfigOptions();
	        options.MaxAutoConnectRetryTime = 0;
	        options.ConnectTimeout = 100;
	        // connect
	        Sequoiadb sdb1 = new Sequoiadb(list);
            sdb1.Connect("", "", options);
	        // set option and change the connect
	        options.ConnectTimeout = 2000;
	        sdb1.ChangeConnectionOptions(options);
	        // check
	        DBCursor cursor = sdb1.GetList(4, null, null, null);
	        Assert.IsTrue(cursor != null);
	        sdb1.Disconnect();
        }
 public void IsValidTest()
 {
     bool result = false;
     Sequoiadb sdb2 = new Sequoiadb(config.conf.Coord.Address);
     System.Console.WriteLine(config.conf.Coord.Address.ToString());
     sdb2.Connect("", "");
     Assert.IsNotNull(sdb2.Connection);
     // check before disconnect
     result = sdb2.IsValid();
     Assert.IsTrue(result);
     // check after disconnect
     sdb2.Disconnect();
     result = sdb2.IsValid();
     Assert.IsFalse(result);
     /*
     // check after shutdown database manually
     sdb2 = new SequoiaClient(config.conf.Coord.Address);
     sdb2.Connect("", "");
     result = true;
     result = sdb2.IsValid();
     Assert.IsFalse(result);
      */
 }
 public void CreateReplicaCataSetTest()
 {
     try
     {
         System.Console.WriteLine(config.conf.Groups[2].Nodes[0].HostName.ToString());
         System.Console.WriteLine(config.conf.Groups[2].Nodes[0].Port.ToString());
         System.Console.WriteLine(config.conf.Groups[2].Nodes[0].DBPath.ToString());
         string str1 = config.conf.Groups[2].Nodes[0].HostName.ToString();
         string str2 = config.conf.Groups[2].Nodes[0].Port.ToString();
         string str3 = config.conf.Groups[2].Nodes[0].DBPath.ToString();
         sdb.CreateReplicaCataGroup(config.conf.Groups[2].Nodes[0].HostName,
                                     config.conf.Groups[2].Nodes[0].Port,
                                     config.conf.Groups[2].Nodes[0].DBPath,
                                     null);
     }
     catch (BaseException)
     {
     }
     Sequoiadb sdb2 = new Sequoiadb(config.conf.Groups[2].Nodes[0].HostName,
                                 config.conf.Groups[2].Nodes[0].Port);
     sdb2.Connect();
     Assert.IsNotNull(sdb2.Connection);
     sdb2.Disconnect();
 }
Example #44
0
        // get collection space, if the collection space does not exist it will try to create one
        public static CollectionSpace GetCollecitonSpace(Sequoiadb sdb, string csName)
        {
            CollectionSpace cs = null;
            try
            {
                cs = sdb.GetCollecitonSpace(csName);
            }
            catch (BaseException e)
            {
                // verify whether the collection space exists
                if ("SDB_DMS_CS_NOTEXIST" == e.ErrorType)
                {
                    // if the collection space does not exist, we are going to create one
                    cs = CreateCollecitonSpace(sdb, csName);
                }
                else
                {
                    Console.WriteLine("Failed to get collection space {0},ErrorType = {1}", csName, e.ErrorType);
                    Environment.Exit(0);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                Environment.Exit(0);
            }

            return cs;
        }
Example #45
0
 // disconnect from database
 public static void Disconnect(Sequoiadb sdb)
 {
     sdb.Disconnect();
 }
 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
         var 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
         var 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
         var node = rg.GetNode(host, port);
         if (node != null)
         {
             rg.RemoveNode(host, port, new BsonDocument());
         }
     }
 }
        public void GetListTest()
        {
            BsonDocument dummy = new BsonDocument();
            BsonDocument bson = null;
            DBCursor cursor = null;
            // list cs
            cursor = sdb.GetList(SDBConst.SDB_LIST_COLLECTIONSPACES, dummy, dummy, dummy);
            Assert.IsNotNull(cursor);
            bson = cursor.Next();
            Assert.IsNotNull(bson);

            // list cl
            cursor = sdb.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(sdb))
            {
                cursor = sdb.GetList(SDBConst.SDB_LIST_GROUPS, dummy, dummy, dummy);
                Assert.IsNotNull(cursor);
                bson = cursor.Next();
                Assert.IsNotNull(bson);
            }

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

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

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

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

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

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

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

            // list storge units
            cursor = sdb.GetList(SDBConst.SDB_LIST_STORAGEUNITS, dummy, dummy, dummy);
            Assert.IsNotNull(cursor);
            bson = cursor.Next();
            Assert.IsNotNull(bson);

        }
 public void IsClosedTest()
 {
     //bool result = false;
     Sequoiadb sdb2 = new Sequoiadb(config.conf.Coord.Address);
     System.Console.WriteLine(config.conf.Coord.Address.ToString());
     sdb2.Connect("", "");
     Assert.IsNotNull(sdb2.Connection);
     // TODO:
     //result = sdb2.IsClosed();
     Assert.IsFalse(false);
     // check
     sdb2.Disconnect();
     //result = sdb2.IsClosed();
     Assert.IsTrue(true);
 }
Example #49
0
 public static CollectionSpace CreateCollecitonSpace(Sequoiadb sdb, string csName)
 {
     return CreateCollecitonSpace(sdb, csName, SDBConst.SDB_PAGESIZE_DEFAULT);
 }
Example #50
0
        // create collection space, if the collection space exists then return
        public static CollectionSpace CreateCollecitonSpace(Sequoiadb sdb, string csName, int pageSize)
        {
            CollectionSpace cs = null;
            try
            {
                cs = sdb.CreateCollectionSpace(csName, pageSize);
            }
            catch (BaseException e)
            {
                // verify whether the collection space exists
                if ("SDB_DMS_CS_EXIST" == e.ErrorType)
                    cs = GetCollecitonSpace(sdb, csName);
                // invalid page size argument
                else if ("SDB_INVALIDARG" == e.ErrorType)
                {
                    Console.WriteLine("Failed to create collection space {0}, invalid page size {1}", csName, pageSize);
                    Environment.Exit(0);
                }
                else
                {
                    Console.WriteLine("Failed to create collection space {0},ErrorType = {1}", csName, e.ErrorType);
                    Environment.Exit(0);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                Environment.Exit(0);
            }

            return cs;
        }
Example #51
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";

            Sequoiadb sdb = new Sequoiadb(sdbIP);

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

            // delete all records from the collection
            BsonDocument bson = new BsonDocument();
            Common.DeleteRecords(dbc, bson, bson);

            // if index does not exist, create one
            if (null == Common.GetIndex(dbc, indexName))
            {
                BsonDocument key = null;
                try
                {
                    key = new BsonDocument { { "Id", 1 } };
                }
                catch (Exception e)
                {
                    Console.WriteLine("Failed to create index def key");
                    Console.WriteLine(e.Message);
                    Environment.Exit(0);
                }

                Common.CreateIndex(dbc, indexName, key, true, true);
                Console.WriteLine("Index {0} has been successfully created", indexName);
            }
            else
            {
                Console.WriteLine("Found index {0} already exist", indexName);
            }

            // create name list
            List<BsonDocument> objList = CreateNameList(numRecord);
            // insert obj
            for (int i = 0; i < objList.Count; ++i)
            {
                try
                {
                    dbc.Insert(objList[i]);
                }
                catch (BaseException e)
                {
                    Console.WriteLine("Failed to insert record, ErrorType = {0}", e.ErrorType);
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                }
            }

            FindSortedRecords(dbc);
            FindAllRecords(dbc);
            FindRangeRecords(dbc);
            FindRecordsUsingHintIXScan(dbc);
            FindRecordsUsingHintCScan(dbc);
            FindSortedRecords(dbc);
            FindRecordsFields(dbc);
            FindTotalNumRecords(dbc);
            GetNumofRowsCondition(dbc);

            Common.Disconnect(sdb);
        }
        public void GetSnapshotTest()
        {
            Sequoiadb sdb2 = new Sequoiadb(config.conf.Coord.Address);
            sdb2.Connect();
            BsonDocument dummy = new BsonDocument();
            DBCursor cursor = sdb2.GetSnapshot(SDBConst.SDB_SNAP_CONTEXTS, dummy, dummy, dummy);
            Assert.IsNotNull(cursor);
            BsonDocument bson = cursor.Next();
            Assert.IsNotNull(bson);

            cursor = sdb2.GetSnapshot(SDBConst.SDB_SNAP_CONTEXTS_CURRENT, dummy, dummy, dummy);
            Assert.IsNotNull(cursor);
            bson = cursor.Next();
            Assert.IsNotNull(bson);

            cursor = sdb2.GetSnapshot(SDBConst.SDB_SNAP_SESSIONS, dummy, dummy, dummy);
            Assert.IsNotNull(cursor);
            bson = cursor.Next();
            Assert.IsNotNull(bson);

            cursor = sdb2.GetSnapshot(SDBConst.SDB_SNAP_SESSIONS_CURRENT, dummy, dummy, dummy);
            Assert.IsNotNull(cursor);
            bson = cursor.Next();
            Assert.IsNotNull(bson);

            cursor = sdb2.GetSnapshot(SDBConst.SDB_SNAP_COLLECTIONS, dummy, dummy, dummy);
            Assert.IsNotNull(cursor);
            bson = cursor.Next();
            Assert.IsNotNull(bson);

            cursor = sdb2.GetSnapshot(SDBConst.SDB_SNAP_COLLECTIONSPACES, dummy, dummy, dummy);
            Assert.IsNotNull(cursor);
            bson = cursor.Next();
            Assert.IsNotNull(bson);

            cursor = sdb2.GetSnapshot(SDBConst.SDB_SNAP_DATABASE, dummy, dummy, dummy);
            Assert.IsNotNull(cursor);
            bson = cursor.Next();
            Assert.IsNotNull(bson);

            cursor = sdb2.GetSnapshot(SDBConst.SDB_SNAP_SYSTEM, dummy, dummy, dummy);
            Assert.IsNotNull(cursor);
            bson = cursor.Next();
            Assert.IsNotNull(bson);

            if (Constants.isClusterEnv(sdb))
            {
                cursor = sdb.GetSnapshot(SDBConst.SDB_SNAP_CATALOG, dummy, dummy, dummy);
                Assert.IsNotNull(cursor);
                BsonDocument obj = cursor.Next();
                Assert.IsNotNull(obj);
            }
            sdb2.Disconnect();
        }