コード例 #1
0
        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();
        }
コード例 #2
0
 public void getGroupTest()
 {
     if (!isCluster)
     {
         return;
     }
     try
     {
         groupName = "SYSCatalogGroup12345";
         group     = sdb.GetReplicaGroup(groupName);
         Assert.Fail("should get SDB_CLS_GRP_NOT_EXIST(-154) error");
     }
     catch (BaseException e)
     {
         Assert.AreEqual("SDB_CLS_GRP_NOT_EXIST", e.ErrorType);
     }
     try
     {
         group = sdb.GetReplicaGroup(0);
         Assert.Fail("should get SDB_CLS_GRP_NOT_EXIST(-154) error");
     }
     catch (BaseException e)
     {
         Assert.AreEqual("SDB_CLS_GRP_NOT_EXIST", e.ErrorType);
     }
 }
コード例 #3
0
        public void MyTestInitialize()
        {
            // check whether it is in the cluster environment or not
            if (!Constants.isClusterEnv(sdb))
            {
                return;
            }
            // init
            create_node2_flag = false;
            // argument
            groupName2 = config.conf.Groups[3].GroupName;
            hostName2  = config.conf.Groups[3].Nodes[1].HostName;
            port2      = config.conf.Groups[3].Nodes[1].Port;
            dbpath2    = config.conf.Groups[3].Nodes[1].DBPath;
            // drop the exist group
            group = sdb.GetReplicaGroup(groupName);
            if (null == group)
            {
                return;
            }
            // create a node
            BsonDocument options = new BsonDocument();

            options.Add("logfilenum", 1);
            node2 = group.CreateNode(hostName2, port2, dbpath2, options);
            Assert.IsNotNull(node2);
            node2.Start();
        }
コード例 #4
0
        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();
        }
コード例 #5
0
 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();
 }
コード例 #6
0
 public void MyTestInitialize()
 {
     if (!isCluster)
     {
         return;
     }
     group     = sdb.GetReplicaGroup(1000);
     groupName = group.GroupName;
     groupID   = 1000;
 }
コード例 #7
0
        public void getNodeTest()
        {
            if (!isCluster)
            {
                return;
            }
            // case 1: normal case
            groupName = "SYSCatalogGroup";
            group     = sdb.GetReplicaGroup(groupName);
            SequoiaDB.Node master = group.GetMaster();
            Console.WriteLine(string.Format("group is: {0}, master is: {1}", groupName, master.NodeName));
            String hostName = master.HostName;
            int    hostPort = master.Port;

            SequoiaDB.Node node1 = group.GetNode(hostName, hostPort);
            Console.WriteLine(string.Format("group is: {0}, node1 is: {1}", groupName, node1.NodeName));
            SequoiaDB.Node node2 = group.GetNode(hostName + ":" + hostPort);
            Console.WriteLine(string.Format("group is: {0}, node2 is: {1}", groupName, node2.NodeName));
            // case 2: get a node which is not exist
            SequoiaDB.Node node3 = null;
            try
            {
                node3 = group.GetNode("ubuntu", 30000);
                Assert.Fail("should get SDB_SYS(-10) error");
            }
            catch (BaseException e)
            {
                Assert.AreEqual("SDB_CLS_NODE_NOT_EXIST", e.ErrorType);
            }
            try
            {
                node3 = group.GetNode(hostName, 0);
                Assert.Fail("should get SDB_CLS_NODE_NOT_EXIST(-155) error");
            }
            catch (BaseException e)
            {
                Assert.AreEqual("SDB_CLS_NODE_NOT_EXIST", e.ErrorType);
            }
            // case 3: get a node from empty group
            groupName = "groupNoteExist";
            group     = sdb.CreateReplicaGroup(groupName);
            try
            {
                node3 = group.GetNode(hostName, 0);
                Assert.Fail("should get SDB_CLS_NODE_NOT_EXIST(-155) error");
            }
            catch (BaseException e)
            {
                Assert.AreEqual("SDB_CLS_NODE_NOT_EXIST", e.ErrorType);
            }
            finally
            {
                sdb.RemoveReplicaGroup(groupName);
            }
        }
コード例 #8
0
 public void GetMasterAndSlaveNodeTest()
 {
     if (!isCluster)
     {
         return;
     }
     //groupName = "db2";
     group = sdb.GetReplicaGroup(groupName);
     SequoiaDB.Node master = group.GetMaster();
     SequoiaDB.Node slave  = group.GetSlave();
     Console.WriteLine("group is: " + groupName + ", master is: " + master.NodeName + ", slave is: " + slave.NodeName);
 }
コード例 #9
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();
        }
コード例 #10
0
        private int _GetMasterPosition(ReplicaGroup group)
        {
            int          primaryId           = -1;
            int          primaryNodePosition = 0;
            bool         hasPrimary          = true;
            BsonDocument detail     = group.GetDetail();
            BsonValue    groupValue = detail.Contains(SequoiadbConstants.FIELD_GROUP) ? detail[SequoiadbConstants.FIELD_GROUP] : null;

            if (groupValue == null || !groupValue.IsBsonArray)
            {
                throw new BaseException("SDB_SYS");
            }
            BsonArray nodes = groupValue.AsBsonArray;

            if (nodes.Count == 0)
            {
                throw new BaseException((int)Errors.errors.SDB_CLS_EMPTY_GROUP);
            }
            BsonValue primaryIdValue = detail.Contains(SequoiadbConstants.FIELD_PRIMARYNODE) ? detail[SequoiadbConstants.FIELD_PRIMARYNODE] : null;

            if (primaryIdValue == null)
            {
                hasPrimary = false;
            }
            else if (!primaryIdValue.IsInt32)
            {
                throw new BaseException((int)Errors.errors.SDB_SYS);
            }
            else if ((primaryId = primaryIdValue.AsInt32) == -1)
            {
                hasPrimary = false;
            }
            // try to mark the position of primary node in the nodes list,
            // the value of position is [1, 7]
            int counter = 0;

            foreach (BsonDocument node in nodes)
            {
                counter++;
                BsonValue nodeIdValue = node.Contains(SequoiadbConstants.FIELD_NODEID) ? node[SequoiadbConstants.FIELD_NODEID] : null;
                if (nodeIdValue == null || !nodeIdValue.IsInt32)
                {
                    throw new BaseException((int)Errors.errors.SDB_SYS, "invalid node id in node list");
                }
                int nodeId = nodeIdValue.AsInt32;
                if (hasPrimary && primaryId == nodeId)
                {
                    primaryNodePosition = counter;
                }
            }
            return(primaryNodePosition);
        }
コード例 #11
0
ファイル: SequoiadbTest.cs プロジェクト: ycs0405/SequoiaDB
        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();
        }
コード例 #12
0
 public void MyTestCleanup()
 {
     // check whether it is in the cluster environment or not
     if (false == Constants.isClusterEnv(sdb))
     {
         return;
     }
     group = sdb.GetReplicaGroup(groupName);
     if (null != group)
     {
         group.RemoveNode(hostName2, port2, null);
     }
     create_node2_flag = false;
 }
コード例 #13
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();
 }
コード例 #14
0
        public void removeRG()
        {
            // check whether it is in the cluster environment or not
            if (!Constants.isClusterEnv(sdb))
            {
                Console.WriteLine("removeRG is for cluster environment only.");
                return;
            }
            // get rg
            group = sdb.GetReplicaGroup(groupName);
            if (group == null)
            {
                group = sdb.CreateReplicaGroup(groupName);
            }
            Assert.IsNotNull(group);
            // create node1
            string hostName1 = config.conf.Groups[1].Nodes[1].HostName;
            int    port1     = config.conf.Groups[1].Nodes[1].Port;
            string dbPath1   = config.conf.Groups[1].Nodes[1].DBPath;
            Dictionary <string, string> map1 = new Dictionary <string, string>();

            map1.Add("diaglevel", config.conf.Groups[1].Nodes[1].DiagLevel);
            var node1 = group.CreateNode(hostName1, port1, dbPath1, map1);

            Assert.IsNotNull(node1);
            // start node1
            Assert.IsTrue(node1.Start());

            // remove the newly build node
            try
            {
                group.RemoveNode(hostName1, port1, null);
            }
            catch (BsonException e)
            {
                string errInfo = e.Message;
                Console.WriteLine("Error code is: " + errInfo);
            }
            group.Stop();
        }
コード例 #15
0
        public void RgTempTest()
        {
            if (!isCluster)
            {
                return;
            }
            groupName = "SYSCoord";
            SequoiaDB.Node master = null;
            SequoiaDB.Node slave  = null;

            // case 1
            group = sdb.GetReplicaGroup(groupName);
            //master = group.GetMaster();
            slave = group.GetSlave();
            Console.WriteLine(String.Format("case1: group is: {0}, master is: {1}, slave is: {2}", groupName,
                                            master == null ? null : master.NodeName,
                                            slave == null ? null : slave.NodeName));
            // case 2
            int    counter1 = 0;
            int    counter2 = 0;
            string str1     = "susetzb:40000";
            string str2     = "susetzb:42000";

            for (int i = 0; i < 100; i++)
            {
                slave = group.GetSlave(1, 2, 3, 4, 5, 6, 7);
                if (slave.NodeName.Equals(str1))
                {
                    counter1++;
                }
                else if (slave.NodeName.Equals(str2))
                {
                    counter2++;
                }
            }
            Console.WriteLine("counter1 is: {0}, counter2 is: {1}", counter1, counter2);
        }
コード例 #16
0
ファイル: SequoiadbTest.cs プロジェクト: ycs0405/SequoiaDB
        public void setSessionAttrTest()
        {
            // create another node
            string       host      = "192.168.20.42";
            int          port      = 55555;
            string       dataPath  = "/opt/sequoiadb/database/data/55555";
            string       groupName = "group1";
            ReplicaGroup rg        = null;

            try
            {
                // get the exist group
                rg = sdb.GetReplicaGroup(groupName);
                // remove the node we going to use
                SequoiaDB.Node node = rg.GetNode(host, port);
                if (node != null)
                {
                    rg.RemoveNode(host, port, new BsonDocument());
                }
                // create node
                Dictionary <string, string> opt = new Dictionary <string, string>();
                rg.CreateNode(host, port, dataPath, opt);
                rg.Start();
                // insert some records first
                int num = 10;
                List <BsonDocument> insertor = new List <BsonDocument>();
                for (int i = 0; i < num; i++)
                {
                    BsonDocument obj = new BsonDocument();
                    obj.Add("id", i);
                    insertor.Add(obj);
                }
                coll.BulkInsert(insertor, 0);
                // begin a new session
                Sequoiadb sdb2 = new Sequoiadb(config.conf.Coord.Address);
                sdb2.Connect(config.conf.UserName, config.conf.Password);
                Assert.IsNotNull(sdb2.Connection);
                // TODO:
                BsonDocument conf = new BsonDocument("PreferedInstance", "m");
                sdb2.SetSessionAttr(conf);
                // check
                // record the slave note "TotalDataRead" before query
                Sequoiadb sddb = new Sequoiadb(host, port);
                sddb.Connect(config.conf.UserName, config.conf.Password);
                DBCursor     cur1    = sddb.GetSnapshot(6, null, null, null);
                BsonDocument status1 = cur1.Next();
                long         count1  = status1.GetValue("TotalDataRead").AsInt64;
                // query
                DBCursor     cursor = coll.Query(null, null, null, null, 0, -1);
                BsonDocument o      = new BsonDocument();
                long         count  = 0;
                while ((o = cursor.Next()) != null)
                {
                    count++;
                }
                // record the slave note "TotalRead" after query
                DBCursor     cur2    = sddb.GetSnapshot(6, null, null, null);
                BsonDocument status2 = cur2.Next();
                long         count2  = status2.GetValue("TotalDataRead").AsInt64;
                //Assert.IsTrue(num == count2 - count1);
                long temp = count2 - count1;
                Console.WriteLine("count2 is " + count2 + ", count1 is " + count1);
                DBCursor     cur3    = sddb.GetSnapshot(6, null, null, null);
                BsonDocument status3 = cur3.Next();
                long         count3  = status3.GetValue("TotalRead").AsInt64;
            }
            finally
            {
                // remove the newly build node
                SequoiaDB.Node node = rg.GetNode(host, port);
                if (node != null)
                {
                    rg.RemoveNode(host, port, new BsonDocument());
                }
            }
        }
コード例 #17
0
        public void GetMasterAndSlaveNodeTest()
        {
            if (!isCluster)
            {
                return;
            }
            groupName = "SYSCatalogGroup";
            group     = sdb.GetReplicaGroup(groupName);
            BsonDocument detail              = group.GetDetail();
            BsonArray    nodeList            = (BsonArray)detail["Group"];
            int          primaryNodePosition = _GetMasterPosition(group);
            int          nodeCount           = nodeList.Count;

            Assert.IsTrue(nodeCount != 0);

            SequoiaDB.Node master = null;
            SequoiaDB.Node slave  = null;

            // case 1
            master = group.GetMaster();
            slave  = group.GetSlave();
            Console.WriteLine(String.Format("case1: group is: {0}, master is: {1}, slave is: {2}", groupName,
                                            master == null ? null : master.NodeName,
                                            slave == null ? null : slave.NodeName));
            if (nodeCount == 1)
            {
                Assert.AreEqual(master.NodeName, slave.NodeName);
            }
            else
            {
                Assert.AreNotEqual(master.NodeName, slave.NodeName);
            }

            // case 2
            slave = group.GetSlave(1, 2, 3, 4, 5, 6, 7);
            Console.WriteLine(String.Format("case2: group is: {0}, master is: {1}, slave is: {2}", groupName,
                                            master == null ? null : master.NodeName,
                                            slave == null ? null : slave.NodeName));
            if (nodeCount == 1)
            {
                Assert.AreEqual(master.NodeName, slave.NodeName);
            }
            else
            {
                Assert.AreNotEqual(master.NodeName, slave.NodeName);
            }

            // case 3
            Random random = new Random();
            int    pos1   = random.Next(7) + 1;
            int    pos2   = 0;

            while (true)
            {
                pos2 = random.Next(7) + 1;
                if (pos2 != pos1)
                {
                    break;
                }
            }
            //pos1 = 4; pos2 = 7;
            slave = group.GetSlave(pos1, pos2);
            Console.WriteLine(String.Format("case3: group is: {0}, master is: {1}, slave is: {2}", groupName,
                                            master == null ? null : master.NodeName,
                                            slave == null ? null : slave.NodeName));
            if (nodeCount == 1)
            {
                Assert.AreEqual(master.NodeName, slave.NodeName);
            }
            else
            {
                if ((pos1 % nodeCount == pos2 % nodeCount) &&
                    (primaryNodePosition == (pos1 - 1) % nodeCount + 1))
                {
                    Assert.AreEqual(master.NodeName, slave.NodeName);
                }
                else
                {
                    Assert.AreNotEqual(master.NodeName, slave.NodeName);
                }
            }
        }
コード例 #18
0
 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();
 }
コード例 #19
0
        public void RGTest()
        {
            // 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)
                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));
            var master = group.GetMaster();
            Assert.IsNotNull(master);
            var 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();
        }
コード例 #20
0
        public void removeRG()
        {
            // check whether it is in the cluster environment or not
            if (!Constants.isClusterEnv(sdb))
            {
                Console.WriteLine("removeRG is for cluster environment only.");
                return;
            }
            // get rg
            group = sdb.GetReplicaGroup(groupName);
            if (group == null)
                group = sdb.CreateReplicaGroup(groupName);
            Assert.IsNotNull(group);
            // create node1
            string hostName1 = config.conf.Groups[1].Nodes[1].HostName;
            int port1 = config.conf.Groups[1].Nodes[1].Port;
            string dbPath1 = config.conf.Groups[1].Nodes[1].DBPath;
            Dictionary<string, string> map1 = new Dictionary<string, string>();
            map1.Add("diaglevel", config.conf.Groups[1].Nodes[1].DiagLevel);
            var node1 = group.CreateNode(hostName1, port1, dbPath1, map1);
            Assert.IsNotNull(node1);
            // start node1
            Assert.IsTrue(node1.Start());

            // remove the newly build node
            try
            {
                group.RemoveNode(hostName1, port1, null);
            }
            catch (BsonException e)
            {
                string errInfo = e.Message;
                Console.WriteLine("Error code is: " + errInfo);
            }
            group.Stop();
        }
コード例 #21
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;
        }