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);
            }
        }
        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 #3
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 #4
0
        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());
                }
            }
        }