Esempio n. 1
0
 public void setSessionAttr_Arguments_Test()
 {
     // begin a new session
     Sequoiadb sdb2 = new Sequoiadb(config.conf.Coord.Address);
     sdb2.Connect(config.conf.UserName, config.conf.Password);
     Assert.IsNotNull(sdb2.Connection);
     // TODO:
     BsonDocument conf = null;
     string[] str = { "M", "m", "S", "s", "A", "a" };
     int[] nodeNumber = { 1, 2, 3, 4, 5, 6, 7 };
     Random rnd = new Random();
     int r = rnd.Next(2);
     int n = -1;
     if (r == 0)
     {
         n = rnd.Next(6);
         conf = new BsonDocument("PreferedInstance", str[n]);
     }
     else
     {
         n = rnd.Next(7);
         conf = new BsonDocument("PreferedInstance", nodeNumber[n]);
     }
     try
     {
         sdb2.SetSessionAttr(conf);
     }
     catch (BaseException e)
     {
         Console.WriteLine(e.ErrorType);
         Assert.Fail();
     }
 }
Esempio n. 2
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());
         }
     }
 }