예제 #1
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();
 }
예제 #2
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)
         {
             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);
         }
     }
     sdb.Disconnect();
 }
예제 #3
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)
         {
             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 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();
 }
예제 #4
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);
      */
 }
예제 #5
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");
     }
 }
예제 #6
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);
 }
예제 #7
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();
        }
예제 #8
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();
 }
예제 #9
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();
        }
예제 #10
0
 // disconnect from database
 public static void Disconnect(Sequoiadb sdb)
 {
     sdb.Disconnect();
 }