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");
     }
 }
示例#2
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);
             */
        }
示例#3
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();
        }
示例#4
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");
            }
        }
        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();
        }
示例#6
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();
        }
示例#8
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();
        }
示例#9
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();
        }
示例#10
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();
        }
示例#11
0
        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();
        }
示例#12
0
 public static void SequoiadbCleamUp()
 {
     // check whether it is in the cluster environment or not
     if (!Constants.isClusterEnv(sdb))
     {
         return;
     }
     group = sdb.GetReplicaGroup(groupName);
     if (null != group)
     {
         // drop all the cs in current group, and then remove this group
         int nodeNum = group.GetNodeNum(SDBConst.NodeStatus.SDB_NODE_ALL);
         if (nodeNum > 0)
         {
             SequoiaDB.Node 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();
         }
         Assert.IsTrue(group.Stop());
         // remove group
         try
         {
             sdb.RemoveReplicaGroup(group.GroupName);
         }
         catch (BaseException e)
         {
             string errInfo = e.Message;
             Console.WriteLine("Error code is: " + errInfo);
         }
     }
     create_node_flag  = false;
     create_node2_flag = false;
     // disconnect
     sdb.Disconnect();
 }
示例#13
0
        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);
        }
 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();
 }
示例#15
0
        public void CheckInvalidSituaction()
        {
            bool          boolValue = true;
            long          longValue = 300 * 1000;
            ClientOptions opt       = new ClientOptions();

            opt.CacheInterval = longValue;
            opt.EnableCache   = boolValue;
            Sequoiadb db = new Sequoiadb(config.conf.Coord.Address);

            db.Connect(config.conf.UserName, config.conf.Password);
            Sequoiadb.InitClient(opt);
            // check
            Type         t                    = db.GetType();
            BindingFlags flag                 = BindingFlags.NonPublic | BindingFlags.Instance;
            FieldInfo    f_nameCache          = t.GetField("nameCache", flag);
            Dictionary <String, DateTime> dic = f_nameCache.GetValue(db) as Dictionary <String, DateTime>;

            Assert.AreEqual(0, dic.Count);

            String csName = "foo_csharp.";
            String clName = "bar_csharp.";

            try {
                db.DropCollectionSpace(csName);
            } catch (BaseException e) {
            }
            try {
                db.CreateCollectionSpace(csName);
                Assert.Fail();
            } catch (BaseException e) {
                csName = "foo_csharp";
            }
            try {
                db.DropCollectionSpace(csName);
            } catch (BaseException e) {
            }
            // check
            Assert.AreEqual(0, dic.Count);
            CollectionSpace cs = db.CreateCollectionSpace(csName);

            // check
            Assert.AreEqual(1, dic.Count);
            Assert.IsTrue(dic.ContainsKey(csName));
            try {
                cs.CreateCollection(clName);
                Assert.Fail();
            } catch (BaseException e) {
                clName = "bar_csharp";
            }
            // check
            Assert.AreEqual(1, dic.Count);
            Assert.IsTrue(dic.ContainsKey(csName));
            cs.CreateCollection(clName);
            // check
            Assert.AreEqual(2, dic.Count);
            Assert.IsTrue(dic.ContainsKey(csName + "." + clName));
            Assert.IsTrue(dic.ContainsKey(csName));

            db.DropCollectionSpace(csName);
            // check
            Assert.AreEqual(0, dic.Count);

            db.Disconnect();
        }
示例#16
0
        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);
            // check whether it is in the cluster environment or not
            if (!Constants.isClusterEnv(sdb))
            {
                return;
            }
            // argument
            groupName = config.conf.Groups[3].GroupName;
            hostName  = config.conf.Groups[3].Nodes[0].HostName;
            port      = config.conf.Groups[3].Nodes[0].Port;
            dbpath    = config.conf.Groups[3].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)
                {
                    SequoiaDB.Node 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_rg_flag = true;
            // create a node
            BsonDocument options = new BsonDocument();

            options.Add("logfilenum", 1);
            node = group.CreateNode(hostName, port, dbpath, options);
            Assert.IsNotNull(node);
            node.Start();
            create_node_flag = true;
        }
示例#17
0
        public void CheckDisableCacheLogic()
        {
            // test1: test default value
            bool          boolValue = false;
            long          longValue = 300 * 1000;
            ClientOptions opt       = new ClientOptions();

            opt.CacheInterval = longValue;
            opt.EnableCache   = boolValue;
            Sequoiadb db = new Sequoiadb(config.conf.Coord.Address);

            db.Connect(config.conf.UserName, config.conf.Password);
            Sequoiadb.InitClient(opt);
            // check
            Type         t                    = db.GetType();
            BindingFlags flag                 = BindingFlags.NonPublic | BindingFlags.Instance;
            FieldInfo    f_nameCache          = t.GetField("nameCache", flag);
            Dictionary <String, DateTime> dic = f_nameCache.GetValue(db) as Dictionary <String, DateTime>;

            Assert.AreEqual(0, dic.Count);

            // create cs
            CollectionSpace[] csObjArr = new CollectionSpace[3];
            for (int i = 0; i < csArr.Length; i++)
            {
                try
                {
                    db.DropCollectionSpace(csArr[i]);
                }
                catch (BaseException e)
                {
                }
            }
            for (int i = 0; i < csArr.Length; i++)
            {
                csObjArr[i] = db.CreateCollectionSpace(csArr[i]);
            }
            // test1: 检测db对象中cs的缓存情况
            Console.Out.WriteLine("point 1: after creating cs, nameCache.Count is: " + dic.Count);
            Assert.AreEqual(0, dic.Count);
            // drop one cs
            db.DropCollectionSpace(csArr[0]);
            // test2: 删除一个cs之后,检测db对象中cs的缓存情况
            Assert.AreEqual(0, dic.Count);
            // create the drop cs
            csObjArr[0] = db.CreateCollectionSpace(csArr[0]);
            Assert.AreEqual(0, dic.Count);
            // create cl
            BsonDocument conf = new BsonDocument();

            conf.Add("ReplSize", 0);
            for (int i = 0; i < clArr1.Length; i++)
            {
                //Console.Out.WriteLine("csObjArr[0] is: " + csObjArr[0].getName() + ", clArr1[x] is: " + clArr1[i]);
                csObjArr[0].CreateCollection(clArr1[i], conf);
            }
            // test3: 检测db对象中cs,cl的缓存情况
            Assert.AreEqual(0, dic.Count);
            // drop one cl
            csObjArr[0].DropCollection(clArr1[0]);
            // test4: 检测删除cl之后,cs,cl的缓存情况
            Assert.AreEqual(0, dic.Count);
            // drop one cs
            db.DropCollectionSpace(csArr[0]);
            // test5: 检测删除cs之后,cs,cl的缓存情况
            Assert.AreEqual(0, dic.Count);
            db.Disconnect();
        }
示例#18
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();

            // snapshot transation
            sdb.TransactionBegin();
            try
            {
                BsonDocument o = null;
                coll.Insert(new BsonDocument());
                cursor = sdb.GetSnapshot(SDBConst.SDB_SNAP_TRANSACTIONS, dummy, dummy, dummy);
                Console.WriteLine("the result of SDB_SNAP_TRANSACTIONS is: ");
                while (null != (o = cursor.Next()))
                {
                    Console.WriteLine(o);
                }
                cursor = sdb.GetSnapshot(SDBConst.SDB_SNAP_TRANSACTIONS_CURRENT, dummy, dummy, dummy);
                Console.WriteLine("the result of SDB_SNAP_TRANSACTIONS_CURRENT is: ");
                while (null != (o = cursor.Next()))
                {
                    Console.WriteLine(o);
                }
            }
            finally
            {
                sdb.TransactionCommit();
            }
        }
示例#19
0
 public static void SequoiadbCleamUp()
 {
     sdb.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);
      */
 }
示例#21
0
 // disconnect from database
 public static void Disconnect(Sequoiadb sdb)
 {
     sdb.Disconnect();
 }
示例#22
0
 public void MyTestCleanup()
 {
     sdb.DropCollectionSpace(csName);
     sdb.Disconnect();
 }
示例#23
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();
            // snapshot transation
            sdb.TransactionBegin();
            try
            {
                BsonDocument o = null;
                coll.Insert(new BsonDocument());
                cursor = sdb.GetSnapshot(SDBConst.SDB_SNAP_TRANSACTIONS, dummy, dummy, dummy);
                Console.WriteLine("the result of SDB_SNAP_TRANSACTIONS is: ");
                while (null != (o = cursor.Next()))
                {
                    Console.WriteLine(o);
                }
                cursor = sdb.GetSnapshot(SDBConst.SDB_SNAP_TRANSACTIONS_CURRENT, dummy, dummy, dummy);
                Console.WriteLine("the result of SDB_SNAP_TRANSACTIONS_CURRENT is: ");
                while (null != (o = cursor.Next()))
                {
                    Console.WriteLine(o);
                }
            }
            catch (BaseException e)
            {
                Console.WriteLine("The error info is: " + e.ErrorType + ", " + e.ErrorCode + ", " + e.Message);
                Assert.IsTrue(e.ErrorType == "SDB_DPS_TRANS_DIABLED");
            }
            finally
            {
                sdb.TransactionCommit();
            }

            // snapshot accessplans
            {
                BsonDocument o = null;
                cursor = sdb.GetSnapshot(SDBConst.SDB_SNAP_ACCESSPLANS, dummy, dummy, dummy);
                Console.WriteLine("the result of SDB_SNAP_TRANSACTIONS is: ");
                while (null != (o = cursor.Next()))
                {
                    Console.WriteLine(o);
                }
            }

            // node health
            {
                cursor = sdb.GetSnapshot(SDBConst.SDB_SNAP_HEALTH, dummy, dummy, dummy);
                Console.WriteLine("the result of SDB_SNAP_HEALTH is: ");
                BsonDocument rec = null;
                while (null != (rec = cursor.Next()))
                {
                    Console.WriteLine(rec);
                }
            }
        }
 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 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();
        }
 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);
 }
示例#27
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();
        }
 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();
 }
        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();
        }
示例#30
0
 public void MyTestCleanup()
 {
     sdb.Disconnect();
 }
 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();
 }
示例#32
0
 // disconnect from database
 public static void Disconnect(Sequoiadb sdb)
 {
     sdb.Disconnect();
 }